-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
Conversation
@@ -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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
if (this.configuration.localNodePath) { | ||
if (this.useWorkspaceNodeSetting === undefined) { | ||
setImmediate(() => { | ||
this.promptAndSetWorkspaceNode(); | ||
}); | ||
} | ||
else if (this.useWorkspaceNodeSetting) { | ||
this._currentVersion = this.configuration.localNodePath; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
||
const allow = vscode.l10n.t("Allow"); | ||
const dismiss = vscode.l10n.t("Dismiss"); | ||
const neverAllow = vscode.l10n.t("Never in this workspace"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)'], { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
@mjbvz updates on this? |
When trying to use this the TSServer instantly crashes with no log, I suspect a permission error maybe? Any idea ? @gabritto
|
Was the node path |
@Titozzz Can you open an issue about this so we can keep track of it? Thanks! |
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? |
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.