stan-language-server
v0.3.1
Published
Language Server Protocol implementation for the Stan probabilistic programming language
Maintainers
Readme
stan-language-server
A language server for the Stan probabilistic programming language written in TypeScript and using Bun to build an executable binary.
Features
- Auto-completion: Keywords, functions, distributions, data types, and constraints
- Hover information: Documentation and type information
- Diagnostics: Real-time syntax and semantic error detection
- Code formatting: Using the official Stan compiler
- Include file support: Full
#includeresolution and compilation
Editor-specific configuration
VSCode:
Install the extension from Marketplace or open-vsx.
Neovim
There are many ways to install language servers in neovim. Here is one (if you have a different or better way, consider contributing it!):
Download the latest language server executable from GitHub and put it somewhere in your PATH. Then in your nvim config folder add lua/lsp/init.lua with:
local servers = {
stan_ls = "lsp.stan",
}
local function setup_server(name, config_module)
local config = require(config_module)
vim.api.nvim_create_autocmd("FileType", {
pattern = config.filetypes,
callback = function()
if #vim.lsp.get_clients({ bufnr = 0, name = name }) > 0 then
return
end
local root_dir = vim.fs.root(0, config.root_markers)
print(string.format("Starting %s for buffer %d with root: %s", name, vim.api.nvim_get_current_buf(),
root_dir or "none"))
vim.lsp.start({
name = name,
cmd = config.cmd,
root_dir = root_dir,
initialization_options = config.settings or {},
on_exit = function(code, signal)
print(string.format("%s exited with code %d, signal %d", name, code, signal))
end,
})
end,
})
end
for server_name, config_path in pairs(servers) do
setup_server(server_name, config_path)
endThen in lua/lsp/stan.lua add the following:
return {
cmd = { "stan-language-server", "--stdio" },
filetypes = { "stan" },
root_markers = { ".git" },
settings = {
maxLineLength = 78,
includePaths = {},
},
}Zed
Install the Stan extension.
Sublime Text 4
Using LSP for Sublime Text, download the latest release and add the following to the settings file:
{
"clients": {
"stan-lsp": {
"enabled": true,
"command": ["/YOUR/PATH/TO/stan-language-server", "--stdio"],
"selector": "source.stan | source.stanfunctions",
"initializationOptions": {},
"settings": {
"stan-language-server": { "includePaths": [], "maxLineLength": 78 }
}
}
}
Emacs (eglot)
Assuming you are using stan-ts-mode,
download the latest release
and add the following to your init.el:
; elgot is built in to emacs 29+, but a similar config would work for lsp-mode
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(stan-ts-mode . ("/YOUR/PATH/TO/stan-language-server" "--stdio"))))For developers
Development uses bun
To install dependencies:
bun installBuilding a binary executable:
bun build:binaryTo run unit tests:
bun testTo run end-to-end tests:
pip install pytest pytest-lsp
bun build:binary && pytest tests/