Skip to content

tomatitito/stan-language-server

Repository files navigation

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 #include resolution and compilation

Editor-specific configuration

VSCode:

Install the extension from Marketplace or open-vsx.

Neovim

Mason

The Stan language server is installable with Mason by running :MasonInstall stan-language-server.

Manual install

The language server can also be configured manually by first installing the language server executable. This can be done directly via npm install -g stan-language-server-bin or by downloading the latest executable from GitHub and putting it somewhere in your PATH.

Neovim 0.11+ (built-in LSP)

Add lsp/stan_ls.lua to your Neovim config directory (e.g., ~/.config/nvim/):

return {
    cmd = { "stan-language-server", "--stdio" },
    filetypes = { "stan" },
    root_markers = { ".git" },
    settings = {
        maxLineLength = 78,
        includePaths = {},
    },
}

Then enable it:

vim.lsp.enable("stan_ls")

Older Neovim (with nvim-lspconfig)

local lspconfig = require("lspconfig")
local configs = require("lspconfig.configs")

configs.stan_ls = {
    default_config = {
        cmd = { "stan-language-server", "--stdio" },
        filetypes = { "stan" },
        root_dir = lspconfig.util.root_pattern(".git"),
        settings = {
            maxLineLength = 78,
            includePaths = {},
        },
    },
}

lspconfig.stan_ls.setup({})

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)

For emacs users, we recommend using mason.el to download from the same source as neovim above.

Assuming you are using stan-ts-mode, add the following to your init.el.

(use-package mason
  :config
  (mason-setup
    (dolist (pkg '("stan-language-server"))
      (unless (mason-installed-p pkg)
        (ignore-errors (mason-install pkg))))) )

(use-package eglot
  :hook (stan-ts-base-mode . eglot-ensure)
  :config
  (add-to-list 'eglot-server-programs '(stan-ts-base-mode
                                        . ("stan-language-server" "--stdio")))

For developers

Development uses bun

To install dependencies:

bun install

Building a binary executable:

bun build:binary

To run unit tests:

bun test

To run end-to-end tests:

bun test:e2e

About

Implementing the language server protocol for the Stan probabilistic programming language

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors