Skip to content

Commit 13b5909

Browse files
committed
Run fantomas
1 parent 79533b8 commit 13b5909

File tree

4 files changed

+176
-166
lines changed

4 files changed

+176
-166
lines changed

src/FSharp.Compiler.LanguageServer/FSharpLanguageServer.fs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,8 @@ type FSharpLanguageServer
8989
FSharpLanguageServer.Create(LspLogger System.Diagnostics.Trace.TraceInformation, initialWorkspace, addExtraHandlers, config)
9090

9191
static member Create
92-
(
93-
logger: ILspLogger,
94-
initialWorkspace,
95-
?addExtraHandlers: Action<IServiceCollection>,
96-
?config: FSharpLanguageServerConfig
97-
) =
92+
(logger: ILspLogger, initialWorkspace, ?addExtraHandlers: Action<IServiceCollection>, ?config: FSharpLanguageServerConfig)
93+
=
9894

9995
let struct (clientStream, serverStream) = FullDuplexStream.CreatePair()
10096

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

Lines changed: 140 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -152,164 +152,156 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
152152
member _.AddLexicalClassifications(_: SourceText, _: TextSpan, _: List<ClassifiedSpan>, _: CancellationToken) = ()
153153

154154
member _.AddSyntacticClassificationsAsync
155-
(
156-
document: Document,
157-
textSpan: TextSpan,
158-
result: List<ClassifiedSpan>,
159-
cancellationToken: CancellationToken
160-
) =
155+
(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken)
156+
=
161157

162158
if not (document |> shouldProduceClassification) then
163159
System.Threading.Tasks.Task.CompletedTask
164-
else
165-
166-
cancellableTask {
167-
use _logBlock = Logger.LogBlock(LogEditorFunctionId.Classification_Syntactic)
168-
169-
let! cancellationToken = CancellableTask.getCancellationToken ()
170-
171-
let defines, langVersion, strictIndentation = document.GetFsharpParsingOptions()
172-
173-
let! sourceText = document.GetTextAsync(cancellationToken)
174-
175-
// For closed documents, only get classification for the text within the span.
176-
// This may be inaccurate for multi-line tokens such as string literals, but this is ok for now
177-
// as it's better than having to tokenize a big part of a file which in return will allocate a lot and hurt find all references performance.
178-
let isOpenDocument = document.Project.Solution.Workspace.IsDocumentOpen document.Id
179-
180-
let eventProps: (string * obj) array =
181-
[|
182-
"context.document.project.id", document.Project.Id.Id.ToString()
183-
"context.document.id", document.Id.Id.ToString()
184-
"isOpenDocument", isOpenDocument
185-
"textSpanLength", textSpan.Length
186-
|]
187-
188-
use _eventDuration =
189-
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSyntacticClassifications, eventProps)
190-
191-
if not isOpenDocument then
192-
let classifiedSpans =
193-
getLexicalClassifications (document.FilePath, defines, sourceText, textSpan, cancellationToken)
194-
195-
result.AddRange(classifiedSpans)
196-
else
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
207-
)
208-
}
209-
|> CancellableTask.startAsTask cancellationToken
160+
else
161+
162+
cancellableTask {
163+
use _logBlock = Logger.LogBlock(LogEditorFunctionId.Classification_Syntactic)
164+
165+
let! cancellationToken = CancellableTask.getCancellationToken ()
166+
167+
let defines, langVersion, strictIndentation = document.GetFsharpParsingOptions()
168+
169+
let! sourceText = document.GetTextAsync(cancellationToken)
170+
171+
// For closed documents, only get classification for the text within the span.
172+
// This may be inaccurate for multi-line tokens such as string literals, but this is ok for now
173+
// as it's better than having to tokenize a big part of a file which in return will allocate a lot and hurt find all references performance.
174+
let isOpenDocument = document.Project.Solution.Workspace.IsDocumentOpen document.Id
175+
176+
let eventProps: (string * obj) array =
177+
[|
178+
"context.document.project.id", document.Project.Id.Id.ToString()
179+
"context.document.id", document.Id.Id.ToString()
180+
"isOpenDocument", isOpenDocument
181+
"textSpanLength", textSpan.Length
182+
|]
183+
184+
use _eventDuration =
185+
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSyntacticClassifications, eventProps)
186+
187+
if not isOpenDocument then
188+
let classifiedSpans =
189+
getLexicalClassifications (document.FilePath, defines, sourceText, textSpan, cancellationToken)
190+
191+
result.AddRange(classifiedSpans)
192+
else
193+
Tokenizer.classifySpans (
194+
document.Id,
195+
sourceText,
196+
textSpan,
197+
Some(document.FilePath),
198+
defines,
199+
Some langVersion,
200+
strictIndentation,
201+
result,
202+
cancellationToken
203+
)
204+
}
205+
|> CancellableTask.startAsTask cancellationToken
210206

211207
member _.AddSemanticClassificationsAsync
212-
(
213-
document: Document,
214-
textSpan: TextSpan,
215-
result: List<ClassifiedSpan>,
216-
cancellationToken: CancellationToken
217-
) =
208+
(document: Document, textSpan: TextSpan, result: List<ClassifiedSpan>, cancellationToken: CancellationToken)
209+
=
218210

219211
if not (document |> shouldProduceClassification) then
220212
System.Threading.Tasks.Task.CompletedTask
221-
else
222-
223-
cancellableTask {
224-
use _logBlock = Logger.LogBlock(LogEditorFunctionId.Classification_Semantic)
225-
226-
let! sourceText = document.GetTextAsync(cancellationToken)
227-
228-
// If we are trying to get semantic classification for a document that is not open, get the results from the background and cache it.
229-
// We do this for find all references when it is populating results.
230-
// We cache it temporarily so we do not have to continuously call into the checker and perform a background operation.
231-
let isOpenDocument = document.Project.Solution.Workspace.IsDocumentOpen document.Id
232-
233-
if not isOpenDocument then
234-
match! unopenedDocumentsSemanticClassificationCache.TryGetValueAsync document with
235-
| ValueSome classificationDataLookup ->
236-
let eventProps: (string * obj) array =
237-
[|
238-
"context.document.project.id", document.Project.Id.Id.ToString()
239-
"context.document.id", document.Id.Id.ToString()
240-
"isOpenDocument", isOpenDocument
241-
"textSpanLength", textSpan.Length
242-
"cacheHit", true
243-
|]
244-
245-
use _eventDuration =
246-
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
247-
248-
addSemanticClassificationByLookup sourceText textSpan classificationDataLookup result
249-
| ValueNone ->
250-
let eventProps: (string * obj) array =
251-
[|
252-
"context.document.project.id", document.Project.Id.Id.ToString()
253-
"context.document.id", document.Id.Id.ToString()
254-
"isOpenDocument", isOpenDocument
255-
"textSpanLength", textSpan.Length
256-
"cacheHit", false
257-
|]
258-
259-
use _eventDuration =
260-
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
261-
262-
let! classificationData = document.GetFSharpSemanticClassificationAsync(nameof (FSharpClassificationService))
263-
264-
let classificationDataLookup = toSemanticClassificationLookup classificationData
265-
do! unopenedDocumentsSemanticClassificationCache.SetAsync(document, classificationDataLookup)
266-
addSemanticClassificationByLookup sourceText textSpan classificationDataLookup result
267-
else
268-
269-
match! openedDocumentsSemanticClassificationCache.TryGetValueAsync document with
270-
| ValueSome classificationDataLookup ->
271-
let eventProps: (string * obj) array =
272-
[|
273-
"context.document.project.id", document.Project.Id.Id.ToString()
274-
"context.document.id", document.Id.Id.ToString()
275-
"isOpenDocument", isOpenDocument
276-
"textSpanLength", textSpan.Length
277-
"cacheHit", true
278-
|]
279-
280-
use _eventDuration =
281-
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
282-
283-
addSemanticClassificationByLookup sourceText textSpan classificationDataLookup result
284-
| ValueNone ->
285-
286-
let eventProps: (string * obj) array =
287-
[|
288-
"context.document.project.id", document.Project.Id.Id.ToString()
289-
"context.document.id", document.Id.Id.ToString()
290-
"isOpenDocument", isOpenDocument
291-
"textSpanLength", textSpan.Length
292-
"cacheHit", false
293-
|]
294-
295-
use _eventDuration =
296-
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
297-
298-
let! _, checkResults = document.GetFSharpParseAndCheckResultsAsync(nameof (IFSharpClassificationService))
299-
300-
let targetRange =
301-
RoslynHelpers.TextSpanToFSharpRange(document.FilePath, textSpan, sourceText)
302-
303-
let classificationData = checkResults.GetSemanticClassification(Some targetRange)
304-
305-
if classificationData.Length > 0 then
306-
let classificationDataLookup = itemToSemanticClassificationLookup classificationData
213+
else
214+
215+
cancellableTask {
216+
use _logBlock = Logger.LogBlock(LogEditorFunctionId.Classification_Semantic)
217+
218+
let! sourceText = document.GetTextAsync(cancellationToken)
219+
220+
// If we are trying to get semantic classification for a document that is not open, get the results from the background and cache it.
221+
// We do this for find all references when it is populating results.
222+
// We cache it temporarily so we do not have to continuously call into the checker and perform a background operation.
223+
let isOpenDocument = document.Project.Solution.Workspace.IsDocumentOpen document.Id
224+
225+
if not isOpenDocument then
226+
match! unopenedDocumentsSemanticClassificationCache.TryGetValueAsync document with
227+
| ValueSome classificationDataLookup ->
228+
let eventProps: (string * obj) array =
229+
[|
230+
"context.document.project.id", document.Project.Id.Id.ToString()
231+
"context.document.id", document.Id.Id.ToString()
232+
"isOpenDocument", isOpenDocument
233+
"textSpanLength", textSpan.Length
234+
"cacheHit", true
235+
|]
236+
237+
use _eventDuration =
238+
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
239+
240+
addSemanticClassificationByLookup sourceText textSpan classificationDataLookup result
241+
| ValueNone ->
242+
let eventProps: (string * obj) array =
243+
[|
244+
"context.document.project.id", document.Project.Id.Id.ToString()
245+
"context.document.id", document.Id.Id.ToString()
246+
"isOpenDocument", isOpenDocument
247+
"textSpanLength", textSpan.Length
248+
"cacheHit", false
249+
|]
250+
251+
use _eventDuration =
252+
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
253+
254+
let! classificationData = document.GetFSharpSemanticClassificationAsync(nameof (FSharpClassificationService))
255+
256+
let classificationDataLookup = toSemanticClassificationLookup classificationData
307257
do! unopenedDocumentsSemanticClassificationCache.SetAsync(document, classificationDataLookup)
258+
addSemanticClassificationByLookup sourceText textSpan classificationDataLookup result
259+
else
308260

309-
addSemanticClassification sourceText textSpan classificationData result
310-
}
311-
|> CancellableTask.ifCanceledReturn ()
312-
|> CancellableTask.startAsTask cancellationToken
261+
match! openedDocumentsSemanticClassificationCache.TryGetValueAsync document with
262+
| ValueSome classificationDataLookup ->
263+
let eventProps: (string * obj) array =
264+
[|
265+
"context.document.project.id", document.Project.Id.Id.ToString()
266+
"context.document.id", document.Id.Id.ToString()
267+
"isOpenDocument", isOpenDocument
268+
"textSpanLength", textSpan.Length
269+
"cacheHit", true
270+
|]
271+
272+
use _eventDuration =
273+
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
274+
275+
addSemanticClassificationByLookup sourceText textSpan classificationDataLookup result
276+
| ValueNone ->
277+
278+
let eventProps: (string * obj) array =
279+
[|
280+
"context.document.project.id", document.Project.Id.Id.ToString()
281+
"context.document.id", document.Id.Id.ToString()
282+
"isOpenDocument", isOpenDocument
283+
"textSpanLength", textSpan.Length
284+
"cacheHit", false
285+
|]
286+
287+
use _eventDuration =
288+
TelemetryReporter.ReportSingleEventWithDuration(TelemetryEvents.AddSemanticClassifications, eventProps)
289+
290+
let! _, checkResults = document.GetFSharpParseAndCheckResultsAsync(nameof (IFSharpClassificationService))
291+
292+
let targetRange =
293+
RoslynHelpers.TextSpanToFSharpRange(document.FilePath, textSpan, sourceText)
294+
295+
let classificationData = checkResults.GetSemanticClassification(Some targetRange)
296+
297+
if classificationData.Length > 0 then
298+
let classificationDataLookup = itemToSemanticClassificationLookup classificationData
299+
do! unopenedDocumentsSemanticClassificationCache.SetAsync(document, classificationDataLookup)
300+
301+
addSemanticClassification sourceText textSpan classificationData result
302+
}
303+
|> CancellableTask.ifCanceledReturn ()
304+
|> CancellableTask.startAsTask cancellationToken
313305

314306
// Do not perform classification if we don't have project options (#defines matter)
315307
member _.AdjustStaleClassification(_: SourceText, classifiedSpan: ClassifiedSpan) : ClassifiedSpan = classifiedSpan

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,20 @@ type internal FSharpDocumentDiagnosticAnalyzer [<ImportingConstructor>] () =
151151
interface IFSharpDocumentDiagnosticAnalyzer with
152152

153153
member _.AnalyzeSyntaxAsync(document: Document, cancellationToken: CancellationToken) : Task<ImmutableArray<Diagnostic>> =
154-
if document.Project.IsFSharpMetadata || (not (document |> shouldProduceDiagnostics)) then
154+
if
155+
document.Project.IsFSharpMetadata
156+
|| (not (document |> shouldProduceDiagnostics))
157+
then
155158
Task.FromResult ImmutableArray.Empty
156159
else
157160
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(document, DiagnosticsType.Syntax)
158161
|> CancellableTask.start cancellationToken
159162

160163
member _.AnalyzeSemanticsAsync(document: Document, cancellationToken: CancellationToken) : Task<ImmutableArray<Diagnostic>> =
161-
if document.Project.IsFSharpMiscellaneousOrMetadata && not document.IsFSharpScript || (not (document |> shouldProduceDiagnostics)) then
164+
if
165+
document.Project.IsFSharpMiscellaneousOrMetadata && not document.IsFSharpScript
166+
|| (not (document |> shouldProduceDiagnostics))
167+
then
162168
Task.FromResult ImmutableArray.Empty
163169
else
164170
FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(document, DiagnosticsType.Semantic)

0 commit comments

Comments
 (0)