[Bug] PrivateIdentifier nodes are omitted from 2020 semantic classifications
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript, vscode
- Domain
- compilers, developer-experience
Research direction
Start in src/services/classifier2020.ts at collectTokens and review the existing declaration-kind mapping for identifier nodes. Add the relevant fourslash regression test covering private field and method declarations and references, then verify that the nodes receive property or method classifications and declaration modifiers.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 106
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/TypeScript
-
Possible Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/TypeScript#64278 · 1 comment · 1 reaction ·
-
Docs
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
microsoft/TypeScript#64118 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
microsoft/TypeScript#63959 · 5 comments ·
-
Domain: lib.d.ts Help Wanted
Difficulty 1/5 Under an hour Newbie friendliness 91/100
microsoft/TypeScript#63722 · 4 comments · 1 reaction ·
All issues in microsoft/TypeScript
Similar issues
-
kind/bug needs-triage
Difficulty 1/5 Under an hour Newbie friendliness 72/100
matrixorigin/matrixone#29223 ·
-
needs-acceptance wg/data-plane-networking
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/semantic-router#4024 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
alexgorbatchev/dotfiles#107 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100