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

FR: Make available as LSP #936

Open
chrisgrieser opened this issue Dec 9, 2024 · 6 comments
Open

FR: Make available as LSP #936

chrisgrieser opened this issue Dec 9, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@chrisgrieser
Copy link

Many formatters/linters such as biome or ruff are also available as LSP, even though they aren't "real" language servers.

Offering an LSP, even if it is just for the formatting command, has its advantages, as it allows for easier integration into editors. With editors like nvim, for example, integrating stylua requires an extra plugin, while an LSP could be used out of the box.

@JohnnyMorganz
Copy link
Owner

Interesting idea. I can see the value in this, although building out a fully fledged language server that conforms to the protocol might be a bit overkill for the tool itself. Maybe it should be a wrapper binary tool, not sure yet.

@JohnnyMorganz JohnnyMorganz added the enhancement New feature or request label Dec 14, 2024
@titaniumtraveler
Copy link

Would using efm-langserver be an idea?
Maybe just provide an example config on how to set stylua up with it.

Implementing a full LSP wrapper for stylua seems a waste of energy when there already are tools that are explicitly made to wrap things like formatters to be available via LSP.

(Note I haven't used it, as I'm happy with how conform.nvim uses stylua, but the readme looks like efm should be easy enough too.)

Another consideration would be to have a common crate to provide an LSP wrapper, but I'm not sure how much that would actually be used.

@antonk52
Copy link

antonk52 commented Jan 8, 2025

As it is already pointed out biome is also written in rust and has a language client available as a subcommand of its CLI. The LS implementation can be checked out here for the inspiration or perhaps it is possible to reuse some of it.

Personally I think if the language client can be a part of the stylua binary itself - that would provide the best user experience and performance end to end.

Another options is to have a typescript/javascript language server as part of the existing npm package. It can shell out to the CLI similar to the VS Code plugin, perhaps some of the code can be reused. Though, the user will have to make sure that stylua is installed through the npm specifically.

@antonk52
Copy link

I've just published to npm a prototype that works good enough for me. It is quite similar code wise to the current vscode plugin. Hopefully this helps.

https://github.com/antonk52/lua-3p-language-servers

@chrisgrieser
Copy link
Author

chrisgrieser commented Jan 11, 2025

@antonk52 awesome! I just gave it a try, and so far it seems to be working as expected.

You should open a PR to have it added to nvim-lspconfig. Just found you already did: neovim/nvim-lspconfig#3553

I also opened a PR to have the package added to mason.nvim: mason-org/mason-registry#8532

@chrisgrieser
Copy link
Author

Any thoughts on integrating lua-3p-language-servers into stylua? With tolls like biome or ruff, the LSP can simply be called by passing an extra argument like cli --lsp. Shipping them together streamlines things, since right now, it's still nonetheless required to installed two things to make one thing work.

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

No branches or pull requests

4 participants