Skip to content
This repository was archived by the owner on Aug 24, 2024. It is now read-only.

Commit 7c9f47f

Browse files
committed
fix: hardcoded value caused wrong semantic type
1 parent bc008fe commit 7c9f47f

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

LeanInk/Analysis/DataTypes.lean

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ instance : Positional Fragment where
5151
inductive SemanticTokenType where
5252
| property
5353
| «variable»
54-
| «constant»
5554
| keyword
56-
| literal
5755

5856
structure SemanticTokenInfo extends Fragment where
5957
semanticType: Option SemanticTokenType := none
@@ -162,9 +160,15 @@ instance : Positional Sentence where
162160
tailPos := (λ x => x.toFragment.tailPos)
163161

164162
/- InfoTree -/
163+
private def Info.isExpanded (self : Info) : Bool :=
164+
let stx := Info.stx self
165+
match stx.getHeadInfo, stx.getTailInfo with
166+
| SourceInfo.original .., SourceInfo.original .. => false
167+
| _, _ => true
168+
165169
structure SemanticTraversalInfo where
166170
stx : Syntax
167-
node : Info
171+
node : Option Info
168172

169173
namespace SemanticTraversalInfo
170174
def genSemanticToken (stx : Syntax) (type : SemanticTokenType) : List Token :=
@@ -173,21 +177,28 @@ namespace SemanticTraversalInfo
173177
if headPos >= tailPos then
174178
[]
175179
else
176-
[Token.semantic { semanticType := SemanticTokenType.variable, headPos := headPos, tailPos := tailPos }]
180+
[Token.semantic { semanticType := type, headPos := headPos, tailPos := tailPos }]
177181

178182
def highlightIdentifier (globalTailPos : String.Pos) (info : SemanticTraversalInfo) : AnalysisM (List Token) := do
179-
match info.stx.getRange?, info.node with
180-
| some range, Info.ofTermInfo info => do
181-
let genToken := genSemanticToken info.stx
182-
match info.expr with
183-
| Expr.fvar .. => return genToken SemanticTokenType.variable
184-
| Expr.lit .. => return genToken SemanticTokenType.literal
185-
| _ =>
186-
if (info.stx.getPos? false).getD 0 > globalTailPos then
187-
return genToken SemanticTokenType.property
188-
else
189-
return []
190-
| _, _ => pure []
183+
match info.node with
184+
| some node => do
185+
if Info.isExpanded node then
186+
return []
187+
match info.stx.getRange?, info.node with
188+
| some range, Info.ofTermInfo info => do
189+
let genToken := genSemanticToken info.stx
190+
match info.expr with
191+
| Expr.fvar .. => return genToken SemanticTokenType.variable
192+
| _ =>
193+
match info.stx.getPos? with
194+
| some pos =>
195+
if pos > globalTailPos then
196+
return genToken SemanticTokenType.property
197+
else
198+
return []
199+
| _ => pure []
200+
| _, _ => pure []
201+
| _ => pure []
191202

192203
def highlightKeyword (headPos tailPos : String.Pos) (stx: Syntax) : AnalysisM (List Token) := do
193204
if let Syntax.atom info val := stx then
@@ -250,12 +261,6 @@ namespace TraversalFragment
250261
| tactic fragment => (fragment.info.toElabInfo.stx.getTailPos? false).getD 0
251262
| unknown fragment => (fragment.info.stx.getTailPos? false).getD 0
252263

253-
private def Info.isExpanded (self : Info) : Bool :=
254-
let stx := Info.stx self
255-
match stx.getHeadInfo, stx.getTailInfo with
256-
| SourceInfo.original .., SourceInfo.original .. => false
257-
| _, _ => true
258-
259264
def create (ctx : ContextInfo) (info : Info) : ((Option TraversalFragment) × (Option SemanticTraversalInfo)) :=
260265
if Info.isExpanded info then
261266
(none, none)

LeanInk/Annotation/Alectryon.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ def genSemanticTokenValue : Option SemanticTokenInfo -> AnalysisM (Option String
121121
| SemanticTokenType.property => pure (some "Name.Attribute")
122122
| SemanticTokenType.keyword => pure (some "Keyword")
123123
| SemanticTokenType.variable => pure (some "Name.Variable")
124-
| SemanticTokenType.constant => pure (some "Name.Constant")
125-
| SemanticTokenType.literal => pure (some "Literal")
126124
| default => pure none
127125

128126
def genToken (token : Compound Analysis.Token) (contents : String) (getContents : String.Pos -> String.Pos -> String) : AnalysisM Token := do

0 commit comments

Comments
 (0)