Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update LSP library and adjust to API differences in code actions context #1018

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/FsAutoComplete/CodeFixes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/FsAutoComplete/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 |]
Expand All @@ -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 |]
Expand All @@ -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 |]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete/LspHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [||]
Expand Down
6 changes: 4 additions & 2 deletions test/FsAutoComplete.Tests.Lsp/CompletionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions test/FsAutoComplete.Tests.Lsp/ExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions test/FsAutoComplete.Tests.Lsp/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions test/FsAutoComplete.Tests.Lsp/UnsedDeclarationsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
&&
Expand All @@ -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"
}

Expand All @@ -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 = {
Expand Down Expand Up @@ -224,7 +224,7 @@ let private projectTests state =
"""
Used


testCaseAsync "unused private function variable" <|
checkUsage server file
"""
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/FsAutoComplete.Tests.Lsp/Utils/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down