Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 554a9c8

Browse files
authored
add workspace and diagnostics to lsp (dotnet#7006)
1 parent 30b4617 commit 554a9c8

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

Diagnostics/DocumentDiagnosticAnalyzer.fs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ type internal FSharpDocumentDiagnosticAnalyzer [<ImportingConstructor>] () =
3333

3434
let getProjectInfoManager(document: Document) =
3535
document.Project.Solution.Workspace.Services.GetService<FSharpCheckerWorkspaceService>().FSharpProjectOptionsManager
36-
36+
37+
let getSettings(document: Document) =
38+
document.Project.Solution.Workspace.Services.GetService<EditorOptions>()
39+
3740
static let errorInfoEqualityComparer =
3841
{ new IEqualityComparer<FSharpErrorInfo> with
3942
member __.Equals (x, y) =
@@ -110,6 +113,10 @@ type internal FSharpDocumentDiagnosticAnalyzer [<ImportingConstructor>] () =
110113
interface IFSharpDocumentDiagnosticAnalyzer with
111114

112115
member this.AnalyzeSyntaxAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
116+
// if using LSP, just bail early
117+
let settings = getSettings document
118+
if settings.Advanced.UsePreviewDiagnostics then Task.FromResult(ImmutableArray<Diagnostic>.Empty)
119+
else
113120
let projectInfoManager = getProjectInfoManager document
114121
asyncMaybe {
115122
let! parsingOptions, projectOptions = projectInfoManager.TryGetOptionsForEditingDocumentOrProject(document, cancellationToken)
@@ -123,6 +130,10 @@ type internal FSharpDocumentDiagnosticAnalyzer [<ImportingConstructor>] () =
123130
|> RoslynHelpers.StartAsyncAsTask cancellationToken
124131

125132
member this.AnalyzeSemanticsAsync(document: Document, cancellationToken: CancellationToken): Task<ImmutableArray<Diagnostic>> =
133+
// if using LSP, just bail early
134+
let settings = getSettings document
135+
if settings.Advanced.UsePreviewDiagnostics then Task.FromResult(ImmutableArray<Diagnostic>.Empty)
136+
else
126137
let projectInfoManager = getProjectInfoManager document
127138
asyncMaybe {
128139
let! parsingOptions, _, projectOptions = projectInfoManager.TryGetOptionsForDocumentOrProject(document, cancellationToken)

LanguageService/FSharpLanguageClient.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type FSharpContentDefinition() =
3434
type internal FSharpLanguageClient
3535
[<ImportingConstructor>]
3636
(
37-
lspService: LspService
37+
lspService: LspService,
38+
settings: EditorOptions
3839
) =
3940
inherit LanguageClient()
4041
override __.Name = "F# Language Service"
@@ -63,4 +64,7 @@ type internal FSharpLanguageClient
6364
member __.CustomMessageTarget = null
6465
member __.MiddleLayer = null
6566
member __.AttachForCustomMessageAsync(rpc: JsonRpc) =
66-
lspService.SetJsonRpc(rpc) |> Async.StartAsTask :> Task
67+
async {
68+
do! lspService.SetJsonRpc(rpc)
69+
do! lspService.SetOptions(settings.Advanced.AsLspOptions())
70+
} |> Async.StartAsTask :> Task

Options/EditorOptions.fs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ type CodeLensOptions =
9393
type AdvancedOptions =
9494
{ IsBlockStructureEnabled: bool
9595
IsOutliningEnabled: bool
96-
UsePreviewTextHover: bool }
96+
UsePreviewTextHover: bool
97+
UsePreviewDiagnostics: bool }
9798
static member Default =
9899
{ IsBlockStructureEnabled = true
99100
IsOutliningEnabled = true
100-
UsePreviewTextHover = false }
101+
UsePreviewTextHover = false
102+
UsePreviewDiagnostics = false }
103+
member this.AsLspOptions(): Options =
104+
{ usePreviewTextHover = this.UsePreviewTextHover
105+
usePreviewDiagnostics = this.UsePreviewDiagnostics }
101106

102107
[<CLIMutable>]
103108
type FormattingOptions =
@@ -203,8 +208,7 @@ module internal OptionsUI =
203208
async {
204209
let lspService = this.GetService<LspService>()
205210
let settings = this.GetService<EditorOptions>()
206-
let options =
207-
{ Options.usePreviewTextHover = settings.Advanced.UsePreviewTextHover }
211+
let options = settings.Advanced.AsLspOptions()
208212
do! lspService.SetOptions options
209213
} |> Async.Start
210214

0 commit comments

Comments
 (0)