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,8 +3,9 @@
-- 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)
lsp_zero.format_on_save({ lsp_zero.format_on_save({
@ -13,8 +14,9 @@ lsp_zero.format_on_save({
timeout_ms = 10000, timeout_ms = 10000,
}, },
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({
@ -57,35 +99,35 @@ require('telescope').setup({
-- Tresitter stuff -- Tresitter stuff
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
ensure_installed = {}, ensure_installed = {},
auto_install = false, auto_install = false,
highlight = { enable = true }, highlight = { enable = true },
indent = { enable = true}, indent = { enable = true },
incremental_selection = { incremental_selection = {
enable = true, enable = true,
keymaps = { keymaps = {
init_selection = '<c-space>', init_selection = '<c-space>',
node_incremental = '<c-space>', node_incremental = '<c-space>',
scope_incremental = '<c-s>', scope_incremental = '<c-s>',
node_decremental = '<M-space>', node_decremental = '<M-space>',
}, },
}, },
textobjects = { textobjects = {
select = { select = {
enable = true, enable = true,
lookahead = true, lookahead = true,
keymaps = { keymaps = {
['aa'] = '@parameter.outer', ['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner', ['ia'] = '@parameter.inner',
['af'] = '@function.outer', ['af'] = '@function.outer',
['if'] = '@function.inner', ['if'] = '@function.inner',
['ac'] = '@class.outer', ['ac'] = '@class.outer',
['ic'] = '@class.inner', ['ic'] = '@class.inner',
} }
} }
} }
} }
-- Lualine -- Lualine
@ -115,7 +157,7 @@ require('lualine').setup({
} }
} }
}, },
lualine_x = {'encoding', 'fileformat', 'filetype'}, lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' }, lualine_y = { 'progress' },
lualine_z = { 'location' } lualine_z = { 'location' }
} }
@ -124,7 +166,7 @@ require('lualine').setup({
-- Copilot -- Copilot
require('copilot').setup({ require('copilot').setup({
suggestions = { enabled = false }, suggestions = { enabled = false },
panel = { enabled = false}, panel = { enabled = false },
}) })
require('copilot_cmp').setup() require('copilot_cmp').setup()
@ -140,7 +182,7 @@ cmp.setup({
}, },
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
-- Enter to confirm completion -- Enter to confirm completion
['<CR>'] = cmp.mapping.confirm({select = false}), ['<CR>'] = cmp.mapping.confirm({ select = false }),
-- Ctrl+Space to open completion menu -- Ctrl+Space to open completion menu
['<C-Space>'] = cmp.mapping.complete(), ['<C-Space>'] = cmp.mapping.complete(),
-- Move between snippet placeholders -- Move between snippet placeholders