sublimelsp / lsp_utils

Module with LSP-related utilities for Sublime Text
https://sublimelsp.github.io/lsp_utils/
MIT License
13 stars 6 forks source link

Needs more documentation for end-users on where to define node_bin #53

Open rwols opened 3 years ago

rwols commented 3 years ago

A lot of npm-based packages have a ${node_bin} variable now but it's not clear to me how to customize that.

rchl commented 3 years ago

People don't explicitly install lsp_utils but just get it by proxy. So I'm not sure what would be a good place to educate the user.

Technically the user doesn't really need to customize it. Initially I wasn't even planning on having a setting for it. Only that it serves the purpose of helping the user if his PATH is not setup properly.

rchl commented 3 years ago

I suppose the solution to this is to just add a comment line like https://github.com/sublimelsp/LSP-json/blob/c99d736ff165e734e32ca7a07e0aac2b58c66cbd/LSP-json.sublime-settings#L2 to all packages that use "node_bin".

andy0130tw commented 10 months ago

I thought the Node.js path finding mechanism was a little bit obscured, especially when you were not using the system-provided Node binary or npm script. I gave up at the end and read the source code to figure out what happened. Ended up adding my own hack in the node_runtime.py: https://gist.github.com/andy0130tw/8377e7f7f4e36d1c231001271e166e24

rchl commented 10 months ago

Looks like you don't want to use Node from the PATH then and instead manually hardcode the path to Node in the command option in the helper package.

rchl commented 10 months ago

Actually I'm not sure how would that work in your case.

Also not sure what sort of solution would you see for that case. Everything really relies on node being in the PATH if you are not using bundled Node.

andy0130tw commented 10 months ago

Sorry for lack of clarity. Considering that Sublime Text is a GUI application, I think it is common for users within a desktop environment to launch it from their desktop e.g., application menu, instead of from the terminal. The way of configuring a PATH variable for an application is DE-dependent and generally not straightforward. The complexity is compounded in the case of lsp_utils because it also requires a working npm.

On the other hand, opting for a bundled Node "just works", but it means that a Node environment is duplicated, extra installation time involves, and one need to store all those language-server dependencies in some cache directory. In my assessment on average use cases, that should be considered the last resort.

As a result, I prefer that there is yet another way to specify the path to node/npm, even if it requires hardcoding them in the config.

rchl commented 10 months ago

If you intention is to use a single local node instance within whole of ST then you should be able to do that by exposing it in PATH. Here is how it should be configured on a system-basis - https://lsp.sublimetext.io/troubleshooting/#updating-the-path-used-by-lsp-servers

If you want to use different node instance per project then that's not really compatible with PATH approach as that is global for the whole application.

So is your intention to be able to configure node instance per-project?

andy0130tw commented 10 months ago

When you add it to the .profile, it also affects any other programs that are launched from your login session. I avoid doing that. And then I tried out the env: ... parameter method described in the docs for LSP-typescript. Despite of the fact that it showed up in the troubleshooting page, it seemed that the language server did not use the updated PATH.

// Settings in here override those in "LSP-typescript/LSP-typescript.sublime-settings"

{
    "initializationOptions": {
        "disableAutomaticTypingAcquisition": true,
        "locale": "zh-TW",
    },
    "enabled": true,
    "env": {
        "PATH": "/Users/qbane/.volta/bin:$PATH"
    }
}
rchl commented 10 months ago

env only applies for the started language server process. It doesn't affect pre-start of the server.

But my question was (out of curiosity, not promising anything) what would be a satisfactory solution for you.

andy0130tw commented 10 months ago

Well... I think a global setting is sufficient for me. Different type of language servers or projects may depend on different version of packages, but they can check and apply their own config after starting up.