bash-lsp/bash-language-server

TypeScript

A language server for Bash

language-serverbash
Star Growth
Stars
2.8k
Forks
154
Weekly Growth
+0
Issues
118
1k2k
Feb 2018Dec 2020Oct 2023Sep 2026
Artifactsnpm
README

Bash Language Server

Bash language server that brings an IDE-like experience for bash scripts to most editors. This is based on the Tree Sitter parser and supports explainshell, shellcheck and shfmt.

Documentation around configuration variables can be found in the config.ts file.

Features

  • Jump to declaration
  • Find references
  • Code Outline & Show Symbols
  • Highlight occurrences
  • Code completion
  • Simple diagnostics reporting
  • Documentation for symbols on hover
  • Workspace symbols
  • Rename symbol
  • Format document

To be implemented:

  • Better jump to declaration and find references based on scope

Installation

Dependencies

As a dependency, we recommend that you first install shellcheck to enable linting: https://github.com/koalaman/shellcheck#installing . If shellcheck is installed, bash-language-server will automatically call it to provide linting and code analysis each time the file is updated (with debounce time of 500ms).

If you want your shell scripts to be formatted consistently, you can install shfmt. If shfmt is installed then your documents will be formatted whenever you take the 'format document' action. In most editors this can be configured to happen automatically when files are saved.

Bash language server

Usually you want to install a client for your editor (see the section below).

But if you want to install the server binary (for examples for editors, like helix, where a generic LSP client is built in), you can install from npm registry as:

npm i -g bash-language-server

Alternatively, bash-language-server may also be distributed directly by your Linux distro, for example on Fedora based distros:

dnf install -y nodejs-bash-language-server

Or on Ubuntu with snap:

sudo snap install bash-language-server --classic

To verify that everything is working:

bash-language-server --help

If you encounter installation errors, ensure you have node version 20 or newer (node --version).

Clients

The following editors and IDEs have available clients:

Vim

For Vim 8 or later install the plugin prabirshrestha/vim-lsp and add the following configuration to .vimrc:

if executable('bash-language-server')
  au User lsp_setup call lsp#register_server({
        \ 'name': 'bash-language-server',
        \ 'cmd': {server_info->['bash-language-server', 'start']},
        \ 'allowlist': ['sh', 'bash'],
        \ })
endif

For Vim 8 or Neovim using YouCompleteMe, add the following to .vimrc:

let g:ycm_language_server =
            \ [
            \   {
            \       'name': 'bash',
            \       'cmdline': [ 'bash-language-server', 'start' ],
            \       'filetypes': [ 'sh' ],
            \   }
            \ ]

For Vim 8 or Neovim using neoclide/coc.nvim, according to it's Wiki article, add the following to your coc-settings.json:

  "languageserver": {
    "bash": {
      "command": "bash-language-server",
      "args": ["start"],
      "filetypes": ["sh"],
      "ignoredRootPaths": ["~"]
    }
  }

For Vim 8 or NeoVim using dense-analysis/ale add the following configuration to your .vimrc:

let g:ale_linters = {
    \ 'sh': ['language_server'],
    \ }

For Vim8/NeoVim v0.5 using jayli/vim-easycomplete. Execute :InstallLspServer sh and config nothing. Maybe it's the easiest way to use bash-language-server in vim/nvim.

Neovim

For Neovim 0.11+ with nvim-lspconfig

vim.lsp.enable 'bashls'

For Neovim 0.11+ without plugins

vim.lsp.config.bashls = {
  cmd = { 'bash-language-server', 'start' },
  filetypes = { 'bash', 'sh' }
}
vim.lsp.enable 'bashls'

For Neovim 0.10 or lower with nvim-lspconfig

require 'lspconfig'.bashls.setup {}

Oni

On the config file (File -> Preferences -> Edit Oni config) add the following configuration:

"language.bash.languageServer.command": "bash-language-server",
"language.bash.languageServer.arguments": ["start"],

Emacs

Lsp-mode has a built-in client, can be installed by use-package. Add the configuration to your .emacs.d/init.el

(use-package lsp-mode
  :commands lsp
  :hook
  (sh-mode . lsp))

Using the built-in eglot lsp mode:

(use-package eglot
  :config
  (add-to-list 'eglot-server-programs '((sh-mode bash-ts-mode) . ("bash-language-server" "start")))

  :hook
  (sh-mode . eglot-ensure)
  (bash-ts-mode . eglot-ensure))

shfmt integration

The indentation used by shfmt is whatever has been configured for the current editor session, so there is no shfmt-specific configuration variable for this. If your editor is configured for two-space indents then that's what it will use. If you're using tabs for indentation then shfmt will use that.

The shfmt integration also supports configuration via .editorconfig. If any shfmt-specific configuration properties are found in .editorconfig then the config in .editorconfig will be used and the language server config will be ignored. This follows shfmt's approach of using either .editorconfig or command line flags, but not both. Note that only shfmt-specific configuration properties are read from .editorconfig - indentation preferences are still provided by the editor, so to format using the indentation specified in .editorconfig make sure your editor is also configured to read .editorconfig. It is possible to disable .editorconfig support and always use the language server config by setting the "Ignore Editorconfig" configuration variable.

Logging

The minimum logging level for the server can be adjusted using the BASH_IDE_LOG_LEVEL environment variable and through the general workspace configuration.

Development Guide

Please see docs/development-guide for more information.

Related repositories
oraios/serena

A powerful MCP toolkit for coding, providing semantic retrieval and editing capabilities - the IDE for your agent

PythonPyPIMIT Licenseagentai
oraios.github.io/serena
29k2k
neovim/nvim-lspconfig

Quickstart configs for Nvim LSP

LuaApache License 2.0vimnvim
13.9k2.5k
a-h/templ

A language for writing HTML user interfaces in Go.

GoGo ModulesMIT Licensetemplating-languageside-support
templ.guide
10.5k366
facebook/pyrefly

A fast type checker and language server for Python

Rustcrates.ioMIT Licensecode-qualityide
pyrefly.org
6.9k512
zigtools/zls

A language server for Zig supporting developers with features like autocomplete and goto definition

ZigMIT Licensezigzls
zigtools.org/zls/install/
5.1k446
LuaLS/lua-language-server

A language server that offers Lua language support - programmed in Lua

LuaMIT Licenselualanguage-server
luals.github.io
4.4k440
Myriad-Dreamin/tinymist

Tinymist [ˈtaɪni mɪst] is an integrated language service for Typst [taɪpst].

Rustcrates.ioApache License 2.0formatterlsp
myriad-dreamin.github.io/tinymist
3.5k183
artempyanykh/marksman

Write Markdown with code assist and intelligence in the comfort of your favourite editor.

F#MIT Licensemarkdownnotes
3.3k72
mtshiba/pylyzer

A fast, feature-rich static code analyzer & language server for Python

Rustcrates.ioMIT Licenselanguage-serverpython
mtshiba.github.io/pylyzer/
2.9k42
typescript-language-server/typescript-language-server

Unofficial TypeScript & JavaScript Language Server

TypeScriptnpmOthertypescriptlanguage-server
npmjs.com/package/typescript-language-server
2.6k187
scalameta/metals

Scala language server with rich IDE features 🚀

ScalaApache License 2.0lspscalameta
scalameta.org/metals/
2.3k439
redhat-developer/vscode-java

Java Language Support for Visual Studio Code

TypeScriptnpmEclipse Public License 2.0javalanguage-server
2.3k543