⚡ perf(vscode): 语言插件给词定词性时,在不在字符串 / 注解 / 注释里按语法树一遍收齐的范围查,不再逐词往上找父节点
This commit is contained in:
1 parent
907c4092c8
commit
ded0395d1f
6 files changed
+205
-60
No files matched your search
@@ -2,7 +2,7 @@ import type { Access, AttributeFacts, AttributeItem, CfgPredicate, ClassFacts, C
|
||||
import type { CommentRules } from './shared'
|
||||
import * as path from 'node:path'
|
||||
import { leadingAttributes, visibilityFacts } from '../rules/rustTree'
|
||||
import { attachComments, children, compoundShape, extendHeader, headerSpan, isCommentNode, leafBlock, leafShape, listBlocks, named, syntaxChildren } from './shared'
|
||||
import { attachComments, children, compoundShape, extendHeader, headerSpan, insideOf, isCommentNode, leafBlock, leafShape, listBlocks, named, syntaxChildren } from './shared'
|
||||
|
||||
const STORAGE = new Set(['pub', 'async', 'const', 'static', 'mut', 'let'])
|
||||
|
||||
@@ -393,10 +393,13 @@ function isAsync(node: Node): boolean {
|
||||
return modifiers?.children.some(child => child?.type === 'async') ?? false
|
||||
}
|
||||
|
||||
const insideComment = insideOf({ line_comment: true, block_comment: true })
|
||||
const insideString = insideOf({ string_literal: true })
|
||||
|
||||
function rustTokenRole(leaf: Node): TokenRole {
|
||||
if (leaf.type === 'line_comment' || leaf.type === 'block_comment' || inside(leaf, 'line_comment') || inside(leaf, 'block_comment'))
|
||||
if (leaf.type === 'line_comment' || leaf.type === 'block_comment' || insideComment(leaf))
|
||||
return 'comment'
|
||||
if (inside(leaf, 'string_literal') || leaf.type === 'string_content')
|
||||
if (insideString(leaf) || leaf.type === 'string_content')
|
||||
return 'string'
|
||||
if (leaf.type === 'integer_literal' || leaf.type === 'float_literal' || leaf.type === 'char_literal')
|
||||
return 'number'
|
||||
@@ -412,13 +415,3 @@ function rustTokenRole(leaf: Node): TokenRole {
|
||||
}
|
||||
return 'plain'
|
||||
}
|
||||
|
||||
function inside(node: Node, type: string): boolean {
|
||||
let current = node.parent
|
||||
while (current) {
|
||||
if (current.type === type)
|
||||
return true
|
||||
current = current.parent
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user