@@ -17,7 +17,7 @@ partial defmethod Highlighted.Token.Kind.priority : Highlighted.Token.Kind → N
17
17
| .const .. => 5
18
18
| .option .. => 4
19
19
| .sort => 4
20
- | .keyword _ _ => 3
20
+ | .keyword _ _ _ => 3
21
21
| .docComment => 1
22
22
| .unknown => 0
23
23
@@ -417,12 +417,12 @@ partial def renderTagged [Monad m] [MonadLiftT IO m] [MonadMCtx m] [MonadEnv m]
417
417
let mut toks : Array Highlighted := #[]
418
418
let mut current := ""
419
419
while !todo.isEmpty do
420
- for kw in ["let" , "fun" , ":=" , "=>" , " do" , "match" , "with" , "if" , "then" , "else" , "break" , "continue" , "for" , "in" , "mut" ] do
420
+ for kw in ["let" , "fun" , "do" , "match" , "with" , "if" , "then" , "else" , "break" , "continue" , "for" , "in" , "mut" ] do
421
421
if kw.isPrefixOf todo && tokenEnder (todo.drop kw.length) then
422
422
if !current.isEmpty then
423
423
toks := toks.push <| .text current
424
424
current := ""
425
- toks := toks.push <| .token ⟨.keyword none none, kw⟩
425
+ toks := toks.push <| .token ⟨.keyword none none none , kw⟩
426
426
todo := todo.drop kw.length
427
427
break
428
428
let c := todo.get 0
@@ -521,7 +521,7 @@ def findTactics (ids : HashMap Lsp.RefIdent Lsp.RefIdent) (stx : Syntax) : Highl
521
521
}
522
522
return
523
523
524
- partial def highlight' (ids : HashMap Lsp.RefIdent Lsp.RefIdent) (stx : Syntax) (lookingAt : Option Name := none) : HighlightM Unit := do
524
+ partial def highlight' (ids : HashMap Lsp.RefIdent Lsp.RefIdent) (stx : Syntax) (lookingAt : Option ( Name × String.Pos) := none) : HighlightM Unit := do
525
525
findTactics ids stx
526
526
match stx with
527
527
| `($e.%$tk$field:ident) =>
@@ -550,7 +550,9 @@ partial def highlight' (ids : HashMap Lsp.RefIdent Lsp.RefIdent) (stx : Syntax)
550
550
| stx@(.atom i x) =>
551
551
let docs ← match lookingAt with
552
552
| none => pure none
553
- | some n => findDocString? (← getEnv) n
553
+ | some (n, _) => findDocString? (← getEnv) n
554
+ let name := lookingAt.map (·.1 )
555
+ let occ := lookingAt.map fun (n, pos) => s! "{ n} -{ pos} "
554
556
if let .sort ← identKind ids ⟨stx⟩ then
555
557
emitToken i ⟨.sort, x⟩
556
558
return
@@ -560,11 +562,11 @@ partial def highlight' (ids : HashMap Lsp.RefIdent Lsp.RefIdent) (stx : Syntax)
560
562
| some '#' =>
561
563
match x.get? ((0 : String.Pos) + '#' ) with
562
564
| some c =>
563
- if c.isAlpha then .keyword lookingAt docs
565
+ if c.isAlpha then .keyword name occ docs
564
566
else .unknown
565
567
| _ => .unknown
566
568
| some c =>
567
- if c.isAlpha then .keyword lookingAt docs
569
+ if c.isAlpha then .keyword name occ docs
568
570
else .unknown
569
571
| _ => .unknown
570
572
| .node _ `str #[.atom i string] =>
@@ -586,9 +588,10 @@ partial def highlight' (ids : HashMap Lsp.RefIdent Lsp.RefIdent) (stx : Syntax)
586
588
| _, _ =>
587
589
highlight' ids dot
588
590
highlight' ids name
589
- | .node _ k children =>
591
+ | stx@(.node _ k children) =>
592
+ let pos := stx.getPos?
590
593
for child in children do
591
- highlight' ids child (lookingAt := some k )
594
+ highlight' ids child (lookingAt := pos.map (k, ·) )
592
595
593
596
def highlight (stx : Syntax) (messages : Array Message) : TermElabM Highlighted := do
594
597
let modrefs := Lean.Server.findModuleRefs (← getFileMap) (← getInfoTrees).toArray
0 commit comments