[Bug] PrivateIdentifier nodes are omitted from 2020 semantic classifications
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- typescript, vscode
调研方向
从 src/services/classifier2020.ts 中的 collectTokens 开始,检查标识符节点现有的 declaration-kind 映射。添加涵盖 private 字段和方法声明及引用的相关 fourslash 回归测试,然后验证这些节点是否获得 property 或 method 分类以及 declaration modifiers。
由索引模型根据 Issue 内容生成。
描述
Bug Report
🔎 Search Terms
semantic highlighting, semantic token, PrivateIdentifier, private field, private method, encodedSemanticClassifications
🕗 Version & Regression Information
- TypeScript 6.0.3 (bundled with VS Code)
- Also present in the v5.9 classifier implementation
- This is not a theme-specific issue
💻 Code
class Foo {
field = 1;
#privateField = 1;
method() {}
#privateMethod() {}
test() {
this.field;
this.#privateField;
this.method();
this.#privateMethod();
}
}
🙁 Actual behavior
In VS Code's Developer: Inspect Editor Tokens and Scopes:
fieldandmethodreceive semantic token types.#privateFieldand#privateMethodreceive no semantic token and fall back to TextMate scopes.- As a result,
editor.semanticTokenColorCustomizationsrules forpropertyandmethoddo not apply to ECMAScript private members.
🙂 Expected behavior
#privateFieldshould be classified asproperty.#privateMethodshould be classified asmethod.- Declarations should also receive the
declarationmodifier.
Root cause
VS Code requests encodedSemanticClassifications-full with format "2020".
In src/services/classifier2020.ts, collectTokens only enters the semantic-classification path for isIdentifier(node):
if (isIdentifier(node) && ...) {
let symbol = typeChecker.getSymbolAtLocation(node);
// ...
}
ECMAScript private names are separate SyntaxKind.PrivateIdentifier nodes, so they are skipped before getSymbolAtLocation is called.
Relevant source:
https://github.com/microsoft/TypeScript/blob/050880ce59e30b356b686bd3144efe24f875ebc8/src/services/classifier2020.ts#L121-L203
Proposed fix
+ isPrivateIdentifier,
isPropertyAccessExpression,
- if (isIdentifier(node) && ...) {
+ if ((isIdentifier(node) || isPrivateIdentifier(node)) && ...) {
The existing declaration-kind mapping already classifies private fields and methods correctly once these nodes reach the symbol-classification path.
I tested the equivalent change against TypeScript 6.0.3:
#privateFielddeclaration/reference →property#privateMethoddeclaration/reference →memberinternally, mapped by VS Code tomethod- declaration occurrences receive the
declarationmodifier - added fourslash regression test passes
Related issue
https://github.com/microsoft/TypeScript/issues/44483 requests new private/protected semantic modifiers. This report is different: ECMAScript PrivateIdentifier nodes currently receive no semantic classification at all.
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 117
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/TypeScript 的其他 Issue
-
Possible Improvement
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/TypeScript#64278 · 1 条评论 · 1 个 reaction ·
-
Docs
难度 2/5 1-3 小时 新手友好度 70/100
microsoft/TypeScript#64118 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
microsoft/TypeScript#64094 ·
-
Docs
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/TypeScript#63959 · 5 条评论 ·
-
Domain: lib.d.ts Help Wanted
难度 1/5 1 小时以内 新手友好度 91/100
microsoft/TypeScript#63722 · 4 条评论 · 1 个 reaction ·
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
optimization optimization:agents-md-curator
难度 2/5 1-3 小时 新手友好度 86/100
githubnext/gh-aw-cao#13143 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
blinklabs-io/bursa#904 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
难度 2/5 1-3 小时 新手友好度 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 条评论 ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist 未关闭bug
难度 2/5 1-3 小时 新手友好度 90/100