split namedarg and = into different tokens
This commit is contained in:
parent
54a5fec08e
commit
fcfbace65e
|
|
@ -39,6 +39,39 @@ export function buildSemanticTokens(document: TextDocument): number[] {
|
||||||
return builder.build().data
|
return builder.build().data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emit split tokens for NamedArgPrefix (e.g., "color=" → "color" + "=")
|
||||||
|
function emitNamedArgPrefix(
|
||||||
|
node: SyntaxNode,
|
||||||
|
document: TextDocument,
|
||||||
|
builder: SemanticTokensBuilder
|
||||||
|
) {
|
||||||
|
const text = document.getText({
|
||||||
|
start: document.positionAt(node.from),
|
||||||
|
end: document.positionAt(node.to),
|
||||||
|
})
|
||||||
|
|
||||||
|
const nameLength = text.length - 1 // Everything except the =
|
||||||
|
const start = document.positionAt(node.from)
|
||||||
|
|
||||||
|
// Emit token for the name part (e.g., "color")
|
||||||
|
builder.push(
|
||||||
|
start.line,
|
||||||
|
start.character,
|
||||||
|
nameLength,
|
||||||
|
TOKEN_TYPES.indexOf(SemanticTokenTypes.property),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
|
||||||
|
// Emit token for the "=" part
|
||||||
|
builder.push(
|
||||||
|
start.line,
|
||||||
|
start.character + nameLength,
|
||||||
|
1, // Just the = character
|
||||||
|
TOKEN_TYPES.indexOf(SemanticTokenTypes.operator),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Walk the tree and collect tokens
|
// Walk the tree and collect tokens
|
||||||
function walkTree(
|
function walkTree(
|
||||||
node: SyntaxNode,
|
node: SyntaxNode,
|
||||||
|
|
@ -46,6 +79,10 @@ function walkTree(
|
||||||
builder: SemanticTokensBuilder,
|
builder: SemanticTokensBuilder,
|
||||||
scopeTracker: ScopeTracker
|
scopeTracker: ScopeTracker
|
||||||
) {
|
) {
|
||||||
|
// Special handling for NamedArgPrefix to split "name=" into two tokens
|
||||||
|
if (node.type.id === Terms.NamedArgPrefix) {
|
||||||
|
emitNamedArgPrefix(node, document, builder)
|
||||||
|
} else {
|
||||||
const tokenInfo = getTokenType(node, document, scopeTracker)
|
const tokenInfo = getTokenType(node, document, scopeTracker)
|
||||||
|
|
||||||
if (tokenInfo !== undefined) {
|
if (tokenInfo !== undefined) {
|
||||||
|
|
@ -53,6 +90,7 @@ function walkTree(
|
||||||
const length = node.to - node.from
|
const length = node.to - node.from
|
||||||
builder.push(start.line, start.character, length, tokenInfo.type, tokenInfo.modifiers)
|
builder.push(start.line, start.character, length, tokenInfo.type, tokenInfo.modifiers)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let child = node.firstChild
|
let child = node.firstChild
|
||||||
while (child) {
|
while (child) {
|
||||||
|
|
@ -142,12 +180,6 @@ function getTokenType(
|
||||||
modifiers: 0,
|
modifiers: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
case Terms.NamedArgPrefix:
|
|
||||||
return {
|
|
||||||
type: TOKEN_TYPES.indexOf(SemanticTokenTypes.property),
|
|
||||||
modifiers: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
case Terms.AssignableIdentifier:
|
case Terms.AssignableIdentifier:
|
||||||
return {
|
return {
|
||||||
type: TOKEN_TYPES.indexOf(SemanticTokenTypes.variable),
|
type: TOKEN_TYPES.indexOf(SemanticTokenTypes.variable),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user