Skip to content

Commit 4a1e094

Browse files
committed
Various fixes
1 parent 4964847 commit 4a1e094

18 files changed

+57
-43
lines changed

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

+3-35
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
123123
let semanticClassificationCache =
124124
new DocumentCache<SemanticClassificationLookup>("fsharp-semantic-classification-cache")
125125

126-
// We don't really care here about concurrency in neither DocumentCahce, nor underlying hashmap.
127-
let syntacticClassificationCache =
128-
new DocumentCache<Dictionary<TextSpan, ImmutableArray<ClassifiedSpan>>>(
129-
"fsharp-syntactic-classification-cache",
130-
CacheItemPolicy(SlidingExpiration = (TimeSpan.FromMinutes 5))
131-
)
132-
133126
interface IFSharpClassificationService with
134127
// Do not perform classification if we don't have project options (#defines matter)
135128
member _.AddLexicalClassifications(_: SourceText, _: TextSpan, _: List<ClassifiedSpan>, _: CancellationToken) = ()
@@ -167,32 +160,8 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
167160
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSyntacticCalssifications, eventProps)
168161

169162
if not isOpenDocument then
170-
// If called concurrently, it'll likely race here (in both getting and setting/adding to underlying dictionary)
171-
// But we don't really care for such small caches, will change the implementation if it shows that it's a problem.
172-
match! syntacticClassificationCache.TryGetValueAsync document with
173-
| ValueSome classifiedSpansDict ->
174-
match classifiedSpansDict.TryGetValue(textSpan) with
175-
| true, _ ->
176-
// if we already classified these spans in the _closed_ document, don't add them to result again
177-
()
178-
| _ ->
179-
let classifiedSpans =
180-
getLexicalClassifications (document.FilePath, defines, sourceText, textSpan, cancellationToken)
181-
182-
classifiedSpansDict.Add(textSpan, classifiedSpans)
183-
result.AddRange(classifiedSpans)
184-
| ValueNone ->
185-
186-
let classifiedSpans =
187-
getLexicalClassifications (document.FilePath, defines, sourceText, textSpan, cancellationToken)
188-
189-
let classifiedSpansDict = Dictionary<TextSpan, ImmutableArray<ClassifiedSpan>>()
190-
191-
do! syntacticClassificationCache.SetAsync(document, classifiedSpansDict)
192-
193-
do classifiedSpansDict[textSpan] <- classifiedSpans
194-
195-
result.AddRange(classifiedSpans)
163+
let classifiedSpans = getLexicalClassifications (document.FilePath, defines, sourceText, textSpan, cancellationToken)
164+
result.AddRange(classifiedSpans)
196165
else
197166
Tokenizer.classifySpans (
198167
document.Id,
@@ -204,8 +173,7 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
204173
strictIndentation,
205174
result,
206175
cancellationToken
207-
)
208-
176+
)
209177
}
210178
|> CancellableTask.startAsTask cancellationToken
211179

vsintegration/src/FSharp.Editor/CodeFixes/AddOpenCodeFixProvider.fs

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ type internal AddOpenCodeFixProvider [<ImportingConstructor>] (assemblyContentPr
7171
let! parseResults, checkResults =
7272
document.GetFSharpParseAndCheckResultsAsync(nameof (AddOpenCodeFixProvider))
7373
|> CancellableTask.start context.CancellationToken
74+
|> Async.AwaitTask
75+
|> liftAsync
7476

7577
let line = sourceText.Lines.GetLineFromPosition(context.Span.End)
7678
let linePos = sourceText.Lines.GetLinePosition(context.Span.End)

vsintegration/src/FSharp.Editor/CodeFixes/AddTypeAnnotationToObjectOfIndeterminateType.fs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type internal AddTypeAnnotationToObjectOfIndeterminateTypeFixProvider [<Importin
4747
let! _, checkFileResults =
4848
document.GetFSharpParseAndCheckResultsAsync(nameof (AddTypeAnnotationToObjectOfIndeterminateTypeFixProvider))
4949
|> CancellableTask.start context.CancellationToken
50+
|> Async.AwaitTask
51+
|> liftAsync
5052

5153
let decl =
5254
checkFileResults.GetDeclarationLocation(

vsintegration/src/FSharp.Editor/CodeFixes/ImplementInterfaceCodeFixProvider.fs

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ type internal ImplementInterfaceCodeFixProvider [<ImportingConstructor>] () =
195195
let! parseResults, checkFileResults =
196196
context.Document.GetFSharpParseAndCheckResultsAsync(nameof (ImplementInterfaceCodeFixProvider))
197197
|> CancellableTask.start ct
198+
|> Async.AwaitTask
199+
|> liftAsync
198200

199201
let cancellationToken = context.CancellationToken
200202
let! sourceText = context.Document.GetTextAsync(cancellationToken)
@@ -203,6 +205,8 @@ type internal ImplementInterfaceCodeFixProvider [<ImportingConstructor>] () =
203205
let! _, _, parsingOptions, _ =
204206
context.Document.GetFSharpCompilationOptionsAsync(nameof (ImplementInterfaceCodeFixProvider))
205207
|> CancellableTask.start ct
208+
|> Async.AwaitTask
209+
|> liftAsync
206210

207211
let defines = CompilerEnvironment.GetConditionalDefinesForEditing parsingOptions
208212
let langVersionOpt = Some parsingOptions.LangVersionText

vsintegration/src/FSharp.Editor/CodeFixes/MakeDeclarationMutable.fs

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type internal MakeDeclarationMutableFixProvider [<ImportingConstructor>] () =
4646
let! parseFileResults, checkFileResults =
4747
document.GetFSharpParseAndCheckResultsAsync(nameof (MakeDeclarationMutableFixProvider))
4848
|> CancellableTask.start context.CancellationToken
49+
|> Async.AwaitTask
50+
|> liftAsync
4951

5052
let decl =
5153
checkFileResults.GetDeclarationLocation(

vsintegration/src/FSharp.Editor/CodeFixes/ReplaceWithSuggestion.fs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type internal ReplaceWithSuggestionCodeFixProvider [<ImportingConstructor>] (set
3030
let! parseFileResults, checkFileResults =
3131
document.GetFSharpParseAndCheckResultsAsync(nameof (ReplaceWithSuggestionCodeFixProvider))
3232
|> CancellableTask.start context.CancellationToken
33+
|> Async.AwaitTask
34+
|> liftAsync
3335

3436
// This is all needed to get a declaration list
3537
let! sourceText = document.GetTextAsync(context.CancellationToken)

vsintegration/src/FSharp.Editor/CodeFixes/UseMutationWhenValueIsMutable.fs

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type internal UseMutationWhenValueIsMutableCodeFixProvider [<ImportingConstructo
5353
let! _, checkFileResults =
5454
document.GetFSharpParseAndCheckResultsAsync(nameof (UseMutationWhenValueIsMutableCodeFixProvider))
5555
|> CancellableTask.start context.CancellationToken
56+
|> Async.AwaitTask
57+
|> liftAsync
5658

5759
let! symbolUse =
5860
checkFileResults.GetSymbolUseAtLocation(

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

+2
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,8 @@ type internal FSharpSignatureHelpProvider [<ImportingConstructor>] (serviceProvi
613613
let! parseResults, checkFileResults =
614614
document.GetFSharpParseAndCheckResultsAsync("ProvideSignatureHelp")
615615
|> CancellableTask.start CancellationToken.None
616+
|> Async.AwaitTask
617+
|> liftAsync
616618

617619
let! sourceText = document.GetTextAsync() |> liftTaskAsync
618620

vsintegration/src/FSharp.Editor/Diagnostics/SimplifyNameDiagnosticAnalyzer.fs

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type internal SimplifyNameDiagnosticAnalyzer [<ImportingConstructor>] () =
5959
let! _, checkResults =
6060
document.GetFSharpParseAndCheckResultsAsync(nameof (SimplifyNameDiagnosticAnalyzer))
6161
|> CancellableTask.start cancellationToken
62+
|> Async.AwaitTask
63+
|> liftAsync
6264

6365
let! result =
6466
SimplifyNames.getSimplifiableNames (

vsintegration/src/FSharp.Editor/Diagnostics/UnusedOpensDiagnosticAnalyzer.fs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type internal UnusedOpensDiagnosticAnalyzer [<ImportingConstructor>] () =
2828
let! _, checkResults =
2929
document.GetFSharpParseAndCheckResultsAsync(nameof (UnusedOpensDiagnosticAnalyzer))
3030
|> CancellableTask.start ct
31+
|> Async.AwaitTask
32+
|> liftAsync
3133

3234
let! unusedOpens =
3335
UnusedOpens.getUnusedOpens (checkResults, (fun lineNumber -> sourceText.Lines.[Line.toZ lineNumber].ToString()))

vsintegration/src/FSharp.Editor/DocumentHighlights/DocumentHighlightsService.fs

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] () =
7676
let! _, checkFileResults =
7777
document.GetFSharpParseAndCheckResultsAsync(nameof (FSharpDocumentHighlightsService))
7878
|> CancellableTask.start ct
79+
|> Async.AwaitTask
80+
|> liftAsync
7981

8082
let! symbolUse =
8183
checkFileResults.GetSymbolUseAtLocation(

vsintegration/src/FSharp.Editor/Formatting/BraceMatchingService.fs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type internal FSharpBraceMatchingService [<ImportingConstructor>] () =
4747
let! checker, _, parsingOptions, _ =
4848
document.GetFSharpCompilationOptionsAsync(nameof (FSharpBraceMatchingService))
4949
|> CancellableTask.start cancellationToken
50+
|> Async.AwaitTask
51+
|> liftAsync
5052

5153
let! sourceText = document.GetTextAsync(cancellationToken)
5254

vsintegration/src/FSharp.Editor/InlineRename/InlineRenameService.fs

+2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ type internal InlineRenameService [<ImportingConstructor>] () =
174174
let! _, checkFileResults =
175175
document.GetFSharpParseAndCheckResultsAsync(nameof (InlineRenameService))
176176
|> CancellableTask.start ct
177+
|> Async.AwaitTask
178+
|> liftAsync
177179

178180
let! symbolUse =
179181
checkFileResults.GetSymbolUseAtLocation(

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

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module internal SymbolHelpers =
2525
let! _, checkFileResults =
2626
document.GetFSharpParseAndCheckResultsAsync(userOpName)
2727
|> CancellableTask.start ct
28+
|> Async.AwaitTask
29+
|> liftAsync
2830

2931
let! defines, langVersion, strictIndentation = document.GetFsharpParsingOptionsAsync(userOpName) |> liftAsync
3032

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ module internal Tokenizer =
453453
member val HashCode = hashCode
454454
member val ClassifiedSpans = classifiedSpans
455455
member val SavedTokens = savedTokens
456+
member val Classified = false with get, set
456457

457458
member data.IsValid(textLine: TextLine) =
458459
data.LineStart = textLine.Start
@@ -662,7 +663,9 @@ module internal Tokenizer =
662663
// 2. the hash codes match
663664
// 3. the start-of-line lex states are the same
664665
match sourceTextDataCache.[i] with
665-
| Some data when data.IsValid(textLine) && data.LexStateAtStartOfLine.Equals(lexState) -> data
666+
| Some data when data.IsValid(textLine) && data.LexStateAtStartOfLine.Equals(lexState) ->
667+
data.Classified <- true
668+
data
666669
| _ ->
667670
// Otherwise, we recompute
668671
let newData = scanSourceLine (sourceTokenizer, textLine, lineContents, lexState)
@@ -711,13 +714,14 @@ module internal Tokenizer =
711714
getFromRefreshedTokenCache (lines, startLine, endLine, sourceTokenizer, sourceTextData, cancellationToken)
712715

713716
for lineData, _ in lineDataResults do
714-
for token in lineData.ClassifiedSpans do
715-
if
716-
(token.TextSpan.Start <= textSpan.Start && textSpan.End <= token.TextSpan.End)
717-
|| textSpan.Contains(token.TextSpan.Start)
718-
|| textSpan.Contains(token.TextSpan.End - 1)
719-
then
720-
result.Add token
717+
if not lineData.Classified then
718+
for token in lineData.ClassifiedSpans do
719+
if
720+
(token.TextSpan.Start <= textSpan.Start && textSpan.End <= token.TextSpan.End)
721+
|| textSpan.Contains(token.TextSpan.Start)
722+
|| textSpan.Contains(token.TextSpan.End - 1)
723+
then
724+
result.Add token
721725

722726
with
723727
| :? OperationCanceledException -> reraise ()

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

+10
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
199199
let! _, checkFileResults =
200200
originDocument.GetFSharpParseAndCheckResultsAsync(nameof (GoToDefinition))
201201
|> CancellableTask.start ct
202+
|> Async.AwaitTask
203+
|> liftAsync
202204

203205
let! fsSymbolUse =
204206
checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, idRange.EndColumn, lineText, lexerSymbol.FullIsland)
@@ -219,6 +221,8 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
219221
let! _, checkFileResults =
220222
implDoc.GetFSharpParseAndCheckResultsAsync(userOpName)
221223
|> CancellableTask.start ct
224+
|> Async.AwaitTask
225+
|> liftAsync
222226

223227
let symbolUses = checkFileResults.GetUsesOfSymbolInFile symbol
224228
let! implSymbol = symbolUses |> Array.tryHead
@@ -243,6 +247,8 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
243247
let! _, checkFileResults =
244248
document.GetFSharpParseAndCheckResultsAsync("FindSymbolDeclarationInDocument")
245249
|> CancellableTask.start ct
250+
|> Async.AwaitTask
251+
|> liftAsync
246252

247253
let symbolUses = checkFileResults.GetUsesOfSymbolInFile targetSymbolUse.Symbol
248254
let! implSymbol = symbolUses |> Array.tryHead
@@ -269,6 +275,8 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
269275
let! _, checkFileResults =
270276
originDocument.GetFSharpParseAndCheckResultsAsync(userOpName)
271277
|> CancellableTask.start ct
278+
|> Async.AwaitTask
279+
|> liftAsync
272280

273281
let declarations =
274282
checkFileResults.GetDeclarationLocation(
@@ -522,6 +530,8 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
522530
let! _, checkResults =
523531
tmpShownDoc.GetFSharpParseAndCheckResultsAsync("NavigateToExternalDeclaration")
524532
|> CancellableTask.start ct
533+
|> Async.AwaitTask
534+
|> liftAsync
525535

526536
let! r =
527537
let rec areTypesEqual (ty1: FSharpType) (ty2: FSharpType) =

vsintegration/src/FSharp.Editor/Refactor/AddExplicitTypeToParameter.fs

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ type internal FSharpAddExplicitTypeToParameterRefactoring [<ImportingConstructor
4444
let! parseFileResults, checkFileResults =
4545
document.GetFSharpParseAndCheckResultsAsync(nameof (FSharpAddExplicitTypeToParameterRefactoring))
4646
|> CancellableTask.start ct
47+
|> Async.AwaitTask
48+
|> liftAsync
4749

4850
let! symbolUse =
4951
checkFileResults.GetSymbolUseAtLocation(

vsintegration/src/FSharp.Editor/TaskList/TaskListService.fs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type internal FSharpTaskListService [<ImportingConstructor>] () as this =
2525
let! _, _, parsingOptions, _ =
2626
doc.GetFSharpCompilationOptionsAsync(nameof (FSharpTaskListService))
2727
|> CancellableTask.start ct
28+
|> Async.AwaitTask
29+
|> liftAsync
2830

2931
return
3032
CompilerEnvironment.GetConditionalDefinesForEditing parsingOptions,

0 commit comments

Comments
 (0)