fix: go to definition in modified file
This commit is contained in:
parent
ccf492b61d
commit
4545e183d8
2 changed files with 25 additions and 0 deletions
|
|
@ -227,6 +227,18 @@ def referringTo (self : References) (ident : RefIdent) (srcSearchPath : SearchPa
|
|||
result := result.push ⟨uri, range⟩
|
||||
result
|
||||
|
||||
def definitionOf (self : References) (ident : RefIdent) (srcSearchPath : SearchPath)
|
||||
: IO (Option Location) := do
|
||||
for (module, refs) in self.allRefs.toList do
|
||||
if let some info := refs.find? ident then
|
||||
if let some definition := info.definition then
|
||||
if let some path ← srcSearchPath.findModuleWithExt "lean" module then
|
||||
-- Resolve symlinks (such as `src` in the build dir) so that files are
|
||||
-- opened in the right folder
|
||||
let uri := DocumentUri.ofPath <| ← IO.FS.realPath path
|
||||
return some ⟨uri, definition⟩
|
||||
return none
|
||||
|
||||
def definitionsMatching (self : References) (srcSearchPath : SearchPath) (filter : Name → Option α)
|
||||
(maxAmount? : Option Nat := none) : IO $ Array (α × Location) := do
|
||||
let mut result := #[]
|
||||
|
|
|
|||
|
|
@ -368,6 +368,15 @@ end ServerM
|
|||
|
||||
section RequestHandling
|
||||
|
||||
def findDefinition (p : TextDocumentPositionParams) : ServerM <| Option Location := do
|
||||
if let some path := p.textDocument.uri.toPath? then
|
||||
let srcSearchPath := (← read).srcSearchPath
|
||||
if let some module ← searchModuleNameOfFileName path srcSearchPath then
|
||||
let references ← (← read).references.get
|
||||
if let some ident := references.findAt? module p.position then
|
||||
return ← references.definitionOf ident srcSearchPath
|
||||
return none
|
||||
|
||||
def handleReference (p : ReferenceParams) : ServerM (Array Location) := do
|
||||
if let some path := p.textDocument.uri.toPath? then
|
||||
let srcSearchPath := (← read).srcSearchPath
|
||||
|
|
@ -527,6 +536,10 @@ section MessageHandling
|
|||
code := ErrorCode.internalError
|
||||
message := s!"Failed to process request {id}: {e}"
|
||||
}
|
||||
if method == "textDocument/definition" || method == "textDocument/declaration" then
|
||||
let params ← parseParams TextDocumentPositionParams params
|
||||
if let some definition ← findDefinition params then
|
||||
(← read).hOut.writeLspResponse ⟨id, #[definition]⟩
|
||||
match method with
|
||||
| "textDocument/references" => handle ReferenceParams (Array Location) handleReference
|
||||
| "workspace/symbol" => handle WorkspaceSymbolParams (Array SymbolInformation) handleWorkspaceSymbol
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue