Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol uses #34

Merged
merged 7 commits into from
Jun 30, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 59 additions & 5 deletions FSharp.AutoComplete/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ type MethodResponse =
Overloads : Overload list
}

type SymbolUseRange =
{
Filename: string
StartLine: int
StartColumn: int
EndLine: int
EndColumn: int
IsFromDefinition: bool
IsFromAttribute : bool
IsFromComputationExpression : bool
IsFromDispatchSlotImplementation : bool
IsFromPattern : bool
IsFromType : bool
}

type SymbolUseResponse =
{
Name: string
Uses: SymbolUseRange list
}
type FSharpErrorSeverityConverter() =
inherit JsonConverter()

Expand Down Expand Up @@ -144,6 +164,8 @@ module internal CommandInput =
helptext <candidate>
- fetch type signature for specified completion candidate
(from last completion request). Only use in JSON mode.
symboluse ""<filename>"" <line> <col> [timeout]
- find all uses of the symbol for the specified location
tooltip ""<filename>"" <line> <col> [timeout]
- get tool tip for the specified location
finddecl ""<filename>"" <line> <col> [timeout]
Expand Down Expand Up @@ -188,6 +210,7 @@ module internal CommandInput =
type PosCommand =
| Completion
| Methods
| SymbolUse
| ToolTip
| FindDeclaration

Expand Down Expand Up @@ -260,6 +283,7 @@ module internal CommandInput =
// Parse 'completion "<filename>" <line> <col> [timeout]' command
let completionTipOrDecl = parser {
let! f = (string "completion " |> Parser.map (fun _ -> Completion)) <|>
(string "symboluse " |> Parser.map (fun _ -> SymbolUse)) <|>
(string "tooltip " |> Parser.map (fun _ -> ToolTip)) <|>
(string "methods " |> Parser.map (fun _ -> Methods)) <|>
(string "finddecl " |> Parser.map (fun _ -> FindDeclaration))
Expand Down Expand Up @@ -461,7 +485,7 @@ module internal Main =
let sb = new System.Text.StringBuilder()
sb.AppendLine("DATA: errors") |> ignore
for e in errs do
sb.AppendLine(sprintf "[%d:%d-%d:%d] %s %s" e.StartLineAlternate e.StartColumn e.EndLineAlternate e.EndColumn
sb.AppendLine(sprintf "[%d:%d-%d:%d] %s %s" e.StartLineAlternate (e.StartColumn + 1) e.EndLineAlternate (e.EndColumn + 1)
(if e.Severity = FSharpErrorSeverity.Error then "ERROR" else "WARNING") e.Message)
|> ignore
sb.Append("<<EOF>>") |> ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON printing just below Data =errs is also affected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll fix it shortly.

Expand Down Expand Up @@ -521,11 +545,11 @@ module internal Main =
let declstrings =
[ for tld in decls do
let m = tld.Declaration.Range
let (s1, e1), (s2, e2) = ((m.StartColumn, m.StartLine), (m.EndColumn, m.EndLine))
let (s1, e1), (s2, e2) = ((m.StartColumn + 1, m.StartLine), (m.EndColumn + 1, m.EndLine))
yield sprintf "[%d:%d-%d:%d] %s" e1 s1 e2 s2 tld.Declaration.Name
for d in tld.Nested do
let m = d.Range
let (s1, e1), (s2, e2) = ((m.StartColumn, m.StartLine), (m.EndColumn, m.EndLine))
let (s1, e1), (s2, e2) = ((m.StartColumn + 1, m.StartLine), (m.EndColumn + 1, m.EndLine))
yield sprintf " - [%d:%d-%d:%d] %s" e1 s1 e2 s2 d.Name ]
printAgent.WriteLine(sprintf "DATA: declarations\n%s\n<<EOF>>" (String.concat "\n" declstrings))
| Json -> prAsJson { Kind = "declarations"; Data = decls }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is also affected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH, maybe we should have a record type for this as well. It'd be nice to have StartColumn/StartLine etc in this type as well, for consistency.

Expand Down Expand Up @@ -617,6 +641,36 @@ module internal Main =

main state

| SymbolUse ->
let symboluses =
async {
let! symboluse = tyRes.GetSymbol(line, col, lineStr)
if symboluse.IsNone then return None else
let! symboluses = tyRes.GetUsesOfSymbolInFile symboluse.Value.Symbol
return Some {
Name = symboluse.Value.Symbol.DisplayName
Uses =
[ for su in symboluses do
yield { StartLine = su.RangeAlternate.StartLine
StartColumn = su.RangeAlternate.StartColumn + 1
EndLine = su.RangeAlternate.EndLine
EndColumn = su.RangeAlternate.EndColumn + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding 1 here doesn't seem right, they should already be 1-based from the Alternate syntax. Looking at the results I also think they should end one earlier e.g. with:

let testval = FileTwo.NewObjectType()

The results have a range with columns start=5 and end=12. t is definitely at 5, and l is 6 further on, so 11. This is an inclusive range and I think we should leave it alone, documenting it as such (if we ever get around to adding documentation for this project!). If editors prefer to work with an exclusive range they can make the adjustement locally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XS columns are 1 based we do something like:

        let start, finish = Symbols.trimSymbolRegion symbolUse lastIdentAtLoc
        let filename = doc.FileName.ToString()  
        let offset = doc.LocationToOffset(start.Line, start.Column+1)
        let domRegion = DomRegion(filename, start.Line, start.Column+1, finish.Line, finish.Column+1)

        let symbol = createSymbol(doc, context, symbolUse.Symbol, lastIdentAtLoc, domRegion)
        let memberRef = MemberReference(symbol, filename, offset, lastIdentAtLoc.Length)

        //if the current range is a symbol range and the fileNameOfRefs match change the ReferenceUsageType
        if symbolUse.IsFromDefinition then
            memberRef.ReferenceUsageType <- ReferenceUsageType.Write

        memberRef

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to fix this. FCS seems to report 0-based columns (lines are 1-based). Do you want me to only add 1 to StartColumn? That doesn't seem right to me. That would leave testva highlighted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I misread. It seems that FCS accepts 1-based column numbers but returns 0-based. Why would this possibly be a good idea?

I've looked at the output we give and I think only declarations, finddecl and this new command return positions. I think they should all return 0-based or all return 1-based columns, for consistency. However, I think that if FCS is outputting 0-based columns it should probably be accepting 0-based as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is all very confusing. Adding 1 to StartColumn and EndColumn seems to be the right thing to do, so we normalize to consistently being 1-based . Do the other commands return 0-based?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Find Declaration seems to return 0-based.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess you posted at the same time as me ;-)

I would be happy if everything returned 1-based so at least FSAC is consistent even if FCS isn't.

@7sharp9 do you adjust the results you get from GetNavigationItems for the pathed document support as well to be 1-based?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it. :)

Separate PR or this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is fine by me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Filename = su.FileName
IsFromDefinition = su.IsFromDefinition
IsFromAttribute = su.IsFromAttribute
IsFromComputationExpression = su.IsFromComputationExpression
IsFromDispatchSlotImplementation = su.IsFromDispatchSlotImplementation
IsFromPattern = su.IsFromPattern
IsFromType = su.IsFromType } ] } }
|> Async.RunSynchronously

match state.OutputMode, symboluses with
| Text, _ -> printMsg "ERROR" "symboluse not supported in text mode"
| Json, Some su -> prAsJson { Kind = "symboluse"; Data = su }
| _ -> printMsg "ERROR" "No symbols found"

main state

| FindDeclaration ->
let declarations = tyRes.GetDeclarationLocation(line,col,lineStr)
|> Async.RunSynchronously
Expand All @@ -625,9 +679,9 @@ module internal Main =
| FSharpFindDeclResult.DeclFound range ->

match state.OutputMode with
| Text -> printAgent.WriteLine(sprintf "DATA: finddecl\n%s:%d:%d\n<<EOF>>" range.FileName range.StartLine range.StartColumn)
| Text -> printAgent.WriteLine(sprintf "DATA: finddecl\n%s:%d:%d\n<<EOF>>" range.FileName range.StartLine (range.StartColumn + 1))
| Json ->
let data = { Line = range.StartLine; Column = range.StartColumn; File = range.FileName }
let data = { Line = range.StartLine; Column = range.StartColumn + 1; File = range.FileName }
prAsJson { Kind = "finddecl"; Data = data }

main state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[2:5-2:6] ERROR The value, constructor, namespace or type 'c' is not defined
[2:6-2:7] ERROR The value, constructor, namespace or type 'c' is not defined
<<EOF>>
DATA: completion
Cons
Expand Down
8 changes: 4 additions & 4 deletions FSharp.AutoComplete/test/integration/ErrorTests/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ DATA: project
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[4:14-4:21] ERROR The namespace or module 'FileTwo' is not defined
[8:11-8:27] ERROR Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
[10:18-10:22] ERROR This expression was expected to have type
[4:15-4:22] ERROR The namespace or module 'FileTwo' is not defined
[8:12-8:28] ERROR Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
[10:19-10:23] ERROR This expression was expected to have type
int
but here has type
string
Expand All @@ -18,7 +18,7 @@ func
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[8:12-8:19] ERROR The value or constructor 'unnamed' is not defined
[8:13-8:20] ERROR The value or constructor 'unnamed' is not defined
<<EOF>>
DATA: completion
func
Expand Down
10 changes: 5 additions & 5 deletions FSharp.AutoComplete/test/integration/FindDeclarations/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ INFO: Synchronous parsing started
DATA: errors
<<EOF>>
DATA: finddecl
<absolute path removed>/test/integration/FindDeclarations/Program.fs:2:6
<absolute path removed>/test/integration/FindDeclarations/Program.fs:2:7
<<EOF>>
DATA: finddecl
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:13:11
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:13:12
<<EOF>>
DATA: finddecl
<absolute path removed>/test/integration/FindDeclarations/Program.fs:6:4
<absolute path removed>/test/integration/FindDeclarations/Program.fs:6:5
<<EOF>>
DATA: finddecl
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:11:5
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:11:6
<<EOF>>
DATA: finddecl
<absolute path removed>/test/integration/FindDeclarations/Script.fsx:4:6
<absolute path removed>/test/integration/FindDeclarations/Script.fsx:4:7
<<EOF>>
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ DATA: errors
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[1:22-1:28] ERROR The value, constructor, namespace or type 'addTwo' is not defined
[1:23-1:29] ERROR The value, constructor, namespace or type 'addTwo' is not defined
<<EOF>>
8 changes: 4 additions & 4 deletions FSharp.AutoComplete/test/integration/OutOfRange/output.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[6:14-6:15] ERROR Missing qualification after '.'
[6:14-6:15] ERROR Missing qualification after '.'
[6:12-6:14] ERROR The value or constructor 'XA' is not defined
[6:15-6:16] ERROR Missing qualification after '.'
[6:15-6:16] ERROR Missing qualification after '.'
[6:13-6:15] ERROR The value or constructor 'XA' is not defined
<<EOF>>
ERROR: Position is out of range
<<EOF>>
Expand All @@ -22,7 +22,7 @@ INFO: No tooltip information
ERROR: Position is out of range
<<EOF>>
DATA: finddecl
<absolute path removed>/test/integration/OutOfRange/Script.fsx:3:7
<absolute path removed>/test/integration/OutOfRange/Script.fsx:3:8
<<EOF>>
ERROR: Could not find declaration
<<EOF>>
Expand Down
32 changes: 16 additions & 16 deletions FSharp.AutoComplete/test/integration/RawIdTest/output.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[9:1-9:2] ERROR Missing qualification after '.'
[11:1-11:2] ERROR Missing qualification after '.'
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
[11:1-11:2] ERROR Missing qualification after '.'
[9:1-9:2] ERROR Missing qualification after '.'
[9:0-9:1] ERROR The value or constructor 'X' is not defined
[11:0-11:1] ERROR The value or constructor 'X' is not defined
[9:2-9:3] ERROR Missing qualification after '.'
[11:2-11:3] ERROR Missing qualification after '.'
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
[11:2-11:3] ERROR Missing qualification after '.'
[9:2-9:3] ERROR Missing qualification after '.'
[9:1-9:2] ERROR The value or constructor 'X' is not defined
[11:1-11:2] ERROR The value or constructor 'X' is not defined
<<EOF>>
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[9:1-9:2] ERROR Missing qualification after '.'
[11:1-11:2] ERROR Missing qualification after '.'
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
[11:1-11:2] ERROR Missing qualification after '.'
[9:1-9:2] ERROR Missing qualification after '.'
[9:0-9:1] ERROR The value or constructor 'Y' is not defined
[11:0-11:1] ERROR The value or constructor 'Y' is not defined
[9:2-9:3] ERROR Missing qualification after '.'
[11:2-11:3] ERROR Missing qualification after '.'
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
[11:2-11:3] ERROR Missing qualification after '.'
[9:2-9:3] ERROR Missing qualification after '.'
[9:1-9:2] ERROR The value or constructor 'Y' is not defined
[11:1-11:2] ERROR The value or constructor 'Y' is not defined
<<EOF>>
DATA: completion
Another`Column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ func
INFO: Synchronous parsing started
<<EOF>>
DATA: errors
[4:14-4:21] ERROR The namespace or module 'FileTwo' is not defined
[8:11-8:27] ERROR Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
[4:15-4:22] ERROR The namespace or module 'FileTwo' is not defined
[8:12-8:28] ERROR Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
<<EOF>>
DATA: completion
<<EOF>>
14 changes: 14 additions & 0 deletions FSharp.AutoComplete/test/integration/SymbolUse/FileTwo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module FileTwo

type Foo =
| Bar
| Qux

let addition x y = x + y

let add x y = x + y

type NewObjectType() =

member x.Terrific (y : int) : int =
y
20 changes: 20 additions & 0 deletions FSharp.AutoComplete/test/integration/SymbolUse/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module X =
let func x = x + 1

let testval = FileTwo.NewObjectType()

let val2 = X.func 2

let val3 = testval.Terrific val2

let val4 : FileTwo.NewObjectType = testval

let shadowed =
// This shadowed var shouldn't show up when looking for testval above and vice-versa
let testval = 123
testval + 1

[<EntryPoint>]
let main args =
printfn "Hello %d" val2
0
6 changes: 6 additions & 0 deletions FSharp.AutoComplete/test/integration/SymbolUse/Script.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


module XA =
let funky x = x + 1

let val99 = XA.funky 21
75 changes: 75 additions & 0 deletions FSharp.AutoComplete/test/integration/SymbolUse/SymbolUse.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{116CC2F9-F987-4B3D-915A-34CAC04A73DA}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Test1</RootNamespace>
<AssemblyName>Test1</AssemblyName>
<Name>Test1</Name>
<UsePartialTypes>False</UsePartialTypes>
<BuildOrder>
<BuildOrder>
<String>Program.fs</String>
</BuildOrder>
</BuildOrder>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>True</DebugSymbols>
<Optimize>False</Optimize>
<Tailcalls>False</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<DocumentationFile>bin\Debug\Test1.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>True</Optimize>
<Tailcalls>True</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<DocumentationFile>bin\Release\Test1.XML</DocumentationFile>
<DebugSymbols>False</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="FSharp.Core">
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FileTwo.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading