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
nil
yaml-language-server
lua-language-server
];
home.sessionVariables.EDITOR = "nvim";
}

View File

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