refactor: address review comments

This commit is contained in:
Joscha 2022-01-31 20:04:24 +01:00 committed by Sebastian Ullrich
parent bfc185e98e
commit d2dcff1f9a
3 changed files with 8 additions and 4 deletions

View file

@ -99,6 +99,8 @@ section Elab
if lastSnap.isAtEnd then
publishDiagnostics m lastSnap.diagnostics.toArray ctx.hOut
publishProgressDone m ctx.hOut
-- This will overwrite existing ilean info for the file, in case something
-- went wrong during the incremental updates.
publishIleanInfoFinal m ctx.hOut <| s.snaps.insertAt 0 s.headerSnap
return none
publishProgressAtPos m lastSnap.endPos ctx.hOut
@ -134,6 +136,8 @@ section Elab
publishIleanInfoFinal m ctx.hOut #[headerSnap]
AsyncList.nil
else
-- This will overwrite existing ilean info for the file since this has a
-- higher version number.
publishIleanInfoUpdate m ctx.hOut <| snaps.insertAt 0 headerSnap
AsyncList.unfoldAsync (nextCmdSnap ctx m cancelTk) { headerSnap, snaps }
end Elab

View file

@ -227,7 +227,7 @@ def referringTo (self : References) (ident : RefIdent) (srcSearchPath : SearchPa
result := result.push ⟨uri, range⟩
result
def definitionOf (self : References) (ident : RefIdent) (srcSearchPath : SearchPath)
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

View file

@ -368,13 +368,13 @@ end ServerM
section RequestHandling
def findDefinition (p : TextDocumentPositionParams) : ServerM <| Option Location := do
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 ← references.definitionOf? ident srcSearchPath
return none
def handleReference (p : ReferenceParams) : ServerM (Array Location) := do
@ -543,7 +543,7 @@ section MessageHandling
-- go-to-type-definition.
if method == "textDocument/definition" || method == "textDocument/declaration" then
let params ← parseParams TextDocumentPositionParams params
if let some definition ← findDefinition params then
if let some definition ← findDefinition? params then
(← read).hOut.writeLspResponse ⟨id, #[definition]⟩
return
match method with