From e0e927edb1bd4fb9ef0ae81dd15387e743a44f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Tue, 5 Mar 2024 22:49:06 +0100 Subject: [PATCH] Add lsp for .lua --- home/editor/neovim/default.nix | 1 + home/editor/neovim/plugins.lua | 108 +++++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/home/editor/neovim/default.nix b/home/editor/neovim/default.nix index 6f1f28e..44c58be 100644 --- a/home/editor/neovim/default.nix +++ b/home/editor/neovim/default.nix @@ -51,6 +51,7 @@ nodePackages.typescript-language-server nil yaml-language-server + lua-language-server ]; home.sessionVariables.EDITOR = "nvim"; } diff --git a/home/editor/neovim/plugins.lua b/home/editor/neovim/plugins.lua index 0bfc100..e1b4454 100644 --- a/home/editor/neovim/plugins.lua +++ b/home/editor/neovim/plugins.lua @@ -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 = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', - }, - }, - textobjects = { - select = { - enable = true, - lookahead = true, + incremental_selection = { + enable = true, + keymaps = { + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', + }, + }, + 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 - [''] = cmp.mapping.confirm({select = false}), + [''] = cmp.mapping.confirm({ select = false }), -- Ctrl+Space to open completion menu [''] = cmp.mapping.complete(), -- Move between snippet placeholders