From a4643b0ee0ae1bdf6a9a91b8ef64db5ba2d81bf2 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 9 May 2024 11:09:49 -0700 Subject: [PATCH] Enable web type acquisition by default for js/ts (#212370) * Enable web type acquisition by default for js/ts Fixes #182791 Fixes #172887 * Cleanup --- .../typescript-language-features/package.json | 15 +++++++------- .../package.nls.json | 4 ++-- .../src/configuration/configuration.ts | 18 ++++++++--------- .../src/extension.browser.ts | 20 ++++++++++++------- .../src/languageProvider.ts | 11 +++++++--- .../src/tsServer/serverProcess.browser.ts | 2 +- .../web/src/fileWatcherManager.ts | 2 -- 7 files changed, 40 insertions(+), 32 deletions(-) diff --git a/extensions/typescript-language-features/package.json b/extensions/typescript-language-features/package.json index fb5383a2978b7..45c687225b542 100644 --- a/extensions/typescript-language-features/package.json +++ b/extensions/typescript-language-features/package.json @@ -1280,22 +1280,21 @@ }, "typescript.tsserver.web.projectWideIntellisense.suppressSemanticErrors": { "type": "boolean", - "default": true, + "default": false, "description": "%configuration.tsserver.web.projectWideIntellisense.suppressSemanticErrors%", "scope": "window" }, + "typescript.tsserver.web.typeAcquisition.enabled": { + "type": "boolean", + "default": true, + "description": "%configuration.tsserver.web.typeAcquisition.enabled%", + "scope": "window" + }, "typescript.tsserver.nodePath": { "type": "string", "description": "%configuration.tsserver.nodePath%", "scope": "window" }, - "typescript.experimental.tsserver.web.typeAcquisition.enabled": { - "type": "boolean", - "default": false, - "description": "%configuration.experimental.tsserver.web.typeAcquisition.enabled%", - "scope": "window", - "tags": ["experimental"] - }, "typescript.preferGoToSourceDefinition": { "type": "boolean", "default": false, diff --git a/extensions/typescript-language-features/package.nls.json b/extensions/typescript-language-features/package.nls.json index e60451eaeb4a9..332f69b71400f 100644 --- a/extensions/typescript-language-features/package.nls.json +++ b/extensions/typescript-language-features/package.nls.json @@ -216,9 +216,9 @@ "configuration.suggest.classMemberSnippets.enabled": "Enable/disable snippet completions for class members.", "configuration.suggest.objectLiteralMethodSnippets.enabled": "Enable/disable snippet completions for methods in object literals.", "configuration.tsserver.web.projectWideIntellisense.enabled": "Enable/disable project-wide IntelliSense on web. Requires that VS Code is running in a trusted context.", - "configuration.tsserver.web.projectWideIntellisense.suppressSemanticErrors": "Suppresses semantic errors. This is needed when using external packages as these can't be included analyzed on web.", + "configuration.tsserver.web.projectWideIntellisense.suppressSemanticErrors": "Suppresses semantic errors on web even when project wide IntelliSense is enabled. This is always on when project wide IntelliSense is not enabled or available. See `#typescript.tsserver.web.projectWideIntellisense.enabled#`", + "configuration.tsserver.web.typeAcquisition.enabled": "Enable/disable package acquisition on the web. This enables IntelliSense for imported packages. Requires `#typescript.tsserver.web.projectWideIntellisense.enabled#`.", "configuration.tsserver.nodePath": "Run TS Server on a custom Node installation. This can be a path to a Node executable, or 'node' if you want VS Code to detect a Node installation.", - "configuration.experimental.tsserver.web.typeAcquisition.enabled": "Enable/disable package acquisition on the web.", "walkthroughs.nodejsWelcome.title": "Get started with JavaScript and Node.js", "walkthroughs.nodejsWelcome.description": "Make the most of Visual Studio Code's first-class JavaScript experience.", "walkthroughs.nodejsWelcome.downloadNode.forMacOrWindows.title": "Install Node.js", diff --git a/extensions/typescript-language-features/src/configuration/configuration.ts b/extensions/typescript-language-features/src/configuration/configuration.ts index 47620bd0743b3..2f0ff4b0a28da 100644 --- a/extensions/typescript-language-features/src/configuration/configuration.ts +++ b/extensions/typescript-language-features/src/configuration/configuration.ts @@ -112,7 +112,7 @@ export interface TypeScriptServiceConfiguration { readonly useSyntaxServer: SyntaxServerConfiguration; readonly webProjectWideIntellisenseEnabled: boolean; readonly webProjectWideIntellisenseSuppressSemanticErrors: boolean; - readonly webExperimentalTypeAcquisition: boolean; + readonly webTypeAcquisitionEnabled: boolean; readonly enableDiagnosticsTelemetry: boolean; readonly enableProjectDiagnostics: boolean; readonly maxTsServerMemory: number; @@ -150,7 +150,7 @@ export abstract class BaseServiceConfigurationProvider implements ServiceConfigu useSyntaxServer: this.readUseSyntaxServer(configuration), webProjectWideIntellisenseEnabled: this.readWebProjectWideIntellisenseEnable(configuration), webProjectWideIntellisenseSuppressSemanticErrors: this.readWebProjectWideIntellisenseSuppressSemanticErrors(configuration), - webExperimentalTypeAcquisition: this.readWebExperimentalTypeAcquisition(configuration), + webTypeAcquisitionEnabled: this.readWebTypeAcquisition(configuration), enableDiagnosticsTelemetry: this.readEnableDiagnosticsTelemetry(configuration), enableProjectDiagnostics: this.readEnableProjectDiagnostics(configuration), maxTsServerMemory: this.readMaxTsServerMemory(configuration), @@ -187,10 +187,6 @@ export abstract class BaseServiceConfigurationProvider implements ServiceConfigu return configuration.get('typescript.disableAutomaticTypeAcquisition', false); } - protected readWebExperimentalTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean { - return configuration.get('typescript.experimental.tsserver.web.typeAcquisition.enabled', false); - } - protected readLocale(configuration: vscode.WorkspaceConfiguration): string | null { const value = configuration.get('typescript.locale', 'auto'); return !value || value === 'auto' ? null : value; @@ -256,15 +252,19 @@ export abstract class BaseServiceConfigurationProvider implements ServiceConfigu return configuration.get('typescript.tsserver.enableTracing', false); } + private readWorkspaceSymbolsExcludeLibrarySymbols(configuration: vscode.WorkspaceConfiguration): boolean { + return configuration.get('typescript.workspaceSymbols.excludeLibrarySymbols', true); + } + private readWebProjectWideIntellisenseEnable(configuration: vscode.WorkspaceConfiguration): boolean { return configuration.get('typescript.tsserver.web.projectWideIntellisense.enabled', true); } private readWebProjectWideIntellisenseSuppressSemanticErrors(configuration: vscode.WorkspaceConfiguration): boolean { - return configuration.get('typescript.tsserver.web.projectWideIntellisense.suppressSemanticErrors', true); + return configuration.get('typescript.tsserver.web.projectWideIntellisense.suppressSemanticErrors', false); } - private readWorkspaceSymbolsExcludeLibrarySymbols(configuration: vscode.WorkspaceConfiguration): boolean { - return configuration.get('typescript.workspaceSymbols.excludeLibrarySymbols', true); + private readWebTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean { + return configuration.get('typescript.tsserver.web.typeAcquisition.enabled', true); } } diff --git a/extensions/typescript-language-features/src/extension.browser.ts b/extensions/typescript-language-features/src/extension.browser.ts index 91a652ed6fa51..25a7669a32664 100644 --- a/extensions/typescript-language-features/src/extension.browser.ts +++ b/extensions/typescript-language-features/src/extension.browser.ts @@ -62,7 +62,7 @@ export async function activate(context: vscode.ExtensionContext): Promise { new TypeScriptVersion( TypeScriptVersionSource.Bundled, vscode.Uri.joinPath(context.extensionUri, 'dist/browser/typescript/tsserver.web.js').toString(), - API.fromSimpleString('5.3.2'))); + API.fromSimpleString('5.4.5'))); let experimentTelemetryReporter: IExperimentationTelemetryReporter | undefined; const packageInfo = getPackageInfo(context); @@ -118,15 +118,21 @@ async function startPreloadWorkspaceContentsIfNeeded(context: vscode.ExtensionCo return; } - const workspaceUri = vscode.workspace.workspaceFolders?.at(0)?.uri; - if (!workspaceUri || workspaceUri.scheme !== 'vscode-vfs' || !workspaceUri.authority.startsWith('github')) { - logger.info(`Skipped loading workspace contents for repository ${workspaceUri?.toString()}`); + if (!vscode.workspace.workspaceFolders) { return; } - const loader = new RemoteWorkspaceContentsPreloader(workspaceUri, logger); - context.subscriptions.push(loader); - return loader.triggerPreload(); + await Promise.all(vscode.workspace.workspaceFolders.map(async folder => { + const workspaceUri = folder.uri; + if (workspaceUri.scheme !== 'vscode-vfs' || !workspaceUri.authority.startsWith('github')) { + logger.info(`Skipped pre loading workspace contents for repository ${workspaceUri?.toString()}`); + return; + } + + const loader = new RemoteWorkspaceContentsPreloader(workspaceUri, logger); + context.subscriptions.push(loader); + await loader.triggerPreload(); + })); } class RemoteWorkspaceContentsPreloader extends Disposable { diff --git a/extensions/typescript-language-features/src/languageProvider.ts b/extensions/typescript-language-features/src/languageProvider.ts index 6bd2b4ed7b7eb..f44ebcc1212ad 100644 --- a/extensions/typescript-language-features/src/languageProvider.ts +++ b/extensions/typescript-language-features/src/languageProvider.ts @@ -18,7 +18,7 @@ import { ClientCapability } from './typescriptService'; import TypeScriptServiceClient from './typescriptServiceClient'; import TypingsStatus from './ui/typingsStatus'; import { Disposable } from './utils/dispose'; -import { isWeb } from './utils/platform'; +import { isWeb, isWebAndHasSharedArrayBuffers } from './utils/platform'; const validateSetting = 'validate.enable'; @@ -142,8 +142,13 @@ export default class LanguageProvider extends Disposable { return; } - if (diagnosticsKind === DiagnosticKind.Semantic && isWeb() && this.client.configuration.webProjectWideIntellisenseSuppressSemanticErrors) { - return; + if (diagnosticsKind === DiagnosticKind.Semantic && isWeb()) { + if (!isWebAndHasSharedArrayBuffers() + || this.client.configuration.webProjectWideIntellisenseSuppressSemanticErrors + || !this.client.configuration.webProjectWideIntellisenseEnabled + ) { + return; + } } // Disable semantic errors in notebooks until we have better notebook support diff --git a/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts b/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts index bb57c2644b477..8c5b8bfc527e2 100644 --- a/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts +++ b/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts @@ -50,7 +50,7 @@ export class WorkerServerProcessFactory implements TsServerProcessFactory { // Explicitly give TS Server its path so it can load local resources '--executingFilePath', tsServerPath, ]; - if (_configuration.webExperimentalTypeAcquisition) { + if (_configuration.webTypeAcquisitionEnabled) { launchArgs.push('--experimentalTypeAcquisition'); } return new WorkerServerProcess(kind, tsServerPath, this._extensionUri, launchArgs, tsServerLog, this._logger); diff --git a/extensions/typescript-language-features/web/src/fileWatcherManager.ts b/extensions/typescript-language-features/web/src/fileWatcherManager.ts index 8c8d7403740ec..5bbce24468829 100644 --- a/extensions/typescript-language-features/web/src/fileWatcherManager.ts +++ b/extensions/typescript-language-features/web/src/fileWatcherManager.ts @@ -40,8 +40,6 @@ export class FileWatcherManager { return FileWatcherManager.noopWatcher; } - console.log('watching file:', path); - this.logger.logVerbose('fs.watchFile', { path }); let uri: URI;