Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Yarn PnP Imports #2196

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/svelte-vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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`

Expand Down
8 changes: 7 additions & 1 deletion packages/svelte-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 17 additions & 4 deletions packages/svelte-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,35 @@ 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<number>('port') ?? -1;

const runtimeArgs = runtimeConfig.get<string[]>('runtime-args');
if (runtimeArgs !== undefined) {
runExecArgv.push(...runtimeArgs);
}

const debugArgs = ['--nolazy'];

const port = runtimeConfig.get<number>('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: {
module: serverModule,
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<string>('runtime');
Expand Down