microsoft / microsoft/TypeScript
[Bug] PrivateIdentifier nodes are omitted from 2020 semantic classifications
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 src/services/classifier2020.ts 中的 collectTokens 开始,检查标识符节点现有的 declaration-kind 映射。添加涵盖 private 字段和方法声明及引用的相关 fourslash 回归测试,然后验证这些节点是否获得 property 或 method 分类以及 declaration modifiers。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript, vscode
- 领域
- compilers, developer-experience
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 活跃
- 描述清晰度
- 描述清楚
- 新手友好度
- 88/100