sassoftware / vscode-sas-extension

This SAS Extension for Visual Studio Code provides support for the SAS language, including features such as SAS syntax highlighting, code completion, hover help, code folding, outline, SAS code snippets and run SAS code.
https://sassoftware.github.io/vscode-sas-extension/
Apache License 2.0
120 stars 48 forks source link

Allow standalone LSP server usage #783

Open fsmunoz opened 9 months ago

fsmunoz commented 9 months ago

Is your feature request related to a problem? Please describe.

One of the goals of LSP was to separate the tooling around language support from the editor. Currently, the SAS LSP server included in the extension doesn't work due to a minimal detail around the behaviour of the ? operator when the variable doesn't exist.

Describe the solution you'd like

Compiling the vscode extension should result in an LSP command that can be used outside of vscode.

Describe alternatives you've considered

N/A

Additional context

Everything important already works, since the stdio option is there, and the build process (npm run compile) produces a usable LSP server in server/dist/node/server.js that can be run with node server/dist/node/server.js --stdio. The only nit is that currently the navigator variable is referenced as part of the locale detection code in a way that doesn't avoid a ReferenceError (which is correct as per the ECMAscript spec, although unexpected to me):

~/src/vscode-sas-extension$ node server/dist/node/server.js --stdio
(...)
ReferenceError: navigator is not defined
    at Object.<anonymous> (/home/frmuno/src/vscode-sas-extension/server/dist/node/server.js:96:1719)
(...)

I've made this minimal change in my fork that uses the ternary operator to go around the fact that ? doesn't avoid the ReferenceError. I can open a PR with it, but there is probably a more idiomatic way of doing it in TypeScript.

With that change, using the -stdio option makes the LSP server work for other editors, specifically here Emacs using emacs-lsp associated with SAS-mode:

image

The benefits are however not limited to this example, since I see no reason why it wouldn't work in vim/neovim/etc and thus be of help to a wider community without incurring any additional complexity.

Environment

Carus11 commented 9 months ago

This would be nice, I would like to use the lsp server in neovim.

scnwwu commented 9 months ago

Thank you for reporting. Your minimal change will only make en locale work. How about passing the locale to start the server? VSCODE_NLS_CONFIG='{"locale":"en"}' node ./server/dist/node/server.js --stdio

fsmunoz commented 9 months ago

Hi @scnwwu , thank you for your feedback!

I think that my change would work the same as it does currently: it would set the "en" the locale whenever there wasn't a VSCODE_NLS_CONFIG env variable, AND then if there wasn't a navigator.language defined - otherwise it would pick the former than the latter.

That said, your suggestion works perfectly for me and doesn't require any change, so it's perfectly fine. It will break by default (instead of defaulting to "en") but since there is a way to go around it's ok.

I think that a very small update to the README to mention this possibility (and the necessity of setting the env variable) could be useful to make others aware, this is a great feature.