Add TypeScript 7 context support - #331798
Conversation
There was a problem hiding this comment.
Pull request overview
Adds opt-in TypeScript 7 language-context and NES rename support using the native TypeScript API while retaining TypeScript 6 compatibility.
Changes:
- Adds TS7 context providers, caching, telemetry, and native API lifecycle management.
- Routes TS6/TS7 context and rename services using configuration.
- Adds TS7 dependencies, settings, and tests.
Show a summary per file
| File | Description |
|---|---|
configurationService.ts |
Defines the TS7 feature setting. |
vscode-node/types.ts |
Adds shared cache and telemetry types. |
vscode-node/tsService.ts |
Detects TS7 configuration and extensions. |
tsc6/tsContextService.ts |
Extracts the TS6 context implementation. |
tsc6/nesRenameService.ts |
Extracts TS6 rename support. |
ts7/typescripts.ts |
Adds native TypeScript symbol utilities. |
ts7/types.ts |
Defines TS7 context abstractions. |
ts7/tsContextService.ts |
Implements TS7 context caching and delivery. |
ts7/ts7Api.ts |
Manages the shared native API connection. |
ts7/test/simple.spec.ts |
Tests core TS7 context generation. |
ts7/test/nesRename.spec.ts |
Tests TS7 NES rename behavior. |
ts7/sourceFileContextProvider.ts |
Provides source-file context. |
ts7/nullContextProvider.ts |
Adds a no-op context provider. |
ts7/nesRenameValidator.ts |
Validates rename safety. |
ts7/nesRenameService.ts |
Implements native NES rename operations. |
ts7/moduleContextProvider.ts |
Provides module context. |
ts7/methodContextProvider.ts |
Provides method and constructor context. |
ts7/functionContextProvider.ts |
Provides function context. |
ts7/code.ts |
Builds context code snippets. |
ts7/classContextProvider.ts |
Provides class and inheritance context. |
ts7/baseContextProviders.ts |
Implements common context runnables. |
ts7/api.ts |
Exposes context and rename operations. |
test/tsService.spec.ts |
Tests TS7 extension selection. |
telemetrySender.ts |
Adds context telemetry handling. |
nesRenameService.ts |
Routes rename operations by TS version. |
package.nls.json |
Localizes the TS7 setting description. |
package.json |
Registers the setting and native dependency. |
package-lock.json |
Locks the TypeScript native nightly. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Files not reviewed (1)
- extensions/copilot/package-lock.json: Generated file
- Files reviewed: 30/31 changed files
- Comments generated: 6
- Review effort level: Balanced
| return inspect !== undefined && ( | ||
| inspect.globalValue !== undefined || | ||
| inspect.workspaceValue !== undefined || | ||
| inspect.workspaceFolderValue !== undefined || | ||
| inspect.globalLanguageValue !== undefined || | ||
| inspect.workspaceLanguageValue !== undefined || | ||
| inspect.workspaceFolderLanguageValue !== undefined | ||
| ); |
| const inflightRequest = this.inflightCachePopulationRequest; | ||
| if (inflightRequest !== undefined && inflightRequest.matchesDocument(document)) { |
| // Recheck for an inflight request and join it if it is for the same document and position. | ||
| if (this.inflightCachePopulationRequest !== undefined && this.inflightCachePopulationRequest.matchesDocument(document)) { |
| "requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The request correlation id" }, | ||
| "opportunityId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The opportunity id" }, | ||
| "source": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The source of the request" }, | ||
| "code:": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The failure code" }, |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| } | ||
| // Workaround for https://github.com/microsoft/typescript-go/issues/4916 | ||
| api.clearSourceFileCache(); | ||
| const snapshot = await api.updateSnapshot({ openFiles: [ { uri: document.uri.toString() } ] }); |
There was a problem hiding this comment.
AI Review: updateSnapshot({ openFiles }) records persistent per-client state until closeFiles; disposing the returned snapshot only releases that snapshot ID. Because this API connection is shared for the service lifetime, every document queried by context or NES rename remains open after the editor closes, retaining its configured or inferred project. Track opened URIs and send closeFiles on document close/disposal, or balance access through a shared reference-counted helper.
| : vscode.extensions.getExtension('vscode.typescript-language-features'); | ||
| if (typeScriptExtension === undefined) { | ||
| this.telemetrySender.sendActivationFailedTelemetry(ErrorLocation.Client, ErrorPart.TypescriptPlugin, 'TypeScript extension not found', undefined); | ||
| this.telemetrySender.sendActivationFailedTelemetry(ErrorLocation.Client, ErrorPart.TypescriptPlugin, 'TypeScript extension not found', useTypeScript7 ? 'ts6' : 'ts7'); |
There was a problem hiding this comment.
AI Review: All three activation-failure paths report ts6 when useTypeScript7 is true and ts7 otherwise. This call also passes that value as the fourth stack argument, leaving version unspecified. Swap the ternary arms at all three sites and pass undefined before the version in this call.
| const result: number[] = []; | ||
| let current: Node | undefined = node; | ||
| while (current !== undefined) { | ||
| result.push(current.kind); |
There was a problem hiding this comment.
AI Review: TS6 deliberately maps compiler kinds to stable nodePath IDs, but this emits raw native TS7 values that already differ (Identifier is 79 natively versus stable ID 80, and FunctionDeclaration is 263 versus 262). Equivalent AST paths therefore produce incompatible telemetry under TS7 and can shift again with @typescript/native@next. Map native kinds by symbolic name to the existing stable IDs and add representative cross-engine path tests.
| if (!TypeScript.runsVersion7()) { | ||
| return new TS6NesRenameService(this.logService); | ||
| } | ||
| return TypeScript.isVersion7SupportEnabled(this.configurationService) |
There was a problem hiding this comment.
AI Review: When TS7 is active, this selects NullNesRenameService unless github.copilot.chat.languageContext.typescript7.enabled is enabled, silently disabling NES prepare/post rename even when NES itself is enabled. That flag is named and documented only for the TS7 language-context provider. Use a rename-specific or general TS7 rollout gate, or rename and document the existing setting as controlling both features.
fc07285
Introduce support for TypeScript 7 language context, including context providers and settings. Implement necessary bug fixes and improvements to ensure proper functionality. The new settings allow users to enable the TypeScript 7 language context for inline suggestions. Testing can be performed by enabling the new settings and verifying the context behavior in TypeScript 7 projects.