diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 81f709e9..f604a2b8 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -4,7 +4,7 @@ "CursorLineCurrentWindow": { "branch": "master", "commit": "b4eeea98b0d139772969fd243a8802a9883fd2a8" }, "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, "ReplaceWithRegister": { "branch": "master", "commit": "832efc23111d19591d495dc72286de2fb0b09345" }, - "SchemaStore.nvim": { "branch": "main", "commit": "f660f74bcaae950a77c69dda91270063c8cbd692" }, + "SchemaStore.nvim": { "branch": "main", "commit": "f7cae6f1b38cb296f48ce1a9c5ed1a419d912a42" }, "ansible-snippets": { "branch": "master", "commit": "ceb5a528a36c41eb55cd58b79fe4954b94929c05" }, "auto-indent.nvim": { "branch": "main", "commit": "46801cf8857d42a20a73c40b0a5d3dfe8b2b6192" }, "better-escape.nvim": { "branch": "master", "commit": "7e86edafb8c7e73699e0320f225464a298b96d12" }, @@ -25,7 +25,7 @@ "dressing.nvim": { "branch": "master", "commit": "18e5beb3845f085b6a33c24112b37988f3f93c06" }, "fidget.nvim": { "branch": "main", "commit": "1ba38e4cbb24683973e00c2e36f53ae64da38ef5" }, "friendly-snippets": { "branch": "main", "commit": "ea068f1becd91bcd4591fceb6420d4335e2e14d3" }, - "fzf-lua": { "branch": "main", "commit": "62cb8f37b3a017e6b2401726c96e02498f332b70" }, + "fzf-lua": { "branch": "main", "commit": "213da0b65bf81e8849d1ebf2a3d47f32a7dc9000" }, "git-conflict.nvim": { "branch": "main", "commit": "4c8e252b87d54d944c1e56bfb477f78b6fdaf661" }, "global-note.nvim": { "branch": "main", "commit": "1e0d4bba425d971ed3ce40d182c574a25507115c" }, "indent-blankline.nvim": { "branch": "master", "commit": "3d08501caef2329aba5121b753e903904088f7e6" }, @@ -49,12 +49,12 @@ "neogen": { "branch": "main", "commit": "0daffcec249bf42275e322361fe55b89a05ff278" }, "nginx.vim": { "branch": "master", "commit": "cffaec54f0c7f9518de053634413a20e90eac825" }, "none-ls-shellcheck.nvim": { "branch": "main", "commit": "0f84461241e76e376a95fb7391deac82dc3efdbf" }, - "none-ls.nvim": { "branch": "main", "commit": "09a7c58e9283dda582d9805f6b182b5b9f137ec7" }, + "none-ls.nvim": { "branch": "main", "commit": "88821b67e6007041f43b802f58e3d9fa9bfce684" }, "nvim-autopairs": { "branch": "master", "commit": "4f41e5940bc0443fdbe5f995e2a596847215cd2a" }, "nvim-bqf": { "branch": "main", "commit": "52703d7adc3be3f7c09eea9a80c5b8caa615fb25" }, "nvim-cmp": { "branch": "main", "commit": "ce16de5665c766f39c271705b17fff06f7bcb84f" }, "nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" }, - "nvim-dap": { "branch": "master", "commit": "405df1dcc2e395ab5173a9c3d00e03942c023074" }, + "nvim-dap": { "branch": "master", "commit": "6ae8a14828b0f3bff1721a35a1dfd604b6a933bb" }, "nvim-dap-python": { "branch": "master", "commit": "3dffa58541d1f52c121fe58ced046268c838d802" }, "nvim-dap-ui": { "branch": "master", "commit": "edfa93f60b189e5952c016eee262d0685d838450" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "3e8e207513e6ef520894950acd76b79902714103" }, @@ -62,22 +62,22 @@ "nvim-hlslens": { "branch": "main", "commit": "3e8fceb2b030100857ee72741a8f48c9a1d8595e" }, "nvim-jdtls": { "branch": "master", "commit": "8eb5f0dbe6e126b392ddcaf45893358619893e45" }, "nvim-lsp-basics": { "branch": "main", "commit": "632714bd3ab355eb6e725b5a78cd8730f12d14d2" }, - "nvim-lspconfig": { "branch": "master", "commit": "9266dc26862d8f3556c2ca77602e811472b4c5b8" }, + "nvim-lspconfig": { "branch": "master", "commit": "ed8b8a15acc441aec669f97d75f2c1f2ac8c8aa5" }, "nvim-lua-gf": { "branch": "main", "commit": "ca712497b2bab6351518917be219e9bfd8d63e4f" }, "nvim-luaref": { "branch": "main", "commit": "9cd3ed50d5752ffd56d88dd9e395ddd3dc2c7127" }, "nvim-nio": { "branch": "master", "commit": "5800f585def265d52f1d8848133217c800bcb25d" }, "nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" }, "nvim-pqf": { "branch": "main", "commit": "ba0e291cb5c0249838132e197dac082777bdc7d6" }, - "nvim-tree.lua": { "branch": "master", "commit": "81eb8d519233c105f30dc0a278607e62b20502fd" }, - "nvim-treesitter": { "branch": "master", "commit": "b350369740e885c85f0f62dd8fe645c6f887ddc6" }, - "nvim-treesitter-context": { "branch": "master", "commit": "c24a7a6dc5fde325af844d165323aa6f7082866e" }, + "nvim-tree.lua": { "branch": "master", "commit": "ae8e46e8fabb32fa3ae5319383ea2c8763f14caa" }, + "nvim-treesitter": { "branch": "master", "commit": "ea4f6d5175812a3f48302d638a766bc18fcbb04a" }, + "nvim-treesitter-context": { "branch": "master", "commit": "ba4289ad345ececd335a9cdd7b9616fd0bb6be92" }, "nvim-treesitter-endwise": { "branch": "master", "commit": "60e8c288e011403f248b5f6478dde12bed8a6c55" }, "nvim-treesitter-refactor": { "branch": "master", "commit": "65ad2eca822dfaec2a3603119ec3cc8826a7859e" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "23b820146956b3b681c19e10d3a8bc0cbd9a1d4c" }, "nvim-ts-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "a6382f744f584bbf71d0a563af789af7190aabda" }, "nvim-ufo": { "branch": "main", "commit": "a5390706f510d39951dd581f6d2a972741b3fa26" }, - "nvim-web-devicons": { "branch": "master", "commit": "b3468391470034353f0e5110c70babb5c62967d3" }, + "nvim-web-devicons": { "branch": "master", "commit": "beb6367ab8496c9e43f22e0252735fdadae1872d" }, "plenary.nvim": { "branch": "master", "commit": "8aad4396840be7fc42896e3011751b7609ca4119" }, "promise-async": { "branch": "main", "commit": "93540c168c5ed2b030ec3e6c40ab8bbb85e36355" }, "sonokai": { "branch": "master", "commit": "da162343354fbd9bf9cd49293a856f0e3761e8ac" }, @@ -97,7 +97,7 @@ "vim-easy-align": { "branch": "master", "commit": "9815a55dbcd817784458df7a18acacc6f82b1241" }, "vim-floaterm": { "branch": "master", "commit": "4e28c8dd0271e10a5f55142fb6fe9b1599ee6160" }, "vim-fugitive": { "branch": "master", "commit": "dac8e5c2d85926df92672bf2afb4fc48656d96c7" }, - "vim-illuminate": { "branch": "master", "commit": "305bf07b919ac526deb5193280379e2f8b599926" }, + "vim-illuminate": { "branch": "master", "commit": "e522e0dd742a83506db0a72e1ced68c9c130f185" }, "vim-kubernetes": { "branch": "master", "commit": "f477818c30efe4914e9a047ba1105b524d78e1b5" }, "vim-lister": { "branch": "master", "commit": "ec903e615f867f910cd8adc73f5906d521f3f214" }, "vim-matchup": { "branch": "master", "commit": "2d660e4aa7c566014c667af2cda0458043527902" }, diff --git a/.config/nvim/lua/plugins/fzf.lua b/.config/nvim/lua/plugins/fzf.lua index 53925e89..7a2fa7b4 100644 --- a/.config/nvim/lua/plugins/fzf.lua +++ b/.config/nvim/lua/plugins/fzf.lua @@ -48,10 +48,9 @@ return { require('fzf-lua.utils').info('Renamed branch ' .. selected[1] .. ' to ' .. new_name) return else - local msg = string.format('Error when renaming branch: %s. Git returned:\n%s', branch, table.concat(stderr, '\n')) + local msg = string.format('Error when renaming branch: %s. Git returned:\n%s', branch, table.concat(stderr or {}, '\n')) require('fzf-lua.utils').err(msg) end - return ret == 0 end) end, ['ctrl-d'] = function(selected) @@ -67,10 +66,9 @@ return { require('fzf-lua.utils').info('Deleted branch ' .. selected[1]) return else - local msg = string.format('Error when deleting branch: %s. Git returned:\n%s', branch, table.concat(stderr, '\n')) + local msg = string.format('Error when deleting branch: %s. Git returned:\n%s', branch, table.concat(stderr or {}, '\n')) require('fzf-lua.utils').err(msg) end - return ret == 0 end) end, }, diff --git a/.config/nvim/lua/plugins/lsp/init.lua b/.config/nvim/lua/plugins/lsp/init.lua index 61201751..5a05c3b4 100644 --- a/.config/nvim/lua/plugins/lsp/init.lua +++ b/.config/nvim/lua/plugins/lsp/init.lua @@ -1,218 +1,16 @@ -local actions = function() - return { - ['Format (lp)'] = function() - require('user.lsp.formatting').format() - end, - ['Code Actions (la)'] = function() - vim.lsp.buf.code_action() - end, - ['Code Lens (lx)'] = function() - vim.lsp.codelens.run() - end, - ['Show Definition (gd)'] = function() - vim.cmd 'Lspsaga peek_definition' - end, - ['Show Declaration (gD)'] = function() - vim.lsp.buf.declaration() - end, - ['Show Type Definition (gy)'] = function() - vim.lsp.buf.type_definition() - end, - ['Show Implementation (gi)'] = function() - vim.lsp.buf.implementation() - end, - ['Find References (gr)'] = function() - vim.cmd 'Lspsaga finder' - end, - ['Signature Help (lk)'] = function() - vim.lsp.buf.signature_help() - end, - ['Signature Documentation (K)'] = function() - -- vim.lsp.buf.hover() - vim.cmd 'Lspsaga hover_doc' - end, - ['Rename symbol (lrn)'] = function() - vim.cmd 'Lspsaga rename ++project' - end, - ['Diagnostics quickfix list (lq)'] = function() - vim.diagnostic.setqflist() - end, - ['Clear Diagnostics'] = function() - vim.diagnostic.reset() - end, - ['Delete Log'] = function() - vim.system { 'rm', '-rf', vim.lsp.get_log_path() } - end, - } -end - local M = { 'neovim/nvim-lspconfig', event = { 'BufReadPre', 'BufNewFile' }, opts = { - inlay_hints = { enabled = true }, - capabilities = { - textDocument = { - completion = { - completionItem = { - snippetSupport = true, - }, - }, - -- codeAction = { - -- dynamicRegistration = true, - -- codeActionLiteralSupport = { - -- codeActionKind = { - -- valueSet = (function() - -- local res = vim.tbl_values(vim.lsp.protocol.CodeActionKind) - -- table.sort(res) - -- return res - -- end)(), - -- }, - -- }, - -- }, - foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true, - }, - }, - }, setup = { - tsserver = function(_, opts) - require('typescript').setup { - server = opts, - } - return true - end, - - yamlls = function(_, opts) - local yaml_cfg = require('yaml-companion').setup { - schemas = opts.settings.yaml.schemas or {}, - builtin_matchers = { - -- Detects Kubernetes files based on content - kubernetes = { enabled = true }, - }, - lspconfig = opts, - } - require('lspconfig')['yamlls'].setup(yaml_cfg) - 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, }, }, } -M.init = function() - local start_ls = function() - _G.tmp_write { should_delete = false, new = false } - -- load lsp - require 'lspconfig' - end - vim.keymap.set('n', 'ls', start_ls) - require('user.menu').add_actions('LSP', { - ['Start LSP (ls)'] = function() - start_ls() - end, - }) -end - -M.config = function(_, opts) - require('user.menu').add_actions('LSP', actions()) - require('user.lsp.handlers').setup() - - require('lspconfig.ui.windows').default_options.border = require('user.utils').borders.single_rounded +M.init = require('user.lsp.config').init - -- Set formatting of lsp log - require('vim.lsp.log').set_format_func(vim.inspect) - - local servers = require 'user.lsp.servers' - ------------------ - -- Capabilities -- - ------------------ - local capabilities = vim.tbl_deep_extend( - 'force', - {}, - vim.lsp.protocol.make_client_capabilities(), - has_cmp and cmp_nvim_lsp.default_capabilities() or {}, - opts.capabilities or {} - ) - - ----------------- - -- Diagnostics -- - ----------------- - -- show icons in the sidebar - local signs = { - [vim.diagnostic.severity.ERROR] = '✘', - [vim.diagnostic.severity.WARN] = '', - [vim.diagnostic.severity.HINT] = ' ', - [vim.diagnostic.severity.INFO] = ' ', - } - vim.diagnostic.config { - signs = { text = signs }, - update_in_insert = false, - virtual_text = { - severity = { min = vim.diagnostic.severity.WARN }, - }, - float = { border = require('user.utils').float_border }, - } - - 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', @@ -288,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' }, @@ -316,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) @@ -327,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/actions.lua b/.config/nvim/lua/user/lsp/actions.lua new file mode 100644 index 00000000..1e9abd69 --- /dev/null +++ b/.config/nvim/lua/user/lsp/actions.lua @@ -0,0 +1,57 @@ +local M = {} +M.actions = function() + return { + ['Format (lp)'] = function() + require('user.lsp.formatting').format() + end, + ['Code Actions (la)'] = function() + vim.lsp.buf.code_action() + end, + ['Code Lens (lx)'] = function() + vim.lsp.codelens.run() + end, + ['Show Definition (gd)'] = function() + vim.cmd 'Lspsaga peek_definition' + end, + ['Show Declaration (gD)'] = function() + vim.lsp.buf.declaration() + end, + ['Show Type Definition (gy)'] = function() + vim.lsp.buf.type_definition() + end, + ['Show Implementation (gi)'] = function() + vim.lsp.buf.implementation() + end, + ['Find References (gr)'] = function() + vim.cmd 'Lspsaga finder' + end, + ['Signature Help (lk)'] = function() + vim.lsp.buf.signature_help() + end, + ['Signature Documentation (K)'] = function() + -- vim.lsp.buf.hover() + vim.cmd 'Lspsaga hover_doc' + end, + ['Rename symbol (lrn)'] = function() + vim.cmd 'Lspsaga rename ++project' + end, + ['Diagnostics quickfix list (lq)'] = function() + vim.diagnostic.setqflist() + end, + ['Toggle inlay hints (lh)'] = function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(), { bufnr = 0 }) + end, + ['Clear Diagnostics'] = function() + vim.diagnostic.reset() + end, + ['Delete Log'] = function() + vim.system { 'rm', '-rf', vim.lsp.get_log_path() } + end, + } +end + +M.setup = function() + require('user.menu').add_actions('LSP', M.actions()) +end + +return M diff --git a/.config/nvim/lua/user/lsp/config.lua b/.config/nvim/lua/user/lsp/config.lua new file mode 100644 index 00000000..57794c68 --- /dev/null +++ b/.config/nvim/lua/user/lsp/config.lua @@ -0,0 +1,85 @@ +local M = { + capabilities = { + textDocument = { + completion = { + completionItem = { + snippetSupport = true, + }, + }, + foldingRange = { + dynamicRegistration = false, + lineFoldingOnly = true, + }, + }, + }, +} + +M.setup_capabilities = function() + ------------------ + -- Capabilities -- + ------------------ + 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.diagnostic_signs = { + [vim.diagnostic.severity.ERROR] = '✘', + [vim.diagnostic.severity.WARN] = '', + [vim.diagnostic.severity.HINT] = ' ', + [vim.diagnostic.severity.INFO] = ' ', +} + +M.diagnostics = function() + ----------------- + -- Diagnostics -- + ----------------- + -- show icons in the sidebar + vim.diagnostic.config { + signs = { text = M.diagnostic_signs }, + update_in_insert = false, + virtual_text = { + severity = { min = vim.diagnostic.severity.WARN }, + }, + float = { border = require('user.utils').float_border }, + } +end + +M.init = function() + local start_ls = function() + _G.tmp_write { should_delete = false, new = false } + -- load lsp + require 'lspconfig' + end + vim.keymap.set('n', 'ls', start_ls) + require('user.menu').add_actions('LSP', { + ['Start LSP (ls)'] = function() + start_ls() + end, + }) +end + +M.setup = function() + require('user.lsp.actions').setup() + require('user.lsp.handlers').setup() + + -- set lsp window border style + require('lspconfig.ui.windows').default_options.border = require('user.utils').borders.single_rounded + + -- Set formatting of lsp log + require('vim.lsp.log').set_format_func(vim.inspect) + + -- set up capabilities + M.setup_capabilities() + + -- set up diagnostics configuration + M.diagnostics() + + -- set up mason to install lsp servers + require('mason-lspconfig').setup { automatic_installation = true } + + -- setup lsp servers + require('user.lsp.servers').setup() +end + +return M diff --git a/.config/nvim/lua/user/lsp/keymaps.lua b/.config/nvim/lua/user/lsp/keymaps.lua index 50283cff..76a7fee1 100644 --- a/.config/nvim/lua/user/lsp/keymaps.lua +++ b/.config/nvim/lua/user/lsp/keymaps.lua @@ -36,7 +36,7 @@ return function(bufnr) -- Inlay hints nnoremap('lh', function() - vim.lsp.inlay_hint(0, nil) + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(), { bufnr = bufnr }) end, returnOpts 'Set qflist') -- Diagnostics diff --git a/.config/nvim/lua/user/lsp/on-attach.lua b/.config/nvim/lua/user/lsp/on-attach.lua index 72e79624..671c0b6b 100644 --- a/.config/nvim/lua/user/lsp/on-attach.lua +++ b/.config/nvim/lua/user/lsp/on-attach.lua @@ -25,7 +25,7 @@ local default_on_attach = function(client, bufnr) desc = 'Auto show code lenses', group = on_attach_aug, buffer = bufnr, - command = 'silent! lua vim.lsp.codelens.refresh()', + command = 'silent! lua vim.lsp.codelens.refresh({bufnr=' .. bufnr .. '})', }) end if client.server_capabilities.document_highlight then @@ -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(true, { bufnr = bufnr }) + 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 6a458f65..f3c330d2 100644 --- a/.config/nvim/lua/user/lsp/servers.lua +++ b/.config/nvim/lua/user/lsp/servers.lua @@ -1,41 +1,54 @@ -local on_attaches = require 'user.lsp.on-attach' -local default_on_attach = on_attaches.default - -local M = { - ansiblels = { +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, + } - bashls = { + require('lspconfig')['bashls'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - cssls = { + require('lspconfig')['cssls'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - cssmodules_ls = { + require('lspconfig')['cssmodules_ls'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - dockerls = { + require('lspconfig')['dockerls'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - docker_compose_language_service = { + require('lspconfig')['docker_compose_language_service'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - groovyls = { + require('lspconfig')['groovyls'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - html = { + require('lspconfig')['html'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - jsonls = { + require('lspconfig')['jsonls'].setup { on_attach = default_on_attach, + capabilities = capabilities, settings = { json = { trace = { @@ -45,19 +58,21 @@ local M = { validate = { enable = true }, }, }, - }, + } - pyright = { + require('lspconfig')['pyright'].setup { on_attach = default_on_attach, + capabilities = capabilities, settings = { organizeimports = { provider = 'isort', }, }, - }, + } - lua_ls = { + require('lspconfig')['lua_ls'].setup { on_attach = default_on_attach, + capabilities = capabilities, settings = { Lua = { runtime = { @@ -82,104 +97,113 @@ local M = { -- telemetry = { enable = false }, }, }, - }, + } - terraformls = { + require('lspconfig')['terraformls'].setup { on_attach = function(c, b) require('treesitter-terraform-doc').setup {} default_on_attach(c, b) c.server_capabilities.semanticTokensProvider = {} end, - }, - - tsserver = { - 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, - }, + } - vimls = { + require('lspconfig')['vimls'].setup { on_attach = default_on_attach, - }, + capabilities = capabilities, + } - jdtls = { + require('lspconfig')['jdtls'].setup { on_attach = function(c, b) require('jdtls').setup_dap() default_on_attach(c, b) end, + capabilities = capabilities, settings = { filetypes = { 'kotlin', 'java' }, workspace = { checkThirdParty = false }, }, - }, - - helm_ls = { + } + + 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, + } - yamlls = { - on_attach = function(c, b) - local filetype = vim.api.nvim_get_option_value('filetype', { buf = b }) - local buftype = vim.api.nvim_get_option_value('buftype', { buf = b }) - local disabled_fts = { 'helm', 'yaml.gotexttmpl', 'gotmpl' } - if buftype ~= '' or filetype == '' or vim.tbl_contains(disabled_fts, filetype) then - vim.diagnostic.disable(b) - vim.defer_fn(function() - vim.diagnostic.reset(nil, b) - end, 1000) - end - default_on_attach(c, b) - end, - settings = { - redhat = { telemetry = { enabled = false } }, - yaml = { - validate = true, - format = { enable = true }, - hover = true, - trace = { server = 'debug' }, - completion = true, - schemaStore = { - enable = true, - url = 'https://www.schemastore.org/api/json/catalog.json', - }, - schemas = { - kubernetes = '', - }, - }, + local yaml_cfg = require('yaml-companion').setup { + builtin_matchers = { + -- Detects Kubernetes files based on content + kubernetes = { enabled = true }, + }, + lspconfig = { + on_attach = function(c, b) + local filetype = vim.api.nvim_get_option_value('filetype', { buf = b }) + local buftype = vim.api.nvim_get_option_value('buftype', { buf = b }) + local disabled_fts = { 'helm', 'yaml.gotexttmpl', 'gotmpl' } + if buftype ~= '' or filetype == '' or vim.tbl_contains(disabled_fts, filetype) then + vim.diagnostic.enable(false, b) + vim.defer_fn(function() + vim.diagnostic.reset(nil, b) + end, 1000) + end + default_on_attach(c, b) + end, + capabilities = capabilities, }, - }, -} + } + require('lspconfig')['yamlls'].setup(yaml_cfg) +end return M diff --git a/.config/nvim/lua/user/utils.lua b/.config/nvim/lua/user/utils.lua index 04e9d6bb..430f62aa 100644 --- a/.config/nvim/lua/user/utils.lua +++ b/.config/nvim/lua/user/utils.lua @@ -157,7 +157,7 @@ M.country_os_to_emoji = function(iso) python_file_handle:close() local emoji = vim.system({ 'python3', python_file, iso }, { text = true }):wait().stdout vim.fn.delete(python_file) - return emoji + return emoji or '' end M.tbl_get_next = function(tbl, cur) diff --git a/.config/nvim/minimal_init.lua b/.config/nvim/minimal_init.lua index 0d2f710d..62c869b9 100644 --- a/.config/nvim/minimal_init.lua +++ b/.config/nvim/minimal_init.lua @@ -4,7 +4,7 @@ local function join_paths(...) return result end -local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp' +local temp_dir = vim.uv.os_getenv 'TEMP' or '/tmp' local package_root = join_paths(temp_dir, 'nvim', 'site', 'lazy') local lazypath = join_paths(temp_dir, 'nvim', 'site') .. '/lazy/lazy.nvim' if not vim.loop.fs_stat(lazypath) then @@ -31,11 +31,7 @@ _G.load_config = function() vim.api.nvim_buf_set_keymap(bufnr, ...) end - local function buf_set_option(...) - vim.api.nvim_buf_set_option(bufnr, ...) - end - - buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + vim.api.nvim_set_option_value('omnifunc', 'v:lua.vim.lsp.omnifunc', { buf = bufnr }) -- Mappings. local opts = { noremap = true, silent = true }