Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(nvim): add vim-plug example #117

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Helm-ls is a [helm](https://github.com/helm/helm) language server protocol [LSP]
- [Default Configuration](#default-configuration)
- [Editor Config examples](#editor-config-examples)
- [Neovim](#neovim)
- [Vim Helm Plugin](#vim-helm-plugin)
- [Filetype detection](#filetype-detection)
- [nvim-lspconfig setup](#nvim-lspconfig-setup)
- [coc.nvim setup](#cocnvim-setup)
- [VSCode](#vscode)
Expand Down Expand Up @@ -215,12 +215,19 @@ settings = {

### Neovim

#### Vim Helm Plugin
#### Filetype detection

To get filetype detection working, you'll need the [vim-helm](https://github.com/towolf/vim-helm) plugin installed before using helm_ls, to install it using vim-plug (or use your preferred plugin manager):
To get filetype detection working, you can use one of the folowing plugins:

- [helm-ls.nvim](https://github.com/qvalentin/helm-ls.nvim): recommended, but requires you to use [tree-sitter](https://github.com/ngalaiko/tree-sitter-go-template?tab=readme-ov-file#neovim-integration-using-nvim-treesitter) for syntax highlighting. Also provides some additional features.
- [vim-helm](https://github.com/towolf/vim-helm): known to cause problems with yaml-language-server when used with another plugin manger than lazy

install it using lazy (or use your preferred plugin manager):

```lua
Plug 'towolf/vim-helm'
{ "qvalentin/helm-ls.nvim", ft = "helm" }
-- or { "towolf/vim-helm", ft = "helm" },
-- or even both
```

#### nvim-lspconfig setup
Expand All @@ -242,11 +249,13 @@ lspconfig.helm_ls.setup {
```

See [examples/nvim/init.lua](https://github.com/mrjosh/helm-ls/blob/master/examples/nvim/init.lua) for an
complete example, which also includes yaml-language-server.
complete example using lazy, or [examples/nvim/init.lua](https://github.com/mrjosh/helm-ls/blob/master/examples/vim-plug/init.lua) for vim-plug.
The examples also include the setup for yaml-language-server.

> [!TIP]
>
> If you are using [AstroNvim](https://github.com/AstroNvim/AstroNvim) you can just install the [astrocommunity](https://github.com/AstroNvim/astrocommunity) helm pack.
> If you are using [AstroNvim](https://github.com/AstroNvim/AstroNvim) you can just install the [astrocommunity](https://github.com/AstroNvim/astrocommunity) helm pack
> or if using [LazyVim](https://github.com/LazyVim/LazyVim) its [LazyVimHelm](https://github.com/LazyVim/LazyVim) plugin.

#### coc.nvim setup

Expand Down
69 changes: 34 additions & 35 deletions examples/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- a minimal example config for setting up neovim with helm-ls and yamlls
-- test it with: nvim -u init.lua

-- setup lazy plugin manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
Expand All @@ -14,70 +15,68 @@ if not vim.loop.fs_stat(lazypath) then
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " "
-- end of lazy setup

-- install required plugins
require("lazy").setup({
-- towolf/vim-helm provides basic syntax highlighting and filetype detection
-- ft = 'helm' is important to not start yamlls
{ 'towolf/vim-helm', ft = 'helm' },
{ "towolf/vim-helm", ft = "helm" },

{ "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile", "BufEnter" } }
{ "neovim/nvim-lspconfig", event = { "BufReadPre", "BufNewFile", "BufEnter" } },
})


local lspconfig = require('lspconfig')

local lspconfig = require("lspconfig")
-- setup helm-ls
lspconfig.helm_ls.setup {
lspconfig.helm_ls.setup({
settings = {
['helm-ls'] = {
["helm-ls"] = {
yamlls = {
path = "yaml-language-server",
}
}
}
}
},
},
},
})

-- setup yamlls
lspconfig.yamlls.setup {}

lspconfig.yamlls.setup({})

-- below are keymapping as recommended by nvim-lspconfig

-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist)

-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"

-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
end, opts)
end,
})

75 changes: 75 additions & 0 deletions examples/vim-plug/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- a minimal example config for setting up neovim with helm-ls and yamlls using the plugin manager vim-plug
-- test it with: nvim -u init.lua

local Plug = vim.fn["plug#"]

-- install required plugins
vim.call("plug#begin")

Plug("https://github.com/neovim/nvim-lspconfig")
Plug("https://github.com/qvalentin/helm-ls.nvim")

vim.call("plug#end")

-- setup helm-ls.nvim
require("helm-ls").setup({
conceal_templates = {
-- enable the replacement of templates with virtual text of their current values
enabled = false, -- tree-sitter must be setup for this feature
},
indent_hints = {
-- enable hints for indent and nindent functions
enabled = false, -- tree-sitter must be setup for this feature
},
})

local lspconfig = require("lspconfig")

lspconfig.yamlls.setup({})
-- setup helm-ls
lspconfig.helm_ls.setup({
settings = {
["helm-ls"] = {
yamlls = {
path = "yaml-language-server",
},
},
},
})

-- below is the config for a basic lsp keymap
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist)

-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"

-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
end, opts)
end,
})
Loading