⚡ 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 { BlockShape, CodeBlock, CommandFacts, CommandWord, DeclaratorFacts,
|
||||
import type { CommentRules, ListBlocks } from './shared'
|
||||
import * as path from 'node:path'
|
||||
import { bashNameReader } from './bashNames'
|
||||
import { attachComments, children, compoundShape, leafBlock, leafShape, listBlocks, named } from './shared'
|
||||
import { attachComments, children, compoundShape, insideOf, leafBlock, leafShape, listBlocks, named } from './shared'
|
||||
|
||||
/** 按习惯当常量用的名字:全大写(可带数字、下划线)。 */
|
||||
const CONSTANT_NAME = /^[A-Z][A-Z0-9_]*$/
|
||||
@@ -543,15 +543,8 @@ function bashSymbols(root: Node): LocalSymbol[] {
|
||||
|
||||
// ─── 词性 ────────────────────────────────────────────────────────────────────
|
||||
|
||||
function insideString(leaf: Node): boolean {
|
||||
for (let node = leaf.parent; node; node = node.parent) {
|
||||
if (EXPANSIONS.has(node.type))
|
||||
return false
|
||||
if (node.type === 'string' || node.type === 'heredoc_body')
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
/** 字符串、here document 里的词:里面的展开(`$x`、`$(…)`)不算。 */
|
||||
const insideString = insideOf({ ...Object.fromEntries([...EXPANSIONS].map(type => [type, false])), string: true, heredoc_body: true })
|
||||
|
||||
function bashTokenRole(leaf: Node): TokenRole {
|
||||
const parent = leaf.parent
|
||||
|
||||
Reference in new issue
Block a user