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

Fix find references in codelense #2042

Merged
merged 1 commit into from
Sep 21, 2024
Merged
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
44 changes: 32 additions & 12 deletions src/Components/CodeLensHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,45 @@ open Fable.Import.VSCode.Vscode

module CodeLensHelpers =

// This data structure provided by FSAC, in CodeLensResolve:
// https://github.com/ionide/FsAutoComplete/blob/258fbc55053f585ea6ebd81a7dc10e4f3573aff6/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs#L1637

type LspUri = string

type LspPosition = {
line : uint32
character : uint32
}

type DotnetNewListResponseRange = {
start : Position
``end`` : Position
}

type LspLocation = {
uri : string
range : Range
}

type CustomIExports =
abstract registerCommand:
command: string * callback: (obj -> obj -> obj -> obj option) * ?thisArg: obj -> Disposable
command: string * callback: (LspUri -> LspPosition -> LspLocation seq -> obj option) * ?thisArg: obj -> Disposable

let showReferences (args: obj) (args2: obj) (args3: obj) =
let uri = vscode.Uri.parse !!args
let pos = vscode.Position.Create(!!args2?Line, !!args2?Character)
let showReferences (uri: LspUri) (args2: LspPosition) (args3: LspLocation seq) =
let uri = vscode.Uri.parse !!uri
let pos = vscode.Position.Create(float args2.line, float args2.character)

let locs =
!!args3
args3
|> Seq.map (fun f ->
let uri = vscode.Uri.parse !!f?Uri

let uri = vscode.Uri.parse f.uri
let range =
vscode.Range.Create(
!!f?Range?Start?Line,
!!f?Range?Start?Character,
!!f?Range?End?Line,
!!f?Range?End?Character
float f.range.start.line,
float f.range.start.character,
float f.range.``end``.line,
float f.range.``end``.character
)

vscode.Location.Create(uri, !^range))
Expand All @@ -34,5 +54,5 @@ module CodeLensHelpers =

let activate (context: ExtensionContext) =
(unbox<CustomIExports> commands)
.registerCommand ("fsharp.showReferences", unbox<(obj -> obj -> obj -> obj option)> (showReferences))
.registerCommand ("fsharp.showReferences", unbox<(LspUri -> LspPosition -> LspLocation seq -> obj option)> (showReferences))
|> context.Subscribe
Loading