diff --git a/packages/svelte-vscode/README.md b/packages/svelte-vscode/README.md index 7eb5f8768..94c28dfe9 100644 --- a/packages/svelte-vscode/README.md +++ b/packages/svelte-vscode/README.md @@ -64,6 +64,11 @@ This setting can only be changed in user settings for security reasons. You normally don't set this. Path to the language server executable. If you installed the `svelte-language-server` npm package, it's within there at `bin/server.js`. Path can be either relative to your workspace root or absolute. Set this only if you want to use a custom version of the language server. This will then also use the workspace version of TypeScript. This setting can only be changed in user settings for security reasons. +#### `svelte.language-server.runtime-args` + +You normally don't set this. Additional arguments to pass to Node when spawning the language server. +This is useful when you use something like Yarn PnP and need its loader arguments `["--loader", ".pnp.loader.mjs"]`. + ##### `svelte.language-server.port` You normally don't set this. At which port to spawn the language server. @@ -86,7 +91,7 @@ Settings to toggle specific features of the extension. The full list of all sett ### Usage with Yarn 2 PnP 1. Run `yarn add -D svelte-language-server` to install svelte-language-server as a dev dependency -2. Run `yarn dlx @yarnpkg/sdks vscode` to generate or update the VSCode/Yarn integration SDKs. This also sets the `svelte.language-server.ls-path` setting for the workspace, pointing it to the workspace-installed language server. Note that this requires workspace trust - else set the `svelte.language-server.ls-path` setting in your user configuration. +2. Run `yarn dlx @yarnpkg/sdks vscode` to generate or update the VSCode/Yarn integration SDKs. This also sets the `svelte.language-server.ls-path` and `svelte.language-server.runtime-args` setting for the workspace, pointing it to the workspace-installed language server. Note that this requires workspace trust - else set the `svelte.language-server.ls-path` and `svelte.language-server.runtime-args` setting in your user configuration. 3. Restart VSCode. 4. Commit the changes to `.yarn/sdks` diff --git a/packages/svelte-vscode/package.json b/packages/svelte-vscode/package.json index 7401e63bd..58bea4295 100644 --- a/packages/svelte-vscode/package.json +++ b/packages/svelte-vscode/package.json @@ -50,7 +50,8 @@ "supported": "limited", "restrictedConfigurations": [ "svelte.language-server.runtime", - "svelte.language-server.ls-path" + "svelte.language-server.ls-path", + "svelte.language-server.runtime-args" ], "description": "The extension requires workspace trust because it executes code specified by the workspace. Loading the user's node_modules and loading svelte config files is disabled when untrusted" } @@ -88,6 +89,11 @@ "title": "Language Server Path", "description": "- You normally don't set this - Path to the language server executable. If you installed the \"svelte-language-server\" npm package, it's within there at \"bin/server.js\". Path can be either relative to your workspace root or absolute. Set this only if you want to use a custom version of the language server. This will then also use the workspace version of TypeScript. This setting can only be changed in user settings for security reasons." }, + "svelte.language-server.runtime-args": { + "type": "array", + "title": "Language Server Runtime Args", + "description": "You normally don't set this. Additional arguments to pass to the node executable when spawning the language server. This is useful when you use something like Yarn PnP and need its loader arguments `[\"--loader\", \".pnp.loader.mjs\"]`." + }, "svelte.language-server.port": { "type": "number", "title": "Language Server Port", diff --git a/packages/svelte-vscode/src/extension.ts b/packages/svelte-vscode/src/extension.ts index dcea00d3b..41c607b6a 100644 --- a/packages/svelte-vscode/src/extension.ts +++ b/packages/svelte-vscode/src/extension.ts @@ -111,14 +111,23 @@ export function activateSvelteLanguageServer(context: ExtensionContext) { // Add --experimental-modules flag for people using node 12 < version < 12.17 // Remove this in mid 2022 and bump vs code minimum required version to 1.55 const runExecArgv: string[] = ['--experimental-modules']; - let port = runtimeConfig.get('port') ?? -1; + + const runtimeArgs = runtimeConfig.get('runtime-args'); + if (runtimeArgs !== undefined) { + runExecArgv.push(...runtimeArgs); + } + + const debugArgs = ['--nolazy']; + + const port = runtimeConfig.get('port') ?? -1; if (port < 0) { - port = 6009; + debugArgs.push('--inspect=6009'); } else { console.log('setting port to', port); runExecArgv.push(`--inspect=${port}`); } - const debugOptions = { execArgv: ['--nolazy', '--experimental-modules', `--inspect=${port}`] }; + + debugArgs.push(...runExecArgv); const serverOptions: ServerOptions = { run: { @@ -126,7 +135,11 @@ export function activateSvelteLanguageServer(context: ExtensionContext) { transport: TransportKind.ipc, options: { execArgv: runExecArgv } }, - debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions } + debug: { + module: serverModule, + transport: TransportKind.ipc, + options: { execArgv: debugArgs } + } }; const serverRuntime = runtimeConfig.get('runtime');