diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a05b6f7..81d09b22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +* Modify CodeLens command to emit "editor.action.showReferences" so it works with vscode (at least) + - Fixed by @zachristmas in https://github.com/zachristmas/csharp-language-server +* Print error mesage to stderr in case of invalid args or a server crash. + - Fixed by @zachristmas in https://github.com/zachristmas/csharp-language-server * Fix completion item kind for an extension method - Reported by @sharpchen in https://github.com/razzmatazz/csharp-language-server/issues/237 - Fixed in https://github.com/razzmatazz/csharp-language-server/pull/238 diff --git a/src/CSharpLanguageServer/Handlers/CodeLens.fs b/src/CSharpLanguageServer/Handlers/CodeLens.fs index e9ea7ecf..8bd92a8f 100644 --- a/src/CSharpLanguageServer/Handlers/CodeLens.fs +++ b/src/CSharpLanguageServer/Handlers/CodeLens.fs @@ -1,6 +1,7 @@ namespace CSharpLanguageServer.Handlers open System +open System.IO open Microsoft.CodeAnalysis open Microsoft.CodeAnalysis.CSharp @@ -167,26 +168,27 @@ module CodeLens = | None -> return p |> LspResult.success | Some symbol -> - let! locations = context.FindReferences symbol false - // FIXME: refNum is wrong. There are lots of false positive even if we distinct locations by - // (l.SourceTree.FilePath, l.SourceSpan) - let refNum = - locations + let! locations' = context.FindReferences symbol false + + let locations = + locations' |> Seq.distinctBy (fun l -> (l.GetMappedLineSpan().Path, l.SourceSpan)) - |> Seq.length + |> Seq.map Location.fromRoslynLocation + |> Seq.choose id - let title = sprintf "%d Reference(s)" refNum + // FIXME: refNum is wrong. There are lots of false positive even if we distinct locations by + // (l.SourceTree.FilePath, l.SourceSpan) + let title = sprintf "%d Reference(s)" (Seq.length locations) - let arg: ReferenceParams = - { TextDocument = { Uri = lensData.DocumentUri } - Position = lensData.Position - WorkDoneToken = None - PartialResultToken = None - Context = { IncludeDeclaration = true } } let command = { Title = title - Command = "textDocument/references" - Arguments = Some [| arg |> serialize |] } + Command = "editor.action.showReferences" + Arguments = Some [| lensData.DocumentUri |> serialize + lensData.Position |> serialize + locations |> Seq.head |> serialize + |] } + + File.WriteAllText("/Users/bob/debug.txt", (serialize command |> string)) return { p with Command = Some command } |> LspResult.success }