Skip to content

Commit

Permalink
add config toggles for the specific kinds of codelenses we have in a …
Browse files Browse the repository at this point in the history
…configurable way
  • Loading branch information
baronfel committed Apr 26, 2022
1 parent 09ae8ab commit 13f1141
Show file tree
Hide file tree
Showing 3 changed files with 817 additions and 733 deletions.
79 changes: 34 additions & 45 deletions src/FsAutoComplete/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,9 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
let getAbstractClassStubReplacements () = abstractClassStubReplacements ()

codeFixes <-
[|
Run.ifEnabled
(fun _ -> config.UnusedOpensAnalyzer)
[|
Run.ifEnabled
(fun _ -> config.UnusedOpensAnalyzer)
(RemoveUnusedOpens.fix getFileLines)
Run.ifEnabled
(fun _ -> config.ResolveNamespaces)
Expand Down Expand Up @@ -898,7 +898,7 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
AddMissingInstanceMember.fix
AddExplicitTypeToParameter.fix tryGetParseResultsForFile
ConvertPositionalDUToNamed.fix tryGetParseResultsForFile getRangeText
UseTripleQuotedInterpolation.fix tryGetParseResultsForFile getRangeText
UseTripleQuotedInterpolation.fix tryGetParseResultsForFile getRangeText
RenameParamToMatchSignature.fix tryGetParseResultsForFile
|]

Expand Down Expand Up @@ -1775,7 +1775,7 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
}

override __.TextDocumentCodeLens(p) =
async {
asyncResult {
logger.info (
Log.setMessage "TextDocumentCodeLens Request: {parms}"
>> Log.addContextDestructured "parms" p
Expand All @@ -1785,38 +1785,23 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
p.TextDocument.GetFilePath()
|> Utils.normalizePath

let! res = commands.Declarations fn None (commands.TryGetFileVersion fn)
let! decls =
commands.Declarations fn None (commands.TryGetFileVersion fn)
|> AsyncResult.ofCoreResponse
|> AsyncResult.map (Array.map fst)

let res =
let res = [|
if config.LineLens.Enabled <> "replaceCodeLens" then
match res with
| CoreResponse.InfoRes msg
| CoreResponse.ErrorRes msg -> LspResult.internalError msg
| CoreResponse.Res (decls) ->
let res =
decls
|> Array.map (
fst
>> getCodeLensInformation p.TextDocument.Uri "signature"
)
|> Array.collect id

let res2 =
if config.EnableReferenceCodeLens then
decls
|> Array.map (
fst
>> getCodeLensInformation p.TextDocument.Uri "reference"
)
|> Array.collect id
else
[||]
if config.CodeLenses.Signature.Enabled
then
yield! decls |> Array.collect (getCodeLensInformation p.TextDocument.Uri "signature")

[| yield! res2; yield! res |] |> Some |> success
else
[||] |> Some |> success
// we have two options here because we're deprecating the EnableReferenceCodeLens one (namespacing, etc)
if config.EnableReferenceCodeLens || config.CodeLenses.References.Enabled then
yield! decls |> Array.collect (getCodeLensInformation p.TextDocument.Uri "reference")
|]

return res
return Some res
}

override __.CodeLensResolve(p) =
Expand Down Expand Up @@ -1864,7 +1849,10 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
let! r = Async.Catch(f arg pos tyRes lineStr data.[1] file)

match r with
| Choice1Of2 r -> return r
| Choice1Of2 (r: LspResult<CodeLens option>) ->
match r with
| Ok (Some r) -> return Ok r
| _ -> return Ok Unchecked.defaultof<_>
| Choice2Of2 e ->
logger.error (
Log.setMessage "CodeLensResolve - Child operation failed for {file}"
Expand Down Expand Up @@ -1901,7 +1889,7 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
>> Log.addContextDestructured "error" msg
)

return { p with Command = None } |> success
return { p with Command = None } |> Some |> success
| CoreResponse.Res (typ, parms, _) ->
let formatted = SigantureData.formatSignature typ parms

Expand All @@ -1910,22 +1898,23 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
Command = ""
Arguments = None }

return { p with Command = Some cmd } |> success
return { p with Command = Some cmd } |> Some |> success
else
let! res = commands.SymbolUseProject tyRes pos lineStr
let! res =
commands.SymbolUseProject tyRes pos lineStr
|> AsyncResult.ofCoreResponse

let res =
match res with
| CoreResponse.InfoRes msg
| CoreResponse.ErrorRes msg ->
| Core.Result.Error msg ->
logger.error (
Log.setMessage "CodeLensResolve - error getting symbol use for {file}"
>> Log.addContextDestructured "file" file
>> Log.addContextDestructured "error" msg
)

{ p with Command = None } |> success
| CoreResponse.Res (LocationResponse.Use (sym, uses)) ->
success None
| Ok (LocationResponse.Use (sym, uses)) ->
let formatted =
if uses.Length = 1 then
"1 Reference"
Expand All @@ -1946,10 +1935,10 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
Command = "fsharp.showReferences"
Arguments = Some args }

{ p with Command = Some cmd } |> success
| CoreResponse.Res (LocationResponse.UseRange (uses)) ->
{ p with Command = Some cmd } |> Some |> success
| Ok (LocationResponse.UseRange (uses)) ->
let formatted =
if uses.Length - 1 = 1 then
if uses.Length = 2 then
"1 Reference"
elif uses.Length = 0 then
"0 References"
Expand All @@ -1969,7 +1958,7 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS
Command = "fsharp.showReferences"
Arguments = Some args }

{ p with Command = Some cmd } |> success
{ p with Command = Some cmd } |> Some |> success

return res
})
Expand Down
Loading

0 comments on commit 13f1141

Please sign in to comment.