Skip to content

Commit

Permalink
feat(semanticTokens): improve decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Apr 1, 2024
1 parent e0f143a commit f7d4881
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/parsers/semanticTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ImportFromNode,
ImportNode,
MemberAccessNode,
NameNode,
ParameterNode,
ParseNode,
ParseNodeBase,
Expand Down Expand Up @@ -90,6 +91,25 @@ export class SemanticTokensWalker extends ParseTreeWalker {

visitDecorator(node: DecoratorNode): boolean {
this.addItem(node.expression, SemanticTokenTypes.decorator);
let nameNode: NameNode | undefined;
switch (node.expression.nodeType) {
case ParseNodeType.Call:
if (node.expression.leftExpression.nodeType === ParseNodeType.MemberAccess) {
nameNode = node.expression.leftExpression.memberName;
} else if (node.expression.leftExpression.nodeType === ParseNodeType.Name) {
nameNode = node.expression.leftExpression;
}
break;
case ParseNodeType.MemberAccess:
nameNode = node.expression.memberName;
break;
case ParseNodeType.Name:
nameNode = node.expression;
break;
}
if (nameNode) {
this.addItem(nameNode, SemanticTokenTypes.decorator);
}
return super.visitDecorator(node);
}

Expand Down

0 comments on commit f7d4881

Please sign in to comment.