Skip to content

Instantly share code, notes, and snippets.

@vrischmann
Last active September 20, 2024 17:03
Show Gist options
  • Save vrischmann/7ede9bff28fe3ad4e4d8fc9fc96e59c7 to your computer and use it in GitHub Desktop.
Save vrischmann/7ede9bff28fe3ad4e4d8fc9fc96e59c7 to your computer and use it in GitHub Desktop.
Using ZLS with nvim-lsp

Using ZLS with nvim-lsp

This configures nvim-lsp to use zls.

Steps

  • build zls as described in its README
  • install nvim-lsp (I'm using the Vim8 native packages), once installed add the file zls.lua under the directory lua/nvim_lsp
  • change the cmd path to point to your zls binary
  • add the content of init.vim to your $HOME/.config/nvim/init.vim, modify the mappings if you want.
packadd lsp
lua << EOF
require'nvim_lsp'.zls.setup{}
EOF
au FileType zig nmap <Leader>dt <cmd>lua vim.lsp.buf.definition()<CR>
au FileType zig nmap <Leader>h <cmd>lua vim.lsp.buf.hover()<CR>
au FileType zig nmap <Leader>p <cmd>lua vim.lsp.buf.signature_help()<CR>
au FileType zig nmap <Leader>gd <cmd>lua vim.lsp.buf.document_symbol()<CR>
au FileType zig setlocal omnifunc=v:lua.vim.lsp.omnifunc
local configs = require 'nvim_lsp/configs'
local util = require 'nvim_lsp/util'
configs.zls = {
default_config = {
cmd = {"/home/vincent/dev/devtools/zls/zig-cache/bin/zls"};
filetypes = {"zig"};
root_dir = util.root_pattern("build.zig", ".git");
};
docs = {
description = [[ ]];
default_config = {
root_dir = [[root_pattern("build.zig", ".git")]];
};
};
}
-- vim:et ts=2 sw=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment