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 instructions for pointer compression through Electron #206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iamim
Copy link

@iamim iamim commented Oct 18, 2024

Following this issue I did some testing and found Electron to be the most reliable way of getting Node with pointer compression. So far, I only tested on the latest macOS but I don't see why it shouldn't work on other platforms.

Thank you for this awesome library!

@yioneko
Copy link
Owner

yioneko commented Oct 19, 2024

Nice addition. This inspires me to explore a way to directly use vscode as node runtime. I found that the official built vscode uses a internal version of node runtime as shown in its product.json:

{
  ...
  "checksumFailMoreInfoUrl": "https://go.microsoft.com/fwlink/?LinkId=828886",
  "electronRepository": "Microsoft/vscode-electron-prebuilt",
  "nodejsRepository": "Microsoft/vscode-node",
  "settingsSearchUrl": "https://bingsettingssearch.trafficmanager.net/api/Search",
  ...
}

The Microsoft/vscode-node repo is not publicly available and it probably contains several ms exclusive patches that specifically make optimizations to vscode and its extensions.

I tested on Linux and successfully found a way to use vscode as node runtime. It is very similar to the way you mentioned to use Electron. Just point the nodePath to the following script:

#!/bin/bash

VSCODE_PATH="/path/to/vscode_installation"
export ELECTRON_RUN_AS_NODE=1
exec "$VSCODE_PATH"/code "$@"

I have not done comprehensive tests on this, but I think this might be interesting for you and others who want identical ts development experience as in vscode.

@quang-dx
Copy link

quang-dx commented Dec 20, 2024

@yioneko Does this work on macOS? I set nodePath in /usr/local/bin/code, but it opens a VS Code instance instead of executing the code.
I also tried on Arch linux, my code path is usr/bin/code, I setup a script like your comment above

#!/bin/bash

VSCODE_PATH="/usr/bin"
export ELECTRON_RUN_AS_NODE=1
exec "$VSCODE_PATH"/code "$@"

but I also open VS Code instance with tsserver.js text file

@iamim
Copy link
Author

iamim commented Dec 20, 2024

@quang-dx make sure you have the env var export ELECTRON_RUN_AS_NODE=1.
I run it on macOS with VSCode as node nowadays.

@quang-dx
Copy link

quang-dx commented Dec 20, 2024

@quang-dx make sure you have the env var export ELECTRON_RUN_AS_NODE=1. I run it on macOS with VSCode as node nowadays.

Can you share your nodePath config on macos?
I tried

tsserver = {
    maxTsServerMemory = 4 * 1024,
    useSyntaxServer = 'auto',
    nodePath = '/Applications/Visual Studio Code.app/Contents/MacOS/Electron',
}

and start nvim with ELECTRON_RUN_AS_NODE=1 nvim . which should make sure ELECTRON_RUN_AS_NODE=1 is set. But electron process will crash shortly with log

[START][2024-12-20 20:15:07] LSP logging initiated
[WARN][2024-12-20 20:15:07] ...m/lsp/client.lua:871	"The language server eslint triggers a registerCapability handler for workspace/didChangeWorkspaceFolders despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2024-12-20 20:15:07] ...lsp/handlers.lua:560	"TSServer exited. Code: null. Signal: SIGTERM"
[ERROR][2024-12-20 20:15:07] ...lsp/handlers.lua:560	"TSServer exited. Code: 0. Signal: null"
[START][2024-12-20 20:15:48] LSP logging initiated
[WARN][2024-12-20 20:15:48] ...m/lsp/client.lua:871	"The language server eslint triggers a registerCapability handler for workspace/didChangeWorkspaceFolders despite dynamicRegistration set to false. Report upstream, this warning is harmless"
[ERROR][2024-12-20 20:15:48] ...lsp/handlers.lua:560	"TSServer exited. Code: null. Signal: SIGTERM"

@iamim
Copy link
Author

iamim commented Dec 23, 2024

@quang-dx hm, my setup is identical with the exception of useSyntaxServer.

I am not certain this is related. It seems like you get an exception from eslint which from my understanding should run as a separate LSP. Does it work with the default config when full node is used?

@AkisArou
Copy link

AkisArou commented Jan 1, 2025

@yioneko Does this work on macOS? I set nodePath in /usr/local/bin/code, but it opens a VS Code instance instead of executing the code. I also tried on Arch linux, my code path is usr/bin/code, I setup a script like your comment above

#!/bin/bash

VSCODE_PATH="/usr/bin"
export ELECTRON_RUN_AS_NODE=1
exec "$VSCODE_PATH"/code "$@"

but I also open VS Code instance with tsserver.js text file

On arch linux if you execute:
ELECTRON_RUN_AS_NODE=1 /usr/bin/code
it will open the vscode window.
but if you execute
ELECTRON_RUN_AS_NODE=1 /opt/visual-studio-code/code
it will indeed run as node.

Just point the nodePath to the script yioneko mentions like:

#!/bin/bash

VSCODE_PATH="/opt/visual-studio-code"
export ELECTRON_RUN_AS_NODE=1
exec "$VSCODE_PATH"/code "$@"

Can't help you for mac!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants