Skip to content

Instantly share code, notes, and snippets.

@andy0130tw
Last active September 9, 2025 14:24
Show Gist options
  • Save andy0130tw/1a80f550d7a8c8e7c0801ff3a3091a8b to your computer and use it in GitHub Desktop.
Save andy0130tw/1a80f550d7a8c8e7c0801ff3a3091a8b to your computer and use it in GitHub Desktop.

A trick to save Node-based LSP memory usage in Node: Use Electron V8 to execute vtsls/eslint/...

Ref: https://www.electronjs.org/blog/v8-memory-cage

Ensure VS Code is installed. Wrap it as a Node executable:

echo > ~/.local/bin/node-electron <<<EOF
#!/bin/bash
export ELECTRON_RUN_AS_NODE=1
exec "/Applications/Visual Studio Code.app/Contents/MacOS/Electron" "$@"
EOF

Intercept node with:

cat > ~/.local/zed-bin/node <<<EOF

#!/bin/bash

NODE_BIN=$HOME/.volta/bin/node

# If there are at least 3 arguments and the 3rd contains "eslintServer.js"
if [[ $# -ge 2 && "$2" == *"eslintServer.js"* ]]; then
  # Run your custom command
  exec ~/.local/bin/node-electron --max-old-space-size=1536 "$2" --stdio
else
  exec "$NODE_BIN" "$@"
fi
EOF

Link npm into this bin directory:

ln -s ~/.volta/bin/npm ~/.local/zed-bin/npm

In Zed, point node.path to our wrapper script:

{
  "node": {
    "path": "/Users/qbane/.local/zed-bin/node"
  }, ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment