@@ -51,9 +51,7 @@ instance : Positional Fragment where
51
51
inductive SemanticTokenType where
52
52
| property
53
53
| «variable »
54
- | «constant »
55
54
| keyword
56
- | literal
57
55
58
56
structure SemanticTokenInfo extends Fragment where
59
57
semanticType: Option SemanticTokenType := none
@@ -162,9 +160,15 @@ instance : Positional Sentence where
162
160
tailPos := (λ x => x.toFragment.tailPos)
163
161
164
162
/- 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
+
165
169
structure SemanticTraversalInfo where
166
170
stx : Syntax
167
- node : Info
171
+ node : Option Info
168
172
169
173
namespace SemanticTraversalInfo
170
174
def genSemanticToken (stx : Syntax) (type : SemanticTokenType) : List Token :=
@@ -173,21 +177,28 @@ namespace SemanticTraversalInfo
173
177
if headPos >= tailPos then
174
178
[]
175
179
else
176
- [Token.semantic { semanticType := SemanticTokenType.variable , headPos := headPos, tailPos := tailPos }]
180
+ [Token.semantic { semanticType := type , headPos := headPos, tailPos := tailPos }]
177
181
178
182
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 []
191
202
192
203
def highlightKeyword (headPos tailPos : String.Pos) (stx: Syntax) : AnalysisM (List Token) := do
193
204
if let Syntax.atom info val := stx then
@@ -250,12 +261,6 @@ namespace TraversalFragment
250
261
| tactic fragment => (fragment.info.toElabInfo.stx.getTailPos? false ).getD 0
251
262
| unknown fragment => (fragment.info.stx.getTailPos? false ).getD 0
252
263
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
-
259
264
def create (ctx : ContextInfo) (info : Info) : ((Option TraversalFragment) × (Option SemanticTraversalInfo)) :=
260
265
if Info.isExpanded info then
261
266
(none, none)
0 commit comments