fix: documentHighlight on partial input

Fixes #455
This commit is contained in:
Sebastian Ullrich 2021-05-11 17:03:18 +02:00
parent d35f46d4ba
commit 1e6dadfa52
3 changed files with 22 additions and 9 deletions

View file

@ -476,7 +476,7 @@ section RequestHandling
def hasRange (stx : Syntax) : Bool :=
stx.getPos?.isSome && stx.getTailPos?.isSome
def rangeOfSyntax (text : FileMap) (stx : Syntax) : Range :=
def rangeOfSyntax! (text : FileMap) (stx : Syntax) : Range :=
⟨text.utf8PosToLspPos <| stx.getPos?.get!,
text.utf8PosToLspPos <| stx.getTailPos?.get!⟩
@ -488,10 +488,10 @@ section RequestHandling
let rec highlightReturn? (doRange? : Option Range) : Syntax → Option DocumentHighlight
| stx@`(doElem|return%$i $e) =>
if stx.getPos?.get! <= pos && pos < stx.getTailPos?.get! then
some { range := doRange?.getD (rangeOfSyntax text i), kind? := DocumentHighlightKind.text }
some { range := doRange?.getD (rangeOfSyntax! text i), kind? := DocumentHighlightKind.text }
else
highlightReturn? doRange? e
| `(do%$i $elems) => highlightReturn? (rangeOfSyntax text i) elems
| `(do%$i $elems) => highlightReturn? (rangeOfSyntax! text i) elems
| stx => stx.getArgs.findSome? (highlightReturn? doRange?)
withWaitFindSnap doc (fun s => s.endPos > pos)
@ -536,8 +536,8 @@ section RequestHandling
(DocumentSymbol.mk {
name := name
kind := SymbolKind.method
range := rangeOfSyntax text stx
selectionRange := rangeOfSyntax text selection
range := rangeOfSyntax! text stx
selectionRange := rangeOfSyntax! text selection
} :: syms, stxs')
else
(syms, stxs')
@ -550,11 +550,13 @@ section RequestHandling
let endStx := match stxs' with
| endStx::_ => endStx
| [] => (stx::stxs').getLast!
-- we can assume that commands always have at least one position (see `parseCommand`)
let range := rangeOfSyntax! text (mkNullNode #[stx, endStx])
(DocumentSymbol.mk {
name := name
kind := kind
range := ⟨(rangeOfSyntax text stx).start, (rangeOfSyntax text endStx).«end»⟩
selectionRange := rangeOfSyntax text selection
name
kind
range
selectionRange := if hasRange selection then rangeOfSyntax! text selection else range
children? := syms.toArray
} :: syms', stxs'')

View file

@ -0,0 +1,2 @@
namespace
--^ textDocument/documentSymbol

View file

@ -0,0 +1,9 @@
{"textDocument": {"uri": "file://partialNamespace.lean"},
"position": {"line": 0, "character": 2}}
[{"selectionRange":
{"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 9}},
"range":
{"start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 9}},
"name": "[anonymous]",
"kind": 3,
"children": []}]