- Notifications
You must be signed in to change notification settings - Fork134
bash-lsp/bash-language-server
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Bash language server that brings an IDE-like experience for bash scripts to most editors. This is based on theTree Sitter parser and supportsexplainshell,shellcheck andshfmt.
Documentation around configuration variables can be found in theconfig.ts file.
- 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
As a dependency, we recommend that you first installshellcheck to enable linting:https://github.com/koalaman/shellcheck#installing . Ifshellcheck
is installed,bash-language-server will automatically call it to provide linting and code analysis each time thefile is updated (with debounce time of 500ms).
If you want your shell scripts to be formatted consistently, you can installshfmt. Ifshfmt
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.
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 16 or newer (node --version
).
The following editors and IDEs have available clients:
- Atom (ide-bash)
- Eclipse (ShellWax)
- Emacs (see below)
- Helix (built-in support)
- JupyterLab (jupyterlab-lsp)
- Neovim (see below)
- Sublime Text (LSP-bash)
- Vim (see below)
- Visual Studio Code (Bash IDE)
- Oni (see below)
For Vim 8 or later install the pluginprabirshrestha/vim-lsp and add the following configuration to.vimrc
:
ifexecutable('bash-language-server')auUserlsp_setupcalllsp#register_server({\'name':'bash-language-server',\'cmd': {server_info->['bash-language-server','start']},\'allowlist': ['sh','bash'],\})endif
For Vim 8 or Neovim usingYouCompleteMe, add the following to.vimrc
:
letg:ycm_language_server=\[\ {\'name':'bash',\'cmdline': ['bash-language-server','start' ],\'filetypes': ['sh' ],\ }\]
For Vim 8 or Neovim usingneoclide/coc.nvim, according toit's Wiki article, add the following to yourcoc-settings.json
:
"languageserver": {"bash": {"command":"bash-language-server","args": ["start"],"filetypes": ["sh"],"ignoredRootPaths": ["~"] } }
For Vim 8 or NeoVim usingdense-analysis/ale add the followingconfiguration to your.vimrc
:
letg:ale_linters= {\'sh': ['language_server'],\}
For Vim8/NeoVim v0.5 usingjayli/vim-easycomplete. Execute:InstallLspServer sh
and config nothing. Maybe it's the easiest way to use bash-language-server in vim/nvim.
For Neovim 0.11+ withnvim-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 withnvim-lspconfig
require'lspconfig'.bashls.setup {}
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"],
Lsp-mode has a built-in client, can be installed byuse-package
.Add the configuration to your.emacs.d/init.el
(use-package lsp-mode:commands lsp:hook (sh-mode. lsp))
Using the built-ineglot
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))
The indentation used byshfmt
is whatever has been configured for the current editor session, sothere is noshfmt
-specific configuration variable for this. If your editor is configured fortwo-space indents then that's what it will use. If you're using tabs for indentation thenshfmt
will use that.
Theshfmt
integration also supports configuration via.editorconfig
. If anyshfmt
-specificconfiguration properties are found in.editorconfig
then the config in.editorconfig
will beused and the language server config will be ignored. This followsshfmt
's approach of using either.editorconfig
or command line flags, but not both. Note that onlyshfmt
-specific configurationproperties 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 alsoconfigured to read.editorconfig
. It is possible to disable.editorconfig
support and always usethe language server config by setting the "Ignore Editorconfig" configuration variable.
The minimum logging level for the server can be adjusted using theBASH_IDE_LOG_LEVEL
environment variableand through the generalworkspace configuration.
Please seedocs/development-guide for more information.
About
A language server for Bash
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.