How do I enable Bash LSP in Neovim?

0
3
Asked By CuriousCoder42 On

I've been trying to learn Bash, and I thought it would be great to get some auto-completion while I code. I'm using lazy.nvim, which made setting up the LSP pretty straightforward. However, I can't seem to get auto-completion to work with the shebang line `#!/usr/bin/env bash`. Is there a way to fix this?

3 Answers

Answered By ScriptingSavvy On

I personally use bash-autocomplete and it's been great across multiple systems like Debian and Fedora. It helps with scripting, though if you're talking about automation, you'll want to ensure everything's properly set up on your end.

Answered By BashNinja01 On

I found it helpful to check out the start of my `lsp.lua` to ensure everything's linked correctly. It looks like this:

"neovim/nvim-lspconfig",
dependencies = {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
"L3MON4D3/LuaSnip",
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-path",
},

Make sure you've got all the necessary dependencies, as they might be affecting your setup.

Answered By TechWizard77 On

You should definitely try using the Bash Language Server in your Neovim setup with nvim-lspconfig. It even combines shellcheck and shfmt for linting and formatting your scripts on save. You can start with this simple configuration snippet:

```lua
{
"neovim/nvim-lspconfig",
config = function()
local util = require 'lspconfig.util'
local servers = {
bashls = {},
}
for server_name, config in pairs(servers) do
vim.lsp.config(server_name, config)
vim.lsp.enable(server_name)
end
end,
},
```

If you're looking for a quicker setup, consider using Kickstart for your configuration, especially if you're new. Just add bashls to your existing setup, and with mason, it'll handle the installation for you.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.