diff --git a/.config/nvim/lua/plugins/lsp/init.lua b/.config/nvim/lua/plugins/lsp/init.lua index 3a74c9e6..5a05c3b4 100644 --- a/.config/nvim/lua/plugins/lsp/init.lua +++ b/.config/nvim/lua/plugins/lsp/init.lua @@ -2,31 +2,7 @@ local M = { 'neovim/nvim-lspconfig', event = { 'BufReadPre', 'BufNewFile' }, opts = { - inlay_hints = { enabled = true }, setup = { - tsserver = function(_, opts) - require('typescript').setup { - server = opts, - } - return true - end, - - helm_ls = function() - local configs = require 'lspconfig.configs' - local util = require 'lspconfig.util' - - if not configs.helm_ls then - configs.helm_ls = { - default_config = { - cmd = { 'helm_ls', 'serve' }, - filetypes = { 'helm', 'gotmpl' }, - root_dir = function(fname) - return util.root_pattern 'Chart.yaml'(fname) - end, - }, - } - end - end, docker_compose_language_service = function() end, }, }, @@ -34,49 +10,7 @@ local M = { M.init = require('user.lsp.config').init -M.config = function() - require('user.lsp.config').setup() - -- local function setup(server) - -- local server_opts = vim.tbl_deep_extend('force', { - -- capabilities = vim.deepcopy(capabilities), - -- }, servers[server] or {}) - -- - -- if opts.setup[server] then - -- if opts.setup[server](server, server_opts) then - -- return - -- end - -- elseif opts.setup['*'] then - -- if opts.setup['*'](server, server_opts) then - -- return - -- end - -- end - -- require('lspconfig')[server].setup(server_opts) - -- end - - -- get all the servers that are available thourgh mason-lspconfig - -- local have_mason, mlsp = pcall(require, 'mason-lspconfig') - -- local all_mslp_servers = {} - -- if have_mason then - -- all_mslp_servers = vim.tbl_keys(require('mason-lspconfig.mappings.server').lspconfig_to_package) - -- end - -- - -- local ensure_installed = {} ---@type string[] - -- for server, server_opts in pairs(servers) do - -- if server_opts then - -- server_opts = server_opts == true and {} or server_opts - -- -- run manual setup if mason=false or if this is a server that cannot be installed with mason-lspconfig - -- if server_opts.mason == false or not vim.tbl_contains(all_mslp_servers, server) then - -- setup(server) - -- else - -- ensure_installed[#ensure_installed + 1] = server - -- end - -- end - -- end - -- - -- if have_mason then - -- mlsp.setup { ensure_installed = ensure_installed, handlers = { setup } } - -- end -end +M.config = require('user.lsp.config').setup M.dependencies = { 'nvimtools/none-ls.nvim', @@ -152,10 +86,7 @@ M.dependencies = { } local language_specific_plugins = { - { - 'mfussenegger/nvim-jdtls', - ft = { 'java' }, - }, + { 'mfussenegger/nvim-jdtls', ft = 'java' }, { 'jose-elias-alvarez/typescript.nvim', ft = { 'typescript', 'typescriptreact', 'typescript.tsx', 'javascript' }, @@ -180,7 +111,7 @@ local language_specific_plugins = { }, { 'someone-stole-my-name/yaml-companion.nvim', - ft = { 'yaml' }, + ft = 'yaml', config = function() local nnoremap = require('user.utils').nnoremap nnoremap('cc', ":lua require('yaml-companion').open_ui_select()", true) @@ -191,10 +122,7 @@ local language_specific_plugins = { }) end, }, - { - 'b0o/SchemaStore.nvim', - ft = { 'yaml' }, - }, + { 'b0o/SchemaStore.nvim', ft = 'yaml' }, } return { diff --git a/.config/nvim/lua/user/lsp/config.lua b/.config/nvim/lua/user/lsp/config.lua index 67a5803e..4f52794a 100644 --- a/.config/nvim/lua/user/lsp/config.lua +++ b/.config/nvim/lua/user/lsp/config.lua @@ -31,14 +31,9 @@ M.setup_capabilities = function() ------------------ -- Capabilities -- ------------------ - M.capabilities = vim.tbl_deep_extend( - 'force', - {}, - vim.lsp.protocol.make_client_capabilities(), - -- TODO: fix cmp capabilities - has_cmp and cmp_nvim_lsp.default_capabilities() or {}, - M.capabilities or {} - ) + local cmp_default_capabilities = require('cmp_nvim_lsp').default_capabilities() + + M.capabilities = vim.tbl_deep_extend('force', vim.lsp.protocol.make_client_capabilities(), cmp_default_capabilities, M.capabilities or {}, {}) end M.diagnostics = function() @@ -62,13 +57,6 @@ M.diagnostics = function() } end -M.get_mason_lspconfig = function() - local have_mason, _ = pcall(require, 'mason-lspconfig') - if have_mason then - M.all_mason_lsp_servers = vim.tbl_keys(require('mason-lspconfig.mappings.server').lspconfig_to_package) - end -end - M.init = function() local start_ls = function() _G.tmp_write { should_delete = false, new = false } @@ -99,8 +87,8 @@ M.setup = function() -- set up diagnostics configuration M.diagnostics() - -- get all the servers that are available thourgh mason-lspconfig - M.get_mason_lspconfig() + -- set up mason to install lsp servers + require('mason-lspconfig').setup { automatic_installation = true } -- setup lsp servers require('user.lsp.servers').setup() diff --git a/.config/nvim/lua/user/lsp/on-attach.lua b/.config/nvim/lua/user/lsp/on-attach.lua index 72e79624..b6268630 100644 --- a/.config/nvim/lua/user/lsp/on-attach.lua +++ b/.config/nvim/lua/user/lsp/on-attach.lua @@ -43,21 +43,6 @@ local default_on_attach = function(client, bufnr) command = 'silent! lua vim.lsp.buf.clear_references()', }) end - -- local diagnostic_pop = augroup 'DiagnosticPop' - -- autocmd('CursorHold', { - -- buffer = bufnr, - -- group = diagnostic_pop, - -- callback = function() - -- vim.diagnostic.open_float(nil, { - -- focusable = false, - -- close_events = { 'BufLeave', 'CursorMoved', 'InsertEnter', 'FocusLost' }, - -- border = 'rounded', - -- source = 'always', - -- prefix = ' ', - -- scope = 'cursor', - -- }) - -- end, - -- }) ---------------------------------- -- Enable tag jump based on LSP -- @@ -65,6 +50,13 @@ local default_on_attach = function(client, bufnr) if client.server_capabilities.goto_definition then vim.api.nvim_set_option_value('tagfunc', 'v:lua.vim.lsp.tagfunc', { buf = bufnr }) end + + ----------------- + -- Inlay Hints -- + ----------------- + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint.enable(bufnr, true) + end end local minimal_on_attach = function(_, bufnr) diff --git a/.config/nvim/lua/user/lsp/servers.lua b/.config/nvim/lua/user/lsp/servers.lua index b1c01987..f9e955f7 100644 --- a/.config/nvim/lua/user/lsp/servers.lua +++ b/.config/nvim/lua/user/lsp/servers.lua @@ -2,40 +2,53 @@ local M = {} M.setup = function() local on_attaches = require 'user.lsp.on-attach' local default_on_attach = on_attaches.default + local capabilities = require('user.lsp.config').capabilities + local configs = require 'lspconfig.configs' + local util = require 'lspconfig.util' + require('lspconfig')['ansiblels'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['bashls'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['cssls'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['cssmodules_ls'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['dockerls'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['docker_compose_language_service'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['groovyls'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['html'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['jsonls'].setup { on_attach = default_on_attach, + capabilities = capabilities, settings = { json = { trace = { @@ -49,6 +62,7 @@ M.setup = function() require('lspconfig')['pyright'].setup { on_attach = default_on_attach, + capabilities = capabilities, settings = { organizeimports = { provider = 'isort', @@ -58,6 +72,7 @@ M.setup = function() require('lspconfig')['lua_ls'].setup { on_attach = default_on_attach, + capabilities = capabilities, settings = { Lua = { runtime = { @@ -90,48 +105,53 @@ M.setup = function() default_on_attach(c, b) c.server_capabilities.semanticTokensProvider = {} end, - } - - require('lspconfig')['tsserver'].setup { - settings = { - preferences = { - allowRenameOfImportPath = true, - disableSuggestions = false, - importModuleSpecifierEnding = 'auto', - importModuleSpecifierPreference = 'non-relative', - includeCompletionsForImportStatements = true, - includeCompletionsForModuleExports = true, - quotePreference = 'single', - }, - -- specify some or all of the following settings if you want to adjust the default behavior - javascript = { - inlayHints = { - includeInlayEnumMemberValueHints = true, - includeInlayFunctionLikeReturnTypeHints = true, - includeInlayFunctionParameterTypeHints = true, - includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all'; - includeInlayParameterNameHintsWhenArgumentMatchesName = true, - includeInlayPropertyDeclarationTypeHints = true, - includeInlayVariableTypeHints = true, + capabilities = capabilities, + } + + require('typescript').setup { + server = { + settings = { + preferences = { + allowRenameOfImportPath = true, + disableSuggestions = false, + importModuleSpecifierEnding = 'auto', + importModuleSpecifierPreference = 'non-relative', + includeCompletionsForImportStatements = true, + includeCompletionsForModuleExports = true, + quotePreference = 'single', }, - }, - typescript = { - inlayHints = { - includeInlayEnumMemberValueHints = true, - includeInlayFunctionLikeReturnTypeHints = true, - includeInlayFunctionParameterTypeHints = true, - includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all'; - includeInlayParameterNameHintsWhenArgumentMatchesName = true, - includeInlayPropertyDeclarationTypeHints = true, - includeInlayVariableTypeHints = true, + -- specify some or all of the following settings if you want to adjust the default behavior + javascript = { + inlayHints = { + includeInlayEnumMemberValueHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all'; + includeInlayParameterNameHintsWhenArgumentMatchesName = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayVariableTypeHints = true, + }, + }, + typescript = { + inlayHints = { + includeInlayEnumMemberValueHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayParameterNameHints = 'all', -- 'none' | 'literals' | 'all'; + includeInlayParameterNameHintsWhenArgumentMatchesName = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayVariableTypeHints = true, + }, }, }, + on_attach = default_on_attach, + capabilities = capabilities, }, - on_attach = default_on_attach, } require('lspconfig')['vimls'].setup { on_attach = default_on_attach, + capabilities = capabilities, } require('lspconfig')['jdtls'].setup { @@ -139,14 +159,27 @@ M.setup = function() require('jdtls').setup_dap() default_on_attach(c, b) end, + capabilities = capabilities, settings = { filetypes = { 'kotlin', 'java' }, workspace = { checkThirdParty = false }, }, } + if not configs.helm_ls then + configs.helm_ls = { + default_config = { + cmd = { 'helm_ls', 'serve' }, + filetypes = { 'helm', 'gotmpl' }, + root_dir = function(fname) + return util.root_pattern 'Chart.yaml'(fname) + end, + }, + } + end require('lspconfig')['helm_ls'].setup { on_attach = default_on_attach, + capabilities = capabilities, } local yaml_cfg = require('yaml-companion').setup { @@ -167,6 +200,7 @@ M.setup = function() end default_on_attach(c, b) end, + capabilities = capabilities, }, } require('lspconfig')['yamlls'].setup(yaml_cfg)