Add lsp for .lua

This commit is contained in:
Torjus Håkestad 2024-03-05 22:49:06 +01:00
parent 405080b22d
commit e0e927edb1
2 changed files with 76 additions and 33 deletions

View File

@ -51,6 +51,7 @@
nodePackages.typescript-language-server nodePackages.typescript-language-server
nil nil
yaml-language-server yaml-language-server
lua-language-server
]; ];
home.sessionVariables.EDITOR = "nvim"; home.sessionVariables.EDITOR = "nvim";
} }

View File

@ -3,6 +3,7 @@
-- LSP stuff -- LSP stuff
local lsp_zero = require('lsp-zero') local lsp_zero = require('lsp-zero')
lsp_zero.on_attach(function(client, bufnr) lsp_zero.on_attach(function(client, bufnr)
lsp_zero.default_keymaps({ buffer = bufnr }) lsp_zero.default_keymaps({ buffer = bufnr })
end) end)
@ -15,6 +16,7 @@ lsp_zero.format_on_save({
servers = { servers = {
['gopls'] = { 'go' }, ['gopls'] = { 'go' },
['nil_ls'] = { 'nix' }, ['nil_ls'] = { 'nix' },
['lua_ls'] = { 'lua' },
}, },
}) })
@ -42,6 +44,46 @@ lspconfig.nil_ls.setup({
}, },
}) })
lspconfig.lua_ls.setup({
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then
return
end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end,
settings = {
Lua = {
format = {
enable = true,
defaultConfig = {
indent_style = "space",
indent_size = "2",
}
}
}
}
})
-- Telescope -- Telescope
require('telescope').setup({ require('telescope').setup({