Now available: a Stan Language Server

The Language Server Protocol is a way for different editors to all share certain abilities when it comes to ‘understanding’ a programming language, like autocomplete or the classic red squiggles under the errors.

Building a language server for Stan has been a wishlist item for many for quite some time, and I’m happy to share that thanks to efforts by Jens Kouros, one is now available!

The features will be largely familiar to existing users of my VSCode Stan plugin (which now uses the language server internally): autocompletion of Stan functions, hover documentation, formatting, and warning/error diagnostics on the fly.

The README there has instructions for configuring your favorite editor (if your favorite editor supports LSP but isn’t in our readme, please let us know how to set it up!).

You can now get a high-quality Stan experience across editors. Enjoy!

Sublime text:

Emacs:

VSCode:

21 Likes

This looks great!

Hello everyone and thanks @WardBrian for making this announcement! I am very excited that we have the first release of the stan language server out!

In addition to what has already been said I would like to encourage everyone to let us know if you have feature requests. We have made sure that the language server is up to par with the VS Code extension, but the plan is to add more functionality step by step, like for instance a “Go to Definition” feature. So if you have anything, just open an issue in the github repo!

8 Likes

I tried Stan language server in Emacs following the github instructions and I got an error

[eglot] (warning) Server tried to register unsupported capability `workspace/didChangeConfiguration’

Language server for R runs ok for me.

Any ideas how to fix this?

That warning should be fixed by Fix dynamic registration for configuration change notification requests by tomatitito · Pull Request #71 · tomatitito/stan-language-server · GitHub (will be in the next release).

Does it prevent you from getting over features like Eldoc?

Wow so cool, thanks for all your hard work!

I just released version 0.3.0 of the stan-language-server. @saudiwin The problem should be fixed now.

2 Likes

Is this available for RStudio?

1 Like

I am not aware of any way to use a language server inside RStudio. If you use Positron, you should be able to use the same extension as VSCode if you install it from open-vsx Open VSX Registry

2 Likes

Fantastic! Really excited to see this, as a Neovim user.

Is there any chance that it might be added to the Mason LSP registry? That seems to be the most well-known way to get LSPs into Neovim these days and keeping them up to date, especially as the LazyVim ecosystem uses Mason and is becoming overwhelmingly popular.

I don’t know much about LSPs beyond using them, but it looks like it’s a relatively simple process via a pull request: GitHub - mason-org/mason-registry: Core registry for mason.nvim.

EDIT: I should say: I’ll have a play today to see if I can work out what the definition file for Mason would look like. If I run into problems, I’ll report my failure here. :)

2 Likes

I think we’d be happy if it ended up in more easy-to-access places, but it would probably be better if a hardcore neovim user was the one who put it there. We’d also be happy to update how our readme recommends neovim users install things

1 Like

I’ll have a play.

Hey @josswright , unfortunately I don’t know anything about mason and how it works. But if you can tell me how to set the language server up with mason, then I’ll be happy to put that in the README. Or you could open a PR and put it there yourself. However, I stumbled upon GitHub - neovim/nvim-lspconfig: Quickstart configs for Nvim LSP which I have been told is “the way to go”. Have you heard about that? (The stan-language-server is not yet available via nvim-lspconfig, but I would try to get it in there…)

This is what I get for sticking my head above the parapet!

The Neovim packaging ecosystem is evolving quite rapidly at the moment, and I wouldn’t want to pretend that I’m an expert. I just spent a couple of weeks recently migrating an ancient, encrusted, decades-old ‘classic’ vim configuration into the newer lua-based Neovim system, and took the opportunity to get up to speed with some of the latest features that seemed useful. LSP support was probably the main new feature that was a real upgrade for me. (Despite the fact that I then had to argue with the R LSP because the tidyverse and I don’t quite see eye-to-eye on how to format code…)

nvim-lspconfig is a package that provides configurations for different LSPs. Mason is a package manager for Neovim that seems to be the most common way to install LSPs and keep them up to date. It has a fairly extensive list of supported LSPs, and a sub-package, mason-lspconfigthat handles enabling installed LSPs for the nvim-lspconfigplugin. (The extra convenience here is that if you copy your Neovim configuration to a new machine, when you open it up then it will automatically download, install, and configure all the LSPs you’ve specified in your configuration.)

So, if my understanding of all this is right:

  • Neovim includes an LSP client.
  • Mason is what you use to install and update LSPs to avoid doing it all manually.
  • nvim-lspconfigis what you use to have configurations for all your LSPs automatically available.
  • mason-lspconfig is used to tell nvim-lspconfigabout LSPs installed via Mason, and enable them automatically as required.

(I think!)

Despite that all sounding quite complicated, my understanding is that a creating a config to go into nvim-lspconfig isn’t too hard, and adding an LSP to Mason’s list is apparently a fairly short .yaml file. I’ve never done any of that before, though, so I could be wildly underestimating it.

I will say that, even though there’s quite a flurry of developments and packages at the moment, all of the ones I’ve listed here seem to be quite core elements of the way things are now done, so I’m not worried that anything I’ve said here is likely to change fundamentally in the near future.

I very much want to have the Stan LSP working in my config, though, so I’ve got every incentive to work all this out. If I can get everything together, I’ll happily report back and submit the appropriate PRs to Mason/nvim-lspconfig and write some updated install documentation for the github page.

2 Likes

Just to make this a bit more concrete: having set up the rest of the config appropriately, I just have a $HOME/.config/nvim/lua/plugins/lsp/mason-lspconfig.luafile like this:

return {
  "mason-org/mason-lspconfig.nvim",
  dependencies = {
    { "mason-org/mason.nvim", opts = {} },
    "neovim/nvim-lspconfig",
  },
  opts = {
    ensure_installed = {
      "r_language_server", -- R
      "julials",           -- Julia
      "lua_ls",            -- Lua
      "marksman"           -- Markdown
    },
    automatic_installation = true,
  },
}

… and all of those LSPs are automatically installed, configured, and enabled for appropriate filetypes.

Just added to my nvim config, looks great! Thanks for your hard work

Hey @miles could you tell me what exactly you added to your config? ;-)

1 Like

As a fellow neovim user, would be amazing to see this in Mason. One thing to note is they do have some minimum requirements to get something added to the registry:

At least one of the following conditions MUST be fulfilled for new packages to be added to the registry.

1. At least 100 stars on GitHub.
2. At least 5000 VSCode marketplace downloads.
3. Be approved at [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).
4. Have a credible authority vouch for it, e.g., the tool is officially recommended by maintainers of the language.

So getting something working with nvim-lspconfig should be enough to add a quick config to Mason and get it in there.

2 Likes

I’d think that we meet this criteria as well, but since an lspconfig is also necessary for nvim users, might as well go that route

1 Like