Skip to content

Commit 5581a1e

Browse files
committed
Revert "Various fixes"
This reverts commit 4a1e094.
1 parent 769fb15 commit 5581a1e

18 files changed

+41
-56
lines changed

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

+33-2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ 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+
126133
interface IFSharpClassificationService with
127134
// Do not perform classification if we don't have project options (#defines matter)
128135
member _.AddLexicalClassifications(_: SourceText, _: TextSpan, _: List<ClassifiedSpan>, _: CancellationToken) = ()
@@ -160,8 +167,32 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
160167
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSyntacticCalssifications, eventProps)
161168

162169
if not isOpenDocument then
163-
let classifiedSpans = getLexicalClassifications (document.FilePath, defines, sourceText, textSpan, cancellationToken)
164-
result.AddRange(classifiedSpans)
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)
165196
else
166197
Tokenizer.classifySpans (
167198
document.Id,

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

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

7775
let line = sourceText.Lines.GetLineFromPosition(context.Span.End)
7876
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,8 +47,6 @@ type internal AddTypeAnnotationToObjectOfIndeterminateTypeFixProvider [<Importin
4747
let! _, checkFileResults =
4848
document.GetFSharpParseAndCheckResultsAsync(nameof (AddTypeAnnotationToObjectOfIndeterminateTypeFixProvider))
4949
|> CancellableTask.start context.CancellationToken
50-
|> Async.AwaitTask
51-
|> liftAsync
5250

5351
let decl =
5452
checkFileResults.GetDeclarationLocation(

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

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

201199
let cancellationToken = context.CancellationToken
202200
let! sourceText = context.Document.GetTextAsync(cancellationToken)
@@ -205,8 +203,6 @@ type internal ImplementInterfaceCodeFixProvider [<ImportingConstructor>] () =
205203
let! _, _, parsingOptions, _ =
206204
context.Document.GetFSharpCompilationOptionsAsync(nameof (ImplementInterfaceCodeFixProvider))
207205
|> CancellableTask.start ct
208-
|> Async.AwaitTask
209-
|> liftAsync
210206

211207
let defines = CompilerEnvironment.GetConditionalDefinesForEditing parsingOptions
212208
let langVersionOpt = Some parsingOptions.LangVersionText

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

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

5250
let decl =
5351
checkFileResults.GetDeclarationLocation(

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

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

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

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

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

5957
let! symbolUse =
6058
checkFileResults.GetSymbolUseAtLocation(

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

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

619617
let! sourceText = document.GetTextAsync() |> liftTaskAsync
620618

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

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

6563
let! result =
6664
SimplifyNames.getSimplifiableNames (

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

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

3432
let! unusedOpens =
3533
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,8 +76,6 @@ type internal FSharpDocumentHighlightsService [<ImportingConstructor>] () =
7676
let! _, checkFileResults =
7777
document.GetFSharpParseAndCheckResultsAsync(nameof (FSharpDocumentHighlightsService))
7878
|> CancellableTask.start ct
79-
|> Async.AwaitTask
80-
|> liftAsync
8179

8280
let! symbolUse =
8381
checkFileResults.GetSymbolUseAtLocation(

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

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

5351
let! sourceText = document.GetTextAsync(cancellationToken)
5452

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

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

180178
let! symbolUse =
181179
checkFileResults.GetSymbolUseAtLocation(

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

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

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

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

+8-12
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ 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
457456

458457
member data.IsValid(textLine: TextLine) =
459458
data.LineStart = textLine.Start
@@ -663,9 +662,7 @@ module internal Tokenizer =
663662
// 2. the hash codes match
664663
// 3. the start-of-line lex states are the same
665664
match sourceTextDataCache.[i] with
666-
| Some data when data.IsValid(textLine) && data.LexStateAtStartOfLine.Equals(lexState) ->
667-
data.Classified <- true
668-
data
665+
| Some data when data.IsValid(textLine) && data.LexStateAtStartOfLine.Equals(lexState) -> data
669666
| _ ->
670667
// Otherwise, we recompute
671668
let newData = scanSourceLine (sourceTokenizer, textLine, lineContents, lexState)
@@ -714,14 +711,13 @@ module internal Tokenizer =
714711
getFromRefreshedTokenCache (lines, startLine, endLine, sourceTokenizer, sourceTextData, cancellationToken)
715712

716713
for lineData, _ in lineDataResults do
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
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
725721

726722
with
727723
| :? OperationCanceledException -> reraise ()

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

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

205203
let! fsSymbolUse =
206204
checkFileResults.GetSymbolUseAtLocation(fcsTextLineNumber, idRange.EndColumn, lineText, lexerSymbol.FullIsland)
@@ -221,8 +219,6 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
221219
let! _, checkFileResults =
222220
implDoc.GetFSharpParseAndCheckResultsAsync(userOpName)
223221
|> CancellableTask.start ct
224-
|> Async.AwaitTask
225-
|> liftAsync
226222

227223
let symbolUses = checkFileResults.GetUsesOfSymbolInFile symbol
228224
let! implSymbol = symbolUses |> Array.tryHead
@@ -247,8 +243,6 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
247243
let! _, checkFileResults =
248244
document.GetFSharpParseAndCheckResultsAsync("FindSymbolDeclarationInDocument")
249245
|> CancellableTask.start ct
250-
|> Async.AwaitTask
251-
|> liftAsync
252246

253247
let symbolUses = checkFileResults.GetUsesOfSymbolInFile targetSymbolUse.Symbol
254248
let! implSymbol = symbolUses |> Array.tryHead
@@ -275,8 +269,6 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
275269
let! _, checkFileResults =
276270
originDocument.GetFSharpParseAndCheckResultsAsync(userOpName)
277271
|> CancellableTask.start ct
278-
|> Async.AwaitTask
279-
|> liftAsync
280272

281273
let declarations =
282274
checkFileResults.GetDeclarationLocation(
@@ -530,8 +522,6 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
530522
let! _, checkResults =
531523
tmpShownDoc.GetFSharpParseAndCheckResultsAsync("NavigateToExternalDeclaration")
532524
|> CancellableTask.start ct
533-
|> Async.AwaitTask
534-
|> liftAsync
535525

536526
let! r =
537527
let rec areTypesEqual (ty1: FSharpType) (ty2: FSharpType) =

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

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

5048
let! symbolUse =
5149
checkFileResults.GetSymbolUseAtLocation(

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

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

3129
return
3230
CompilerEnvironment.GetConditionalDefinesForEditing parsingOptions,

0 commit comments

Comments
 (0)