diff --git a/paket.lock b/paket.lock index 438445732..418bd46db 100644 --- a/paket.lock +++ b/paket.lock @@ -97,7 +97,7 @@ NUGET System.Collections.Immutable (>= 5.0) System.Reflection.Metadata (>= 5.0) Ionide.KeepAChangelog.Tasks (0.1.8) - copy_local: true - Ionide.LanguageServerProtocol (0.4.9) + Ionide.LanguageServerProtocol (0.4.10) FSharp.Core (>= 6.0) Newtonsoft.Json (>= 13.0.1) StreamJsonRpc (>= 2.10.44) diff --git a/src/FsAutoComplete/CodeFixes.fs b/src/FsAutoComplete/CodeFixes.fs index 12a57afd5..b6cde1051 100644 --- a/src/FsAutoComplete/CodeFixes.fs +++ b/src/FsAutoComplete/CodeFixes.fs @@ -310,7 +310,12 @@ module Run = runDiagnostics (fun d -> d.Message.Contains checkMessage) handler let ifDiagnosticByType (diagnosticType: string) handler : CodeFix = - runDiagnostics (fun d -> d.Source.Contains diagnosticType) handler + runDiagnostics + (fun d -> + match d.Source with + | None -> false + | Some s -> s.Contains diagnosticType) + handler let ifDiagnosticByCode codes handler : CodeFix = runDiagnostics (fun d -> d.Code.IsSome && Set.contains d.Code.Value codes) handler diff --git a/src/FsAutoComplete/FsAutoComplete.Lsp.fs b/src/FsAutoComplete/FsAutoComplete.Lsp.fs index ed98958bf..cb888bc23 100644 --- a/src/FsAutoComplete/FsAutoComplete.Lsp.fs +++ b/src/FsAutoComplete/FsAutoComplete.Lsp.fs @@ -400,7 +400,7 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient) = { Range = fcsRangeToLsp n Code = Some "FSAC0001" Severity = Some DiagnosticSeverity.Hint - Source = "FSAC" + Source = Some "FSAC" Message = "Unused open statement" RelatedInformation = None Tags = Some [| DiagnosticTag.Unnecessary |] @@ -418,7 +418,7 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient) = { Range = fcsRangeToLsp n Code = Some "FSAC0003" Severity = Some DiagnosticSeverity.Hint - Source = "FSAC" + Source = Some "FSAC" Message = "This value is unused" RelatedInformation = Some [||] Tags = Some [| DiagnosticTag.Unnecessary |] @@ -441,7 +441,7 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient) = { Diagnostic.Range = fcsRangeToLsp range Code = Some "FSAC0002" Severity = Some DiagnosticSeverity.Hint - Source = "FSAC" + Source = Some "FSAC" Message = "This qualifier is redundant" RelatedInformation = Some [||] Tags = Some [| DiagnosticTag.Unnecessary |] @@ -478,7 +478,7 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient) = // { Range = range // Code = Some w.Code // Severity = Some DiagnosticSeverity.Information - // Source = "F# Linter" + // Source = Some "F# Linter" // Message = w.Warning.Details.Message // RelatedInformation = None // Tags = None @@ -524,7 +524,7 @@ type FSharpLspServer(state: State, lspClient: FSharpLspClient) = { Range = range Code = Option.ofObj m.Code Severity = Some severity - Source = $"F# Analyzers (%s{m.Type})" + Source = Some $"F# Analyzers (%s{m.Type})" Message = m.Message RelatedInformation = None Tags = None diff --git a/src/FsAutoComplete/LspHelpers.fs b/src/FsAutoComplete/LspHelpers.fs index c7cef269f..707de3fe8 100644 --- a/src/FsAutoComplete/LspHelpers.fs +++ b/src/FsAutoComplete/LspHelpers.fs @@ -101,7 +101,7 @@ module Conversions = { Line = error.EndLine - 1 Character = error.EndColumn } } Severity = fcsSeverityToDiagnostic error.Severity - Source = "F# Compiler" + Source = Some "F# Compiler" Message = error.Message Code = Some(string error.ErrorNumber) RelatedInformation = Some [||] diff --git a/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs b/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs index d5dfc0dc1..9553d3f58 100644 --- a/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/CompletionTests.fs @@ -428,11 +428,13 @@ let autoOpenTests state = // Message required for QuickFix to fire ("is not defined") Message = $"The value or constructor '{word}' is not defined." Code = Some "39" - Source = "F# Compiler" + Source = Some "F# Compiler" RelatedInformation = None Tags = None Data = None - CodeDescription = None } |] } } + CodeDescription = None } |] + Only = None + TriggerKind = None } } let (|ContainsOpenAction|_|) (codeActions: CodeAction []) = codeActions diff --git a/test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs b/test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs index d19a1e968..735d8be0e 100644 --- a/test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs @@ -116,7 +116,7 @@ let linterTests state = End = { Line = 0; Character = 11 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0042" - Source = "F# Linter" + Source = Some "F# Linter" Message = "Consider changing `test` to PascalCase." RelatedInformation = None Tags = None @@ -128,7 +128,7 @@ let linterTests state = End = { Line = 1; Character = 25 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`not (a = b)` might be able to be refactored into `a <> b`." RelatedInformation = None Tags = None @@ -140,7 +140,7 @@ let linterTests state = End = { Line = 2; Character = 26 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`not (a <> b)` might be able to be refactored into `a = b`." RelatedInformation = None Tags = None @@ -152,7 +152,7 @@ let linterTests state = End = { Line = 3; Character = 22 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`fun x -> x` might be able to be refactored into `id`." RelatedInformation = None Tags = None @@ -164,7 +164,7 @@ let linterTests state = End = { Line = 4; Character = 20 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`not true` might be able to be refactored into `false`." RelatedInformation = None Tags = None @@ -176,7 +176,7 @@ let linterTests state = End = { Line = 5; Character = 21 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`not false` might be able to be refactored into `true`." RelatedInformation = None Tags = None @@ -188,7 +188,7 @@ let linterTests state = End = { Line = 7; Character = 21 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`a <> true` might be able to be refactored into `not a`." RelatedInformation = None Tags = None @@ -200,7 +200,7 @@ let linterTests state = End = { Line = 8; Character = 20 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`x = null` might be able to be refactored into `isNull x`." RelatedInformation = None Tags = None @@ -212,7 +212,7 @@ let linterTests state = End = { Line = 9; Character = 37 } } Severity = Some DiagnosticSeverity.Information Code = Some "FL0065" - Source = "F# Linter" + Source = Some "F# Linter" Message = "`List.head (List.sort x)` might be able to be refactored into `List.min x`." RelatedInformation = None Tags = None @@ -343,7 +343,7 @@ let analyzerTests state = End = { Line = 3; Character = 31 } } Severity = Some DiagnosticSeverity.Warning Code = Some "OV001" - Source = "F# Analyzers (Option.Value analyzer)" + Source = Some "F# Analyzers (Option.Value analyzer)" Message = "Option.Value shouldn't be used" RelatedInformation = None Tags = None diff --git a/test/FsAutoComplete.Tests.Lsp/Helpers.fs b/test/FsAutoComplete.Tests.Lsp/Helpers.fs index 6451bdcf9..0ce6dfc90 100644 --- a/test/FsAutoComplete.Tests.Lsp/Helpers.fs +++ b/test/FsAutoComplete.Tests.Lsp/Helpers.fs @@ -559,10 +559,9 @@ let diagnosticsFromSource (desiredSource: String) = Observable.choose (fun (diags: Diagnostic[]) -> match diags |> Array.choose (fun d -> - if d.Source.StartsWith desiredSource then - Some d - else - None) + match d.Source with + | Some s -> if s.StartsWith desiredSource then Some d else None + | None -> None) with | [||] -> None | diags -> Some diags) diff --git a/test/FsAutoComplete.Tests.Lsp/UnsedDeclarationsTests.fs b/test/FsAutoComplete.Tests.Lsp/UnsedDeclarationsTests.fs index c6ce2c0e4..f0d5456b6 100644 --- a/test/FsAutoComplete.Tests.Lsp/UnsedDeclarationsTests.fs +++ b/test/FsAutoComplete.Tests.Lsp/UnsedDeclarationsTests.fs @@ -23,7 +23,7 @@ let private checkUsageAt expected = async { let source = sourceWithoutCursor |> Text.trimTripleQuotation - let! (doc, diags) = + let! (doc, diags) = let getDoc = match doc with | Untitled -> Server.createUntitledDocument @@ -36,7 +36,7 @@ let private checkUsageAt |> Array.filter (fun d -> d.Range |> Range.containsStrictly cursor) let isUnused (diag: Diagnostic) = - diag.Source = "FSAC" + diag.Source = Some "FSAC" && diag.Code = Some "FSAC0003" && @@ -46,9 +46,9 @@ let private checkUsageAt let diag = diagsAtCursor |> Array.filter isUnused match expected with - | Unused -> + | Unused -> Expect.hasLength diag 1 "There should be exactly one unused value diagnostic at cursor position" - | Used -> + | Used -> Expect.hasLength diag 0 "There should be no unused value diagnostic at cursor position" } @@ -59,12 +59,12 @@ let private checkUsage expected = async { let (cursor, source) = - sourceWithCursor + sourceWithCursor |> Text.trimTripleQuotation |> Cursor.assertExtractPosition do! checkUsageAt server doc source cursor expected } - + let private scriptTests state = let config = { @@ -224,7 +224,7 @@ let private projectTests state = """ Used - + testCaseAsync "unused private function variable" <| checkUsage server file """ @@ -250,7 +250,7 @@ let private projectTests state = let $0f _ = () """ Used - + // https://github.com/fsharp/FsAutoComplete/issues/832 testList "issue #832" [ // `$P`: used (or public -> not marked unused) diff --git a/test/FsAutoComplete.Tests.Lsp/Utils/Server.fs b/test/FsAutoComplete.Tests.Lsp/Utils/Server.fs index 5cb5733b6..4b61ffd94 100644 --- a/test/FsAutoComplete.Tests.Lsp/Utils/Server.fs +++ b/test/FsAutoComplete.Tests.Lsp/Utils/Server.fs @@ -377,7 +377,7 @@ module Document = let ps: CodeActionParams = { TextDocument = doc.TextDocumentIdentifier Range = range - Context = { Diagnostics = diagnostics } } + Context = { Diagnostics = diagnostics; Only = None; TriggerKind = None } } let! res = doc.Server.Server.TextDocumentCodeAction ps return res |> assertOk