Skip to content

Commit

Permalink
JS/TS package acquisition (#184438)
Browse files Browse the repository at this point in the history
* Experiment with adding ata using `@types` packages shipped in an extension

* Use own file system instead of `https`

* JS/TS type support on web

* Tsconfig needs esModuleInterop not module:nodenext

We actually want webpack to emit commonjs, but need to write ES default
imports to use node-maintainer

* fix package.json indentation

* Adding setting to disable web type acquisition

* Fix merge of yarn lock

* Fixing merge errors

* Fixing errors

* Pick up package externally

* Fixing conflicts

* Bump version

---------

Co-authored-by: Kat Marchán <[email protected]>
Co-authored-by: Nathan Shively-Sanders <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2023
1 parent 1a99420 commit 45e2e0b
Show file tree
Hide file tree
Showing 17 changed files with 1,055 additions and 269 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
**/extensions/typescript-language-features/test-workspace/**
**/extensions/typescript-language-features/extension.webpack.config.js
**/extensions/typescript-language-features/extension-browser.webpack.config.js
**/extensions/typescript-language-features/package-manager/node-maintainer/**
**/extensions/vscode-api-tests/testWorkspace/**
**/extensions/vscode-api-tests/testWorkspace2/**
**/fixtures/**
Expand Down
7 changes: 5 additions & 2 deletions build/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports.unicodeFilter = [
'!LICENSES.chromium.html',
'!**/LICENSE',

'!**/*.{dll,exe,png,bmp,jpg,scpt,cur,ttf,woff,eot,template,ico,icns,opus}',
'!**/*.{dll,exe,png,bmp,jpg,scpt,cur,ttf,woff,eot,template,ico,icns,opus,wasm}',
'!**/test/**',
'!**/*.test.ts',
'!**/*.{d.ts,json,md}',
Expand Down Expand Up @@ -88,6 +88,7 @@ module.exports.indentationFilter = [
'!test/smoke/out/**',
'!extensions/typescript-language-features/test-workspace/**',
'!extensions/typescript-language-features/resources/walkthroughs/**',
'!extensions/typescript-language-features/package-manager/node-maintainer/**',
'!extensions/markdown-math/notebook-out/**',
'!extensions/ipynb/notebook-out/**',
'!extensions/vscode-api-tests/testWorkspace/**',
Expand Down Expand Up @@ -115,7 +116,7 @@ module.exports.indentationFilter = [
'!src/vs/*/**/*.d.ts',
'!src/typings/**/*.d.ts',
'!extensions/**/*.d.ts',
'!**/*.{svg,exe,png,bmp,jpg,scpt,bat,cmd,cur,ttf,woff,eot,md,ps1,template,yaml,yml,d.ts.recipe,ico,icns,plist,opus,admx,adml}',
'!**/*.{svg,exe,png,bmp,jpg,scpt,bat,cmd,cur,ttf,woff,eot,md,ps1,template,yaml,yml,d.ts.recipe,ico,icns,plist,opus,admx,adml,wasm}',
'!build/{lib,download,linux,darwin}/**/*.js',
'!build/**/*.sh',
'!build/azure-pipelines/**/*.js',
Expand Down Expand Up @@ -157,6 +158,7 @@ module.exports.copyrightFilter = [
'!**/*.disabled',
'!**/*.code-workspace',
'!**/*.js.map',
'!**/*.wasm',
'!build/**/*.init',
'!build/linux/libcxx-fetcher.*',
'!resources/linux/snap/snapcraft.yaml',
Expand All @@ -166,6 +168,7 @@ module.exports.copyrightFilter = [
'!extensions/markdown-language-features/media/highlight.css',
'!extensions/markdown-math/notebook-out/**',
'!extensions/ipynb/notebook-out/**',
'!extensions/typescript-language-features/node-maintainer/**',
'!extensions/html-language-features/server/src/modes/typescript/*',
'!extensions/*/server/bin/*',
'!src/vs/editor/test/node/classification/typescript-test.ts',
Expand Down
3 changes: 3 additions & 0 deletions extensions/shared.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ function withBrowserDefaults(/**@type WebpackConfig & { context: string }*/extCo
},
},
]
}, {
test: /\.wasm$/,
type: 'asset/inline'
}]
},
externals: {
Expand Down
14 changes: 11 additions & 3 deletions extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
],
"dependencies": {
"@vscode/extension-telemetry": "^0.8.4",
"jsonc-parser": "^3.2.0",
"semver": "7.5.2",
"vscode-tas-client": "^0.1.63",
"@vscode/sync-api-client": "^0.7.2",
"@vscode/sync-api-common": "^0.7.2",
"@vscode/sync-api-service": "^0.7.3",
"@vscode/ts-package-manager": "^0.0.2",
"jsonc-parser": "^3.2.0",
"semver": "7.5.2",
"vscode-tas-client": "^0.1.63",
"vscode-uri": "^3.0.3"
},
"devDependencies": {
Expand Down Expand Up @@ -1250,6 +1251,13 @@
"description": "%configuration.tsserver.web.projectWideIntellisense.suppressSemanticErrors%",
"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,
Expand Down
17 changes: 16 additions & 1 deletion extensions/typescript-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,20 @@
"configuration.suggest.classMemberSnippets.enabled": "Enable/disable snippet completions for class members.",
"configuration.suggest.objectLiteralMethodSnippets.enabled": "Enable/disable snippet completions for methods in object literals. Requires using TypeScript 4.7+ in the workspace.",
"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. This is needed when using external packages as these can't be included analyzed on web.",
"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",
"walkthroughs.nodejsWelcome.downloadNode.forMacOrWindows.description": "Node.js is an easy way to run JavaScript code. You can use it to quickly build command-line apps and servers. It also comes with npm, a package manager which makes reusing and sharing JavaScript code easy.\n[Install Node.js](https://nodejs.org/en/download/)",
"walkthroughs.nodejsWelcome.downloadNode.forLinux.title": "Install Node.js",
"walkthroughs.nodejsWelcome.downloadNode.forLinux.description": "Node.js is an easy way to run JavaScript code. You can use it to quickly build command-line apps and servers. It also comes with npm, a package manager which makes reusing and sharing JavaScript code easy.\n[Install Node.js](https://nodejs.org/en/download/package-manager/)",
"walkthroughs.nodejsWelcome.makeJsFile.title": "Create a JavaScript File",
"walkthroughs.nodejsWelcome.makeJsFile.description": "Let's write our first JavaScript file. We'll have to create a new file and save it with the ``.js`` extension at the end of the file name.\n[Create a JavaScript File](command:javascript-walkthrough.commands.createJsFile)",
"walkthroughs.nodejsWelcome.debugJsFile.title": "Run and Debug your JavaScript",
"walkthroughs.nodejsWelcome.debugJsFile.description": "Once you've installed Node.js, you can run JavaScript programs at a terminal by entering ``node your-file-name.js``\nAnother easy way to run Node.js programs is by using VS Code's debugger which lets you run your code, pause at different points, and help you understand what's going on step-by-step.\n[Start Debugging](command:javascript-walkthrough.commands.debugJsFile)",
"walkthroughs.nodejsWelcome.debugJsFile.altText": "Debug and run your JavaScript code in Node.js with Visual Studio Code.",
"walkthroughs.nodejsWelcome.learnMoreAboutJs.title": "Explore More",
"walkthroughs.nodejsWelcome.learnMoreAboutJs.description": "Want to get more comfortable with JavaScript, Node.js, and VS Code? Be sure to check out our docs!\nWe've got lots of resources for learning [JavaScript](https://code.visualstudio.com/docs/nodejs/working-with-javascript) and [Node.js](https://code.visualstudio.com/docs/nodejs/nodejs-tutorial).\n\n[Learn More](https://code.visualstudio.com/docs/nodejs/nodejs-tutorial)",
"walkthroughs.nodejsWelcome.learnMoreAboutJs.altText": "Learn more about JavaScript and Node.js in Visual Studio Code."
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface TypeScriptServiceConfiguration {
readonly useSyntaxServer: SyntaxServerConfiguration;
readonly webProjectWideIntellisenseEnabled: boolean;
readonly webProjectWideIntellisenseSuppressSemanticErrors: boolean;
readonly webExperimentalTypeAcquisition: boolean;
readonly enableDiagnosticsTelemetry: boolean;
readonly enableProjectDiagnostics: boolean;
readonly maxTsServerMemory: number;
Expand Down Expand Up @@ -145,6 +146,7 @@ export abstract class BaseServiceConfigurationProvider implements ServiceConfigu
useSyntaxServer: this.readUseSyntaxServer(configuration),
webProjectWideIntellisenseEnabled: this.readWebProjectWideIntellisenseEnable(configuration),
webProjectWideIntellisenseSuppressSemanticErrors: this.readWebProjectWideIntellisenseSuppressSemanticErrors(configuration),
webExperimentalTypeAcquisition: this.readWebExperimentalTypeAcquisition(configuration),
enableDiagnosticsTelemetry: this.readEnableDiagnosticsTelemetry(configuration),
enableProjectDiagnostics: this.readEnableProjectDiagnostics(configuration),
maxTsServerMemory: this.readMaxTsServerMemory(configuration),
Expand Down Expand Up @@ -175,6 +177,10 @@ export abstract class BaseServiceConfigurationProvider implements ServiceConfigu
return configuration.get<boolean>('typescript.disableAutomaticTypeAcquisition', false);
}

protected readWebExperimentalTypeAcquisition(configuration: vscode.WorkspaceConfiguration): boolean {
return configuration.get<boolean>('typescript.experimental.tsserver.web.typeAcquisition.enabled', false);
}

protected readLocale(configuration: vscode.WorkspaceConfiguration): string | null {
const value = configuration.get<string>('typescript.locale', 'auto');
return !value || value === 'auto' ? null : value;
Expand Down
20 changes: 15 additions & 5 deletions extensions/typescript-language-features/src/extension.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ import * as vscode from 'vscode';
import { Api, getExtensionApi } from './api';
import { CommandManager } from './commands/commandManager';
import { registerBaseCommands } from './commands/index';
import { TypeScriptServiceConfiguration } from './configuration/configuration';
import { BrowserServiceConfigurationProvider } from './configuration/configuration.browser';
import { ExperimentationTelemetryReporter, IExperimentationTelemetryReporter } from './experimentTelemetryReporter';
import { AutoInstallerFs } from './filesystems/autoInstallerFs';
import { MemFs } from './filesystems/memFs';
import { createLazyClientHost, lazilyActivateClient } from './lazyClientHost';
import { Logger } from './logging/logger';
import RemoteRepositories from './remoteRepositories.browser';
import { API } from './tsServer/api';
import { noopRequestCancellerFactory } from './tsServer/cancellation';
import { noopLogDirectoryProvider } from './tsServer/logDirectoryProvider';
import { PluginManager } from './tsServer/plugins';
import { WorkerServerProcessFactory } from './tsServer/serverProcess.browser';
import { ITypeScriptVersionProvider, TypeScriptVersion, TypeScriptVersionSource } from './tsServer/versionProvider';
import { ActiveJsTsEditorTracker } from './ui/activeJsTsEditorTracker';
import { TypeScriptServiceConfiguration } from './configuration/configuration';
import { BrowserServiceConfigurationProvider } from './configuration/configuration.browser';
import { Logger } from './logging/logger';
import { Disposable } from './utils/dispose';
import { getPackageInfo } from './utils/packageInfo';
import { isWebAndHasSharedArrayBuffers } from './utils/platform';
import { PluginManager } from './tsServer/plugins';
import { Disposable } from './utils/dispose';

class StaticVersionProvider implements ITypeScriptVersionProvider {

Expand Down Expand Up @@ -99,6 +101,14 @@ export async function activate(context: vscode.ExtensionContext): Promise<Api> {
context.subscriptions.push(lazilyActivateClient(lazyClientHost, pluginManager, activeJsTsEditorTracker, async () => {
await startPreloadWorkspaceContentsIfNeeded(context, logger);
}));
context.subscriptions.push(vscode.workspace.registerFileSystemProvider('vscode-global-typings', new MemFs(), {
isCaseSensitive: true,
isReadonly: false
}));
context.subscriptions.push(vscode.workspace.registerFileSystemProvider('vscode-node-modules', new AutoInstallerFs(), {
isCaseSensitive: true,
isReadonly: false
}));

return getExtensionApi(onCompletionAccepted.event, pluginManager);
}
Expand Down
Loading

0 comments on commit 45e2e0b

Please sign in to comment.