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

Add custom Node option to run TS Server #191019

Merged
merged 12 commits into from
Sep 6, 2023
Merged

Add custom Node option to run TS Server #191019

merged 12 commits into from
Sep 6, 2023

Conversation

gabritto
Copy link
Member

@gabritto gabritto commented Aug 22, 2023

Fixes #151245.
Fixes #172719.

This PR creates a new setting that is a path to a Node installation that should be used to run TS Server. This allows users of desktop VSCode to run TS Server with a Node version that doesn't have a hard memory limit at 4GB, unlike the bundled version of Node. The custom memory limit can be set through the existing "Max TS Server Memory" setting.

@gabritto gabritto marked this pull request as ready for review August 22, 2023 20:46
@@ -173,6 +175,11 @@ export default class TypeScriptServiceClient extends Disposable implements IType
this.restartTsServer();
}));

this._nodeVersionManager = this._register(new NodeVersionManager(this._configuration, context.workspaceState));
this._register(this._nodeVersionManager.onDidPickNewVersion(() => {
this.restartTsServer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that it didn't turn out to be possible to block startup on the user accepting the setting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out how to do it easily, no. But in any case, the node path setting can change at some point, so we need the code above, I think.

Comment on lines 25 to 33
if (this.configuration.localNodePath) {
if (this.useWorkspaceNodeSetting === undefined) {
setImmediate(() => {
this.promptAndSetWorkspaceNode();
});
}
else if (this.useWorkspaceNodeSetting) {
this._currentVersion = this.configuration.localNodePath;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks the same as the code in the block below; probably could be pulled out into a method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're the same except the version below uses this.updateActiveVersion instead of assigning directly as in this._currentVersion = this.configuration.localNodePath (which is kinda special because we're initializing the class at that point), so didn't seem worth it to extract into a method with an option

const useWorkspaceNodeStorageKey = 'typescript.useWorkspaceNode';

export class NodeVersionManager extends Disposable {
private _currentVersion: string | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the "version" moniker is left over from copying the tsdk code? Was confused as to whether or not this was checking versions or something until I realized that this was acutally managing the node path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, do you think simply NodeManager would be better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining NodePathManager and _currentPath, but I also haven't gone to look for examples that would indicate what's canonical to this repo's style.

@mjbvz mjbvz added this to the August 2023 milestone Aug 23, 2023

const allow = vscode.l10n.t("Allow");
const dismiss = vscode.l10n.t("Dismiss");
const neverAllow = vscode.l10n.t("Never in this workspace");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the user selects never, is there a way for them still opt in later on?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to remember the prompt answer for a specific node path. So if you change the workspace node path to point to a different path, the prompt will show up again. However, it's a bit contrived to do that if you select "never" by accident. Should I add a command to use the workspace node path?


private findNodePath(): string | null {
try {
const out = child_process.execFileSync('node', ['-e', 'console.log(process.execPath)'], {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context: I tried doing the node detection using which, like other language extensions do, but it does not work if you have a node version manager like volta, because if you do, your path points to volta's node.exe wrapper, and if you use that to run TS Server, it crashes.
This alternative approach was suggested by @jakebailey.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to not do this for all paths?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean for all paths?

@gabritto
Copy link
Member Author

@mjbvz updates on this?

@mjbvz mjbvz modified the milestones: August 2023, September 2023 Aug 29, 2023
@mjbvz mjbvz enabled auto-merge (squash) September 6, 2023 19:07
@mjbvz mjbvz merged commit efc1b30 into microsoft:main Sep 6, 2023
5 checks passed
@Titozzz
Copy link
Contributor

Titozzz commented Sep 19, 2023

When trying to use this the TSServer instantly crashes with no log, I suspect a permission error maybe? Any idea ? @gabritto

2023-09-19 11:22:46.128 [error] TSServer exited. Code: 1. Signal: null
2023-09-19 11:22:46.128 [info] TSServer log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-EvKNgY/tsserver.log undefined
2023-09-19 11:22:46.128 [info] Starting TS Server undefined
2023-09-19 11:22:46.128 [info] Using tsserver from: /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js undefined
2023-09-19 11:22:46.128 [info] Using Node installation from /usr/local/bin/node to run TS Server undefined
2023-09-19 11:22:46.128 [info] <syntax> Log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-0QawBe/tsserver.log
2023-09-19 11:22:46.128 [info] <syntax> Forking...
2023-09-19 11:22:46.129 [info] <syntax> Starting...
2023-09-19 11:22:46.129 [info] <semantic> Log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-Vvnhnw/tsserver.log
2023-09-19 11:22:46.129 [info] <semantic> Forking...
2023-09-19 11:22:46.129 [info] <semantic> Starting...
2023-09-19 11:22:46.164 [error] TSServer exited. Code: 1. Signal: null
2023-09-19 11:22:46.164 [info] TSServer log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-Vvnhnw/tsserver.log undefined
2023-09-19 11:22:46.164 [info] Starting TS Server undefined
2023-09-19 11:22:46.164 [info] Using tsserver from: /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js undefined
2023-09-19 11:22:46.164 [info] Using Node installation from /usr/local/bin/node to run TS Server undefined
2023-09-19 11:22:46.164 [info] <syntax> Log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-OKk9z9/tsserver.log

@gabritto
Copy link
Member Author

gabritto commented Sep 19, 2023

When trying to use this the TSServer instantly crashes with no log, I suspect a permission error maybe? Any idea ? @gabritto

2023-09-19 11:22:46.128 [error] TSServer exited. Code: 1. Signal: null
2023-09-19 11:22:46.128 [info] TSServer log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-EvKNgY/tsserver.log undefined
2023-09-19 11:22:46.128 [info] Starting TS Server undefined
2023-09-19 11:22:46.128 [info] Using tsserver from: /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js undefined
2023-09-19 11:22:46.128 [info] Using Node installation from /usr/local/bin/node to run TS Server undefined
2023-09-19 11:22:46.128 [info] <syntax> Log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-0QawBe/tsserver.log
2023-09-19 11:22:46.128 [info] <syntax> Forking...
2023-09-19 11:22:46.129 [info] <syntax> Starting...
2023-09-19 11:22:46.129 [info] <semantic> Log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-Vvnhnw/tsserver.log
2023-09-19 11:22:46.129 [info] <semantic> Forking...
2023-09-19 11:22:46.129 [info] <semantic> Starting...
2023-09-19 11:22:46.164 [error] TSServer exited. Code: 1. Signal: null
2023-09-19 11:22:46.164 [info] TSServer log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-Vvnhnw/tsserver.log undefined
2023-09-19 11:22:46.164 [info] Starting TS Server undefined
2023-09-19 11:22:46.164 [info] Using tsserver from: /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js undefined
2023-09-19 11:22:46.164 [info] Using Node installation from /usr/local/bin/node to run TS Server undefined
2023-09-19 11:22:46.164 [info] <syntax> Log file: /Users/thibault/Library/Application Support/Code - Insiders/logs/20230919T112235/window1/exthost/vscode.typescript-language-features/tsserver-log-OKk9z9/tsserver.log

Was the node path /usr/local/bin/node detected by vscode or provided by you?
Also, are you using any node manager? What version of Node are you using?

@gabritto
Copy link
Member Author

@Titozzz Can you open an issue about this so we can keep track of it? Thanks!

@Titozzz
Copy link
Contributor

Titozzz commented Sep 20, 2023

I tried using "node" and "/usr/local/bin/node", and "bun" out of curiosity.

I do use n to manage my node versions

@gabritto
Copy link
Member Author

I tried using "node" and "/usr/local/bin/node", and "bun" out of curiosity.

I do use n to manage my node versions

And did TSServer crash with both "node" and "/usr/local/bin/node"? Do you know what version of Node was being used when the crash happened?

@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants