Installation

Cargo

cargo install bazel-language-server

Nix

nix run github:barrettruth/bazel-language-server

From source

git clone https://github.com/barrettruth/bazel-language-server.git
cd bazel-language-server
cargo install --path .

Editor setup

Neovim

Using the built-in LSP client directly:

vim.lsp.config('bazel_ls', {
  cmd = { 'bazel-language-server' },
  filetypes = { 'bzl' },
  root_markers = { 'MODULE.bazel', 'WORKSPACE', 'WORKSPACE.bazel', '.git' },
  workspace_required = false,
})

vim.lsp.enable('bazel_ls')

The workspace root is taken from workspaceFolders, falling back to rootUri, rootPath, and then the working directory. Whichever one answered is logged at startup on stderr.

Bazel

Bazel is optional. The target index is parsed from BUILD files, so the server starts and answers with no Bazel on PATH. To check what the Bazel subsystem makes of a workspace:

bazel-language-server doctor path/to/workspace