Skip to content

Commit 4621181

Browse files
committed
Merge pull request #34 from rojepp/symbol_uses
Symbol uses
2 parents bfd4c7d + ae5a618 commit 4621181

File tree

19 files changed

+633
-389
lines changed

19 files changed

+633
-389
lines changed

FSharp.AutoComplete/Program.fs

Lines changed: 95 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,50 @@ type MethodResponse =
8585
Overloads : Overload list
8686
}
8787

88+
type SymbolUseRange =
89+
{
90+
Filename: string
91+
StartLine: int
92+
StartColumn: int
93+
EndLine: int
94+
EndColumn: int
95+
IsFromDefinition: bool
96+
IsFromAttribute : bool
97+
IsFromComputationExpression : bool
98+
IsFromDispatchSlotImplementation : bool
99+
IsFromPattern : bool
100+
IsFromType : bool
101+
}
102+
103+
type SymbolUseResponse =
104+
{
105+
Name: string
106+
Uses: SymbolUseRange list
107+
}
108+
109+
type FSharpErrorInfo =
110+
{
111+
FileName: string
112+
StartLine:int
113+
EndLine:int
114+
StartColumn:int
115+
EndColumn:int
116+
Severity:FSharpErrorSeverity
117+
Message:string
118+
Subcategory:string
119+
}
120+
static member OfFSharpError(e:Microsoft.FSharp.Compiler.FSharpErrorInfo) =
121+
{
122+
FileName = e.FileName
123+
StartLine = e.StartLineAlternate
124+
EndLine = e.EndLineAlternate
125+
StartColumn = e.StartColumn + 1
126+
EndColumn = e.EndColumn + 1
127+
Severity = e.Severity
128+
Message = e.Message
129+
Subcategory = e.Subcategory
130+
}
131+
88132
type FSharpErrorSeverityConverter() =
89133
inherit JsonConverter()
90134

@@ -106,9 +150,18 @@ type RangeConverter() =
106150

107151
override x.CanConvert(t:System.Type) = t = typeof<Range.range>
108152

109-
override x.WriteJson(writer, value, serializer) =
153+
override x.WriteJson(writer, value, _serializer) =
110154
let range = value :?> Range.range
111-
serializer.Serialize(writer, (range.Start, range.End))
155+
writer.WriteStartObject()
156+
writer.WritePropertyName("StartColumn")
157+
writer.WriteValue(range.StartColumn + 1)
158+
writer.WritePropertyName("StartLine")
159+
writer.WriteValue(range.StartLine)
160+
writer.WritePropertyName("EndColumn")
161+
writer.WriteValue(range.EndColumn + 1)
162+
writer.WritePropertyName("EndLine")
163+
writer.WriteValue(range.EndLine)
164+
writer.WriteEndObject()
112165

113166
override x.ReadJson(_reader, _t, _, _serializer) =
114167
raise (System.NotSupportedException())
@@ -144,6 +197,8 @@ module internal CommandInput =
144197
helptext <candidate>
145198
- fetch type signature for specified completion candidate
146199
(from last completion request). Only use in JSON mode.
200+
symboluse ""<filename>"" <line> <col> [timeout]
201+
- find all uses of the symbol for the specified location
147202
tooltip ""<filename>"" <line> <col> [timeout]
148203
- get tool tip for the specified location
149204
finddecl ""<filename>"" <line> <col> [timeout]
@@ -188,6 +243,7 @@ module internal CommandInput =
188243
type PosCommand =
189244
| Completion
190245
| Methods
246+
| SymbolUse
191247
| ToolTip
192248
| FindDeclaration
193249

@@ -260,6 +316,7 @@ module internal CommandInput =
260316
// Parse 'completion "<filename>" <line> <col> [timeout]' command
261317
let completionTipOrDecl = parser {
262318
let! f = (string "completion " |> Parser.map (fun _ -> Completion)) <|>
319+
(string "symboluse " |> Parser.map (fun _ -> SymbolUse)) <|>
263320
(string "tooltip " |> Parser.map (fun _ -> ToolTip)) <|>
264321
(string "methods " |> Parser.map (fun _ -> Methods)) <|>
265322
(string "finddecl " |> Parser.map (fun _ -> FindDeclaration))
@@ -456,12 +513,13 @@ module internal Main =
456513
match results.GetErrors() with
457514
| None -> ()
458515
| Some errs ->
516+
let errs = errs |> Seq.map FSharpErrorInfo.OfFSharpError
459517
match state.OutputMode with
460518
| Text ->
461519
let sb = new System.Text.StringBuilder()
462520
sb.AppendLine("DATA: errors") |> ignore
463521
for e in errs do
464-
sb.AppendLine(sprintf "[%d:%d-%d:%d] %s %s" e.StartLineAlternate e.StartColumn e.EndLineAlternate e.EndColumn
522+
sb.AppendLine(sprintf "[%d:%d-%d:%d] %s %s" e.StartLine e.StartColumn e.EndLine e.EndColumn
465523
(if e.Severity = FSharpErrorSeverity.Error then "ERROR" else "WARNING") e.Message)
466524
|> ignore
467525
sb.Append("<<EOF>>") |> ignore
@@ -521,11 +579,11 @@ module internal Main =
521579
let declstrings =
522580
[ for tld in decls do
523581
let m = tld.Declaration.Range
524-
let (s1, e1), (s2, e2) = ((m.StartColumn, m.StartLine), (m.EndColumn, m.EndLine))
582+
let (s1, e1), (s2, e2) = ((m.StartColumn + 1, m.StartLine), (m.EndColumn + 1, m.EndLine))
525583
yield sprintf "[%d:%d-%d:%d] %s" e1 s1 e2 s2 tld.Declaration.Name
526584
for d in tld.Nested do
527585
let m = d.Range
528-
let (s1, e1), (s2, e2) = ((m.StartColumn, m.StartLine), (m.EndColumn, m.EndLine))
586+
let (s1, e1), (s2, e2) = ((m.StartColumn + 1, m.StartLine), (m.EndColumn + 1, m.EndLine))
529587
yield sprintf " - [%d:%d-%d:%d] %s" e1 s1 e2 s2 d.Name ]
530588
printAgent.WriteLine(sprintf "DATA: declarations\n%s\n<<EOF>>" (String.concat "\n" declstrings))
531589
| Json -> prAsJson { Kind = "declarations"; Data = decls }
@@ -617,6 +675,36 @@ module internal Main =
617675

618676
main state
619677

678+
| SymbolUse ->
679+
let symboluses =
680+
async {
681+
let! symboluse = tyRes.GetSymbol(line, col, lineStr)
682+
if symboluse.IsNone then return None else
683+
let! symboluses = tyRes.GetUsesOfSymbolInFile symboluse.Value.Symbol
684+
return Some {
685+
Name = symboluse.Value.Symbol.DisplayName
686+
Uses =
687+
[ for su in symboluses do
688+
yield { StartLine = su.RangeAlternate.StartLine
689+
StartColumn = su.RangeAlternate.StartColumn + 1
690+
EndLine = su.RangeAlternate.EndLine
691+
EndColumn = su.RangeAlternate.EndColumn + 1
692+
Filename = su.FileName
693+
IsFromDefinition = su.IsFromDefinition
694+
IsFromAttribute = su.IsFromAttribute
695+
IsFromComputationExpression = su.IsFromComputationExpression
696+
IsFromDispatchSlotImplementation = su.IsFromDispatchSlotImplementation
697+
IsFromPattern = su.IsFromPattern
698+
IsFromType = su.IsFromType } ] } }
699+
|> Async.RunSynchronously
700+
701+
match state.OutputMode, symboluses with
702+
| Text, _ -> printMsg "ERROR" "symboluse not supported in text mode"
703+
| Json, Some su -> prAsJson { Kind = "symboluse"; Data = su }
704+
| _ -> printMsg "ERROR" "No symbols found"
705+
706+
main state
707+
620708
| FindDeclaration ->
621709
let declarations = tyRes.GetDeclarationLocation(line,col,lineStr)
622710
|> Async.RunSynchronously
@@ -625,9 +713,9 @@ module internal Main =
625713
| FSharpFindDeclResult.DeclFound range ->
626714

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

633721
main state

FSharp.AutoComplete/test/integration/CompletionFilter/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
INFO: Synchronous parsing started
22
<<EOF>>
33
DATA: errors
4-
[2:5-2:6] ERROR The value, constructor, namespace or type 'c' is not defined
4+
[2:6-2:7] ERROR The value, constructor, namespace or type 'c' is not defined
55
<<EOF>>
66
DATA: completion
77
Cons

FSharp.AutoComplete/test/integration/ErrorTests/output.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ DATA: project
55
INFO: Synchronous parsing started
66
<<EOF>>
77
DATA: errors
8-
[4:14-4:21] ERROR The namespace or module 'FileTwo' is not defined
9-
[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-
[10:18-10:22] ERROR This expression was expected to have type
8+
[4:15-4:22] ERROR The namespace or module 'FileTwo' is not defined
9+
[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+
[10:19-10:23] ERROR This expression was expected to have type
1111
int
1212
but here has type
1313
string
@@ -18,7 +18,7 @@ func
1818
INFO: Synchronous parsing started
1919
<<EOF>>
2020
DATA: errors
21-
[8:12-8:19] ERROR The value or constructor 'unnamed' is not defined
21+
[8:13-8:20] ERROR The value or constructor 'unnamed' is not defined
2222
<<EOF>>
2323
DATA: completion
2424
func

FSharp.AutoComplete/test/integration/ErrorTestsJson/output.json

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,34 @@
2424
"Kind": "errors",
2525
"Data": [
2626
{
27-
"StartLine": 3,
28-
"StartLineAlternate": 4,
29-
"EndLine": 3,
30-
"EndLineAlternate": 4,
31-
"StartColumn": 14,
32-
"EndColumn": 21,
27+
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Program.fs",
28+
"StartLine": 4,
29+
"EndLine": 4,
30+
"StartColumn": 15,
31+
"EndColumn": 22,
3332
"Severity": "Error",
3433
"Message": "The namespace or module 'FileTwo' is not defined",
35-
"Subcategory": "typecheck",
36-
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Program.fs"
34+
"Subcategory": "typecheck"
3735
},
3836
{
39-
"StartLine": 7,
40-
"StartLineAlternate": 8,
41-
"EndLine": 7,
42-
"EndLineAlternate": 8,
43-
"StartColumn": 11,
44-
"EndColumn": 27,
37+
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Program.fs",
38+
"StartLine": 8,
39+
"EndLine": 8,
40+
"StartColumn": 12,
41+
"EndColumn": 28,
4542
"Severity": "Error",
4643
"Message": "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.",
47-
"Subcategory": "typecheck",
48-
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Program.fs"
44+
"Subcategory": "typecheck"
4945
},
5046
{
51-
"StartLine": 9,
52-
"StartLineAlternate": 10,
53-
"EndLine": 9,
54-
"EndLineAlternate": 10,
55-
"StartColumn": 18,
56-
"EndColumn": 22,
47+
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Program.fs",
48+
"StartLine": 10,
49+
"EndLine": 10,
50+
"StartColumn": 19,
51+
"EndColumn": 23,
5752
"Severity": "Error",
5853
"Message": "This expression was expected to have type\n int \nbut here has type\n string ",
59-
"Subcategory": "typecheck",
60-
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Program.fs"
54+
"Subcategory": "typecheck"
6155
}
6256
]
6357
}
@@ -69,16 +63,14 @@
6963
"Kind": "errors",
7064
"Data": [
7165
{
72-
"StartLine": 7,
73-
"StartLineAlternate": 8,
74-
"EndLine": 7,
75-
"EndLineAlternate": 8,
76-
"StartColumn": 12,
77-
"EndColumn": 19,
66+
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Script.fsx",
67+
"StartLine": 8,
68+
"EndLine": 8,
69+
"StartColumn": 13,
70+
"EndColumn": 20,
7871
"Severity": "Error",
7972
"Message": "The value or constructor 'unnamed' is not defined",
80-
"Subcategory": "typecheck",
81-
"FileName": "<absolute path removed>/test/integration/ErrorTestsJson/Script.fsx"
73+
"Subcategory": "typecheck"
8274
}
8375
]
8476
}

FSharp.AutoComplete/test/integration/FindDeclarations/output.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ INFO: Synchronous parsing started
1515
DATA: errors
1616
<<EOF>>
1717
DATA: finddecl
18-
<absolute path removed>/test/integration/FindDeclarations/Program.fs:2:6
18+
<absolute path removed>/test/integration/FindDeclarations/Program.fs:2:7
1919
<<EOF>>
2020
DATA: finddecl
21-
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:13:11
21+
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:13:12
2222
<<EOF>>
2323
DATA: finddecl
24-
<absolute path removed>/test/integration/FindDeclarations/Program.fs:6:4
24+
<absolute path removed>/test/integration/FindDeclarations/Program.fs:6:5
2525
<<EOF>>
2626
DATA: finddecl
27-
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:11:5
27+
<absolute path removed>/test/integration/FindDeclarations/FileTwo.fs:11:6
2828
<<EOF>>
2929
DATA: finddecl
30-
<absolute path removed>/test/integration/FindDeclarations/Script.fsx:4:6
30+
<absolute path removed>/test/integration/FindDeclarations/Script.fsx:4:7
3131
<<EOF>>

FSharp.AutoComplete/test/integration/MultipleUnsavedFiles/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ DATA: errors
1717
INFO: Synchronous parsing started
1818
<<EOF>>
1919
DATA: errors
20-
[1:22-1:28] ERROR The value, constructor, namespace or type 'addTwo' is not defined
20+
[1:23-1:29] ERROR The value, constructor, namespace or type 'addTwo' is not defined
2121
<<EOF>>

FSharp.AutoComplete/test/integration/OutOfRange/output.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
INFO: Synchronous parsing started
22
<<EOF>>
33
DATA: errors
4-
[6:14-6:15] ERROR Missing qualification after '.'
5-
[6:14-6:15] ERROR Missing qualification after '.'
6-
[6:12-6:14] ERROR The value or constructor 'XA' is not defined
4+
[6:15-6:16] ERROR Missing qualification after '.'
5+
[6:15-6:16] ERROR Missing qualification after '.'
6+
[6:13-6:15] ERROR The value or constructor 'XA' is not defined
77
<<EOF>>
88
ERROR: Position is out of range
99
<<EOF>>
@@ -22,7 +22,7 @@ INFO: No tooltip information
2222
ERROR: Position is out of range
2323
<<EOF>>
2424
DATA: finddecl
25-
<absolute path removed>/test/integration/OutOfRange/Script.fsx:3:7
25+
<absolute path removed>/test/integration/OutOfRange/Script.fsx:3:8
2626
<<EOF>>
2727
ERROR: Could not find declaration
2828
<<EOF>>

FSharp.AutoComplete/test/integration/RawIdTest/output.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
INFO: Synchronous parsing started
22
<<EOF>>
33
DATA: errors
4-
[9:1-9:2] ERROR Missing qualification after '.'
5-
[11:1-11:2] ERROR Missing qualification after '.'
6-
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
7-
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
8-
[11:1-11:2] ERROR Missing qualification after '.'
9-
[9:1-9:2] ERROR Missing qualification after '.'
10-
[9:0-9:1] ERROR The value or constructor 'X' is not defined
11-
[11:0-11:1] ERROR The value or constructor 'X' is not defined
4+
[9:2-9:3] ERROR Missing qualification after '.'
5+
[11:2-11:3] ERROR Missing qualification after '.'
6+
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
7+
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
8+
[11:2-11:3] ERROR Missing qualification after '.'
9+
[9:2-9:3] ERROR Missing qualification after '.'
10+
[9:1-9:2] ERROR The value or constructor 'X' is not defined
11+
[11:1-11:2] ERROR The value or constructor 'X' is not defined
1212
<<EOF>>
1313
INFO: Synchronous parsing started
1414
<<EOF>>
1515
DATA: errors
16-
[9:1-9:2] ERROR Missing qualification after '.'
17-
[11:1-11:2] ERROR Missing qualification after '.'
18-
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
19-
[11:2-11:3] ERROR Unexpected reserved keyword in implementation file
20-
[11:1-11:2] ERROR Missing qualification after '.'
21-
[9:1-9:2] ERROR Missing qualification after '.'
22-
[9:0-9:1] ERROR The value or constructor 'Y' is not defined
23-
[11:0-11:1] ERROR The value or constructor 'Y' is not defined
16+
[9:2-9:3] ERROR Missing qualification after '.'
17+
[11:2-11:3] ERROR Missing qualification after '.'
18+
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
19+
[11:3-11:4] ERROR Unexpected reserved keyword in implementation file
20+
[11:2-11:3] ERROR Missing qualification after '.'
21+
[9:2-9:3] ERROR Missing qualification after '.'
22+
[9:1-9:2] ERROR The value or constructor 'Y' is not defined
23+
[11:1-11:2] ERROR The value or constructor 'Y' is not defined
2424
<<EOF>>
2525
DATA: completion
2626
Another`Column

FSharp.AutoComplete/test/integration/RobustCommands/completewithoutproject.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ func
88
INFO: Synchronous parsing started
99
<<EOF>>
1010
DATA: errors
11-
[4:14-4:21] ERROR The namespace or module 'FileTwo' is not defined
12-
[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.
11+
[4:15-4:22] ERROR The namespace or module 'FileTwo' is not defined
12+
[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.
1313
<<EOF>>
1414
DATA: completion
1515
<<EOF>>

0 commit comments

Comments
 (0)