Skip to content

Commit 4964847

Browse files
committed
Various fixes
1 parent 95bd02d commit 4964847

12 files changed

+119
-97
lines changed

vsintegration/src/FSharp.Editor/AutomaticCompletion/BraceCompletionSessionProvider.fs

+11-10
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,17 @@ type EditorBraceCompletionSessionFactory() =
499499
let sourceCode = sourceCodeTask.Result
500500

501501
position = 0
502-
|| (let colorizationData =
503-
Tokenizer.getClassifiedSpans (
504-
document.Id,
505-
sourceCode,
506-
TextSpan(position - 1, 1),
507-
Some(document.FilePath),
508-
[],
509-
None,
510-
None,
511-
cancellationToken
502+
|| (let colorizationData = ResizeArray<_>()
503+
Tokenizer.classifySpans (
504+
document.Id,
505+
sourceCode,
506+
TextSpan(position - 1, 1),
507+
Some(document.FilePath),
508+
[],
509+
None,
510+
None,
511+
colorizationData,
512+
cancellationToken
512513
)
513514

514515
colorizationData.Count = 0

vsintegration/src/FSharp.Editor/Classification/ClassificationService.fs

+14-12
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
172172
match! syntacticClassificationCache.TryGetValueAsync document with
173173
| ValueSome classifiedSpansDict ->
174174
match classifiedSpansDict.TryGetValue(textSpan) with
175-
| true, classifiedSpans -> result.AddRange(classifiedSpans)
175+
| true, _ ->
176+
// if we already classified these spans in the _closed_ document, don't add them to result again
177+
()
176178
| _ ->
177179
let classifiedSpans =
178180
getLexicalClassifications (document.FilePath, defines, sourceText, textSpan, cancellationToken)
@@ -192,18 +194,18 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
192194

193195
result.AddRange(classifiedSpans)
194196
else
195-
result.AddRange(
196-
Tokenizer.getClassifiedSpans (
197-
document.Id,
198-
sourceText,
199-
textSpan,
200-
Some(document.FilePath),
201-
defines,
202-
Some langVersion,
203-
strictIndentation,
204-
cancellationToken
205-
)
197+
Tokenizer.classifySpans (
198+
document.Id,
199+
sourceText,
200+
textSpan,
201+
Some(document.FilePath),
202+
defines,
203+
Some langVersion,
204+
strictIndentation,
205+
result,
206+
cancellationToken
206207
)
208+
207209
}
208210
|> CancellableTask.startAsTask cancellationToken
209211

vsintegration/src/FSharp.Editor/Commands/HelpContextService.fs

+13-11
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,19 @@ type internal FSharpHelpContextService [<ImportingConstructor>] () =
116116

117117
let textLine = sourceText.Lines.GetLineFromPosition(textSpan.Start)
118118

119-
let classifiedSpans =
120-
Tokenizer.getClassifiedSpans (
121-
document.Id,
122-
sourceText,
123-
textLine.Span,
124-
Some document.Name,
125-
defines,
126-
Some langVersion,
127-
strictIndentation,
128-
cancellationToken
129-
)
119+
let classifiedSpans = ResizeArray<_>()
120+
121+
Tokenizer.classifySpans (
122+
document.Id,
123+
sourceText,
124+
textLine.Span,
125+
Some document.Name,
126+
defines,
127+
Some langVersion,
128+
strictIndentation,
129+
classifiedSpans,
130+
cancellationToken
131+
)
130132

131133
return! FSharpHelpContextService.GetHelpTerm(document, textSpan, classifiedSpans)
132134
}

vsintegration/src/FSharp.Editor/Completion/CompletionUtils.fs

+16-13
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,19 @@ module internal CompletionUtils =
104104
let textLines = sourceText.Lines
105105
let triggerLine = textLines.GetLineFromPosition triggerPosition
106106

107-
let classifiedSpans =
108-
Tokenizer.getClassifiedSpans (
109-
documentId,
110-
sourceText,
111-
triggerLine.Span,
112-
Some filePath,
113-
defines,
114-
langVersion,
115-
strictIndentation,
116-
ct
117-
)
107+
let classifiedSpans = ResizeArray<_>()
108+
109+
Tokenizer.classifySpans (
110+
documentId,
111+
sourceText,
112+
triggerLine.Span,
113+
Some filePath,
114+
defines,
115+
langVersion,
116+
strictIndentation,
117+
classifiedSpans,
118+
ct
119+
)
118120

119121
classifiedSpans.Count = 0
120122
|| // we should provide completion at the start of empty line, where there are no tokens at all
@@ -189,8 +191,9 @@ module internal CompletionUtils =
189191
// backticks before later valid backticks on a line, this is an acceptable compromise in order to support
190192
// the majority of common cases.
191193

192-
let classifiedSpans =
193-
Tokenizer.getClassifiedSpans (documentId, sourceText, line.Span, Some filePath, defines, langVersion, strictIndentation, ct)
194+
let classifiedSpans = ResizeArray<_>()
195+
196+
Tokenizer.classifySpans (documentId, sourceText, line.Span, Some filePath, defines, langVersion, strictIndentation, classifiedSpans, ct)
194197

195198
let inline isBacktickIdentifier (classifiedSpan: ClassifiedSpan) =
196199
classifiedSpan.ClassificationType = ClassificationTypeNames.Identifier

vsintegration/src/FSharp.Editor/Completion/HashDirectiveCompletionProvider.fs

+6-1
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,22 @@ type internal HashDirectiveCompletionProvider
7474
let textLines = text.Lines
7575
let triggerLine = textLines.GetLineFromPosition(position)
7676

77-
Tokenizer.getClassifiedSpans (
77+
let classifiedSpans = ResizeArray<_>()
78+
79+
Tokenizer.classifySpans (
7880
documentId,
7981
text,
8082
triggerLine.Span,
8183
Some document.FilePath,
8284
defines,
8385
Some langVersion,
8486
strictIndentation,
87+
classifiedSpans,
8588
CancellationToken.None
8689
)
8790

91+
classifiedSpans
92+
8893
let isInStringLiteral (text: SourceText, position: int) : bool =
8994
getClassifiedSpans (text, position)
9095
|> Seq.exists (fun classifiedSpan ->

vsintegration/src/FSharp.Editor/Debugging/LanguageDebugInfoService.fs

+13-11
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,19 @@ type internal FSharpLanguageDebugInfoService [<ImportingConstructor>] () =
6262
let! sourceText = document.GetTextAsync(cancellationToken)
6363
let textSpan = TextSpan.FromBounds(0, sourceText.Length)
6464

65-
let classifiedSpans =
66-
Tokenizer.getClassifiedSpans (
67-
document.Id,
68-
sourceText,
69-
textSpan,
70-
Some(document.Name),
71-
defines,
72-
Some langVersion,
73-
strictIndentation,
74-
cancellationToken
75-
)
65+
let classifiedSpans = ResizeArray<_>()
66+
67+
Tokenizer.classifySpans (
68+
document.Id,
69+
sourceText,
70+
textSpan,
71+
Some(document.Name),
72+
defines,
73+
Some langVersion,
74+
strictIndentation,
75+
classifiedSpans,
76+
cancellationToken
77+
)
7678

7779
let result =
7880
match FSharpLanguageDebugInfoService.GetDataTipInformation(sourceText, position, classifiedSpans) with

vsintegration/src/FSharp.Editor/LanguageService/Tokenizer.fs

+4-5
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ module internal Tokenizer =
684684
]
685685

686686
/// Generates a list of Classified Spans for tokens which undergo syntactic classification (i.e., are not typechecked).
687-
let getClassifiedSpans
687+
let classifySpans
688688
(
689689
documentKey: DocumentId,
690690
sourceText: SourceText,
@@ -693,10 +693,9 @@ module internal Tokenizer =
693693
defines: string list,
694694
langVersion,
695695
strictIndentation,
696+
result: ResizeArray<ClassifiedSpan>,
696697
cancellationToken: CancellationToken
697-
) : ResizeArray<ClassifiedSpan> =
698-
699-
let result = new ResizeArray<ClassifiedSpan>()
698+
) : unit =
700699

701700
try
702701
let sourceTokenizer =
@@ -724,7 +723,7 @@ module internal Tokenizer =
724723
| :? OperationCanceledException -> reraise ()
725724
| ex -> Assert.Exception(ex)
726725

727-
result
726+
()
728727

729728
let inline (||>) struct (arg1, arg2) ([<InlineIfLambda>] func: 'T1 -> 'T2 -> 'T3) = func arg1 arg2
730729

vsintegration/src/FSharp.Editor/Navigation/FindUsagesService.fs

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type internal FSharpFindUsagesService [<ImportingConstructor>] () =
6363
let! _, checkFileResults =
6464
document.GetFSharpParseAndCheckResultsAsync(nameof (FSharpFindUsagesService))
6565
|> CancellableTask.start context.CancellationToken
66+
|> Async.AwaitTask
67+
|> liftAsync
6668

6769
let! symbolUse =
6870
checkFileResults.GetSymbolUseAtLocation(lineNumber, symbol.Ident.idRange.EndColumn, textLine, symbol.FullIsland)

vsintegration/src/FSharp.Editor/Navigation/GoToDefinition.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
570570
&& symbol1.DeclaringEntity.CompiledName = symbol2.DeclaringEntity.CompiledName
571571
| _ -> false)
572572
|> ValueOption.map (fun x -> x.Range)
573-
|> Option.ofValueOption
573+
|> ValueOption.toOption
574574

575575
let span =
576576
match RoslynHelpers.TryFSharpRangeToTextSpan(tmpShownDoc.GetTextAsync(cancellationToken).Result, r) with

vsintegration/tests/FSharp.Editor.Tests/HelpContextServiceTests.fs

+13-11
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,19 @@ type HelpContextServiceTests() =
4242
let textLine = sourceText.Lines.GetLineFromPosition(marker)
4343
let documentId = DocumentId.CreateNewId(ProjectId.CreateNewId())
4444

45-
let classifiedSpans =
46-
Tokenizer.getClassifiedSpans (
47-
documentId,
48-
sourceText,
49-
textLine.Span,
50-
Some "test.fs",
51-
[],
52-
None,
53-
None,
54-
CancellationToken.None
55-
)
45+
let classifiedSpans = ResizeArray<_>()
46+
47+
Tokenizer.classifySpans (
48+
documentId,
49+
sourceText,
50+
textLine.Span,
51+
Some "test.fs",
52+
[],
53+
None,
54+
None,
55+
classifiedSpans,
56+
CancellationToken.None
57+
)
5658

5759
let task =
5860
FSharpHelpContextService.GetHelpTerm(document, span, classifiedSpans)

vsintegration/tests/FSharp.Editor.Tests/LanguageDebugInfoServiceTests.fs

+13-11
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,19 @@ let main argv =
5252
let sourceText = SourceText.From(code)
5353
let documentId = DocumentId.CreateNewId(ProjectId.CreateNewId())
5454

55-
let classifiedSpans =
56-
Tokenizer.getClassifiedSpans (
57-
documentId,
58-
sourceText,
59-
TextSpan.FromBounds(0, sourceText.Length),
60-
Some(fileName),
61-
defines,
62-
None,
63-
None,
64-
CancellationToken.None
65-
)
55+
let classifiedSpans = ResizeArray<_>()
56+
57+
Tokenizer.classifySpans (
58+
documentId,
59+
sourceText,
60+
TextSpan.FromBounds(0, sourceText.Length),
61+
Some(fileName),
62+
defines,
63+
None,
64+
None,
65+
classifiedSpans,
66+
CancellationToken.None
67+
)
6668

6769
let actualDataTipSpanOption =
6870
FSharpLanguageDebugInfoService.GetDataTipInformation(sourceText, searchPosition, classifiedSpans)

vsintegration/tests/FSharp.Editor.Tests/SyntacticColorizationServiceTests.fs

+13-11
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ type SyntacticClassificationServiceTests() =
3030

3131
let documentId = DocumentId.CreateNewId(ProjectId.CreateNewId())
3232

33-
let tokens =
34-
Tokenizer.getClassifiedSpans (
35-
documentId,
36-
SourceText.From(fileContents),
37-
textSpan,
38-
Some(fileName),
39-
defines,
40-
langVersion,
41-
None,
42-
CancellationToken.None
43-
)
33+
let tokens = ResizeArray<_>()
34+
35+
Tokenizer.classifySpans (
36+
documentId,
37+
SourceText.From(fileContents),
38+
textSpan,
39+
Some(fileName),
40+
defines,
41+
langVersion,
42+
None,
43+
tokens,
44+
CancellationToken.None
45+
)
4446

4547
let markerPosition = fileContents.IndexOf(marker)
4648
Assert.True(markerPosition >= 0, $"Cannot find marker '{marker}' in file contents")

0 commit comments

Comments
 (0)