microsoft / microsoft/TypeScript-TmLanguage

typescript-basics: fix highlighting for triple-slash reference directives with preserve="true"

Offen
#1,066 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
TypeScript
Sterne
471
Forks
149
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Does this issue occur when all extensions are disabled?: Yes

  • versions
Version: 1.108.2
Commit: c9d77990917f3102ada88be140d28b038d1dd7c7
Date: 2026-01-21T13:52:09.270Z
Electron: 39.2.7
ElectronBuildId: 12953945
Chromium: 142.0.7444.235
Node.js: 22.21.1
V8: 14.2.231.21-electron.0
OS: Windows_NT x64 10.0.19045
Problem

TypeScript supports preserve="true" on triple-slash reference directives, e.g.

/// <reference path="../communication-api.d.ts" preserve="true" />

However, VS Code's bundled TypeScript TextMate grammar fails to recognize the directive when preserve="true" is present, causing the line to be tokenized as a regular line comment instead of a reference directive.

Expected behavior

/// <reference ... /> should be tokenized/highlighted as a reference directive regardless of the presence of preserve="true".

Actual behavior

When preserve="true" is present, the entire line is highlighted as a regular line comment (directive tokenization does not apply).

Repro
  1. Open a .ts file in VS Code
  2. Add the following baseline line (this is highlighted as a reference directive):
/// <reference path="../communication-api.d.ts" />
  1. Now add preserve="true" (this becomes a regular comment highlight):
/// <reference path="../communication-api.d.ts" preserve="true" />
  1. Observe that only the preserve="true" form loses directive highlighting.
Evidence (Inspect Editor Tokens and Scopes)

Without preserve="true"

  • textmate scopes:
    • punctuation.definition.comment.ts
    • comment.line.triple-slash.directive.ts
    • source.ts
    • comment.line
Image

With preserve="true"

  • textmate scopes:
    • comment.line.double-slash.ts
    • source.ts
    • comment.line
Image
Potential fix

Update extensions/typescript-basics/syntaxes/TypeScript.tmLanguage.json under repository/directives to allow the optional preserve="true" attribute in /// <reference ... /> directives.

This makes directives with preserve="true" highlight consistently with the existing path/types/lib reference directives.

Notes
  • The change is limited to the directive-matching pattern and does not affect general comment tokenization.
  • Handles common spacing variants (e.g. preserve="true"/> and preserve="true" />).
Tests
  • Manual verification in VS Code:

    • /// <reference path="..." /> (unchanged)
    • /// <reference path="..." preserve="true" /> (now highlighted as directive)
    • Same for types and lib forms
  • (Optional) Add/adjust a colorize fixture under extensions/typescript-basics/test/colorize-fixtures/ to cover the preserve="true" case.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie in extensions/typescript-basics/syntaxes/TypeScript.tmLanguage.json, insbesondere mit dem im Issue beschriebenen repository/directives-Muster. Prüfen Sie die vorhandenen Colorize-Fixtures unter extensions/typescript-basics/test/colorize-fixtures/ und verifizieren Sie, dass die path-, types- und lib-Direktiven mit und ohne preserve="true" weiterhin korrekt hervorgehoben werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
1/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
58/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.