Skip to content

Instantly share code, notes, and snippets.

@da99
Last active April 21, 2024 05:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save da99/aa9911476c5238be4708b6e67f3e005f to your computer and use it in GitHub Desktop.
Save da99/aa9911476c5238be4708b6e67f3e005f to your computer and use it in GitHub Desktop.
Don't use BashLS with Neovim LSP. Use EFM-langserver + shellcheck
version: 2
root-markers:
- .git/
lint-debounce: 1s
tools:
sh-shellcheck: &sh-shellcheck
lint-command: 'shellcheck -f gcc -x'
lint-source: 'shellcheck'
lint-formats:
- '%f:%l:%c: %trror: %m'
- '%f:%l:%c: %tarning: %m'
- '%f:%l:%c: %tote: %m'
sh-shfmt: &sh-shfmt
format-command: 'shfmt -ci -s -bn'
format-stdin: true
languages:
sh:
- <<: *sh-shellcheck
- <<: *sh-shfmt
require "lspconfig".efm.setup {
init_options = {documentFormatting = true},
settings = {
rootMarkers = {".git/"},
}
}
# BashLS doesn't give you errors/warnings in your .sh files. So use EFM-langserver + shellcheck.
# EFM-langserver checks and lints for various languages. Shellcheck is a binary EFM-langserver
# uses for .sh files.
# Install GO (programming language) for your OS.
# Then use "go" to install the following:
# =============================================================================
# EFM-langserver:
# =============================================================================
if ! which shfmt ; then
go install mvdan.cc/sh/v3/cmd/shfmt@latest
fi
if ! which efm-langserver ; then
go install github.com/mattn/efm-langserver@latest
fi
if ! which gup ; then
go install github.com/nao1215/gup@latest
fi
gup update # Use this command to update all the binaries you just installed with 'go'.
# Put "config.yaml" (see above) in ~/.config/efm-langserver/
# Make sure you have nvim-lspconfig (https://github.com/neovim/nvim-lspconfig) installed.
# Add the Lua code above. Where it says "require lspconfig.efm.setup..."
# Be sure to get disable "require'lspconfig'.bashls.setup({})" if you have it in your init.lua file.
# You won't need it for efm-langserver since it replaces BashLS.
# For linux users:
# Run this to keep watching your lsp log file:
watch -n5 tail ~/.cache/nvim/lsp.log
# In Neovim: Open a .sh file. And do :LspInfo
# This will get you the location of your lsp.log file
# and other info. Combine this with the outout of lsp.log
# and this should be enough to fix any potential problems you have in getting all
# of this to work.
@lanej
Copy link

lanej commented Apr 21, 2024

🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment