From 880bbd18e0e4608840aca314c4d8be47b19515f8 Mon Sep 17 00:00:00 2001 From: Dmitrii Chumak Date: Thu, 24 Jul 2025 18:04:28 +0300 Subject: [PATCH] [vim] migration to 0.11 and native lsp client --- nvim/lazy-lock.json | 27 ++++--- nvim/lsp/basedpyright.lua | 25 ++++++ nvim/lsp/bashls.lua | 25 ++++++ nvim/lsp/gopls.lua | 20 +++++ nvim/lsp/lua_ls.lua | 33 ++++++++ nvim/lua/lsp-config.lua | 157 +++++++++++--------------------------- nvim/lua/plugins/init.lua | 9 +-- 7 files changed, 164 insertions(+), 132 deletions(-) create mode 100644 nvim/lsp/basedpyright.lua create mode 100644 nvim/lsp/bashls.lua create mode 100644 nvim/lsp/gopls.lua create mode 100644 nvim/lsp/lua_ls.lua diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 53c440b..52daef0 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,20 +1,19 @@ { - "LuaSnip": { "branch": "master", "commit": "c9b9a22904c97d0eb69ccb9bab76037838326817" }, - "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" }, - "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, - "codecompanion.nvim": { "branch": "main", "commit": "1b1bfc71f426a50ece54489078f5afe82b0af90c" }, + "LuaSnip": { "branch": "master", "commit": "3d5bced1b9ae69fa3f9b1942e28af5dbc537f946" }, + "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, + "cmp-path": { "branch": "main", "commit": "e52e640b7befd8113b3350f46e8cfcfe98fcf730" }, + "codecompanion.nvim": { "branch": "main", "commit": "e23e8e5a5643b089607f21f576f6e63174cc44dc" }, "github-theme": { "branch": "main", "commit": "c106c9472154d6b2c74b74565616b877ae8ed31d" }, - "gitsigns.nvim": { "branch": "main", "commit": "011dc6718bcebdf92a5336bb0da79189c3afe621" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" }, - "mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" }, - "nvim-cmp": { "branch": "main", "commit": "c27370703e798666486e3064b64d59eaf4bdc6d5" }, - "nvim-lspconfig": { "branch": "master", "commit": "fd26f8626c03b424f7140d454031d1dcb8d23513" }, - "nvim-treesitter": { "branch": "master", "commit": "684eeac91ed8e297685a97ef70031d19ac1de25a" }, - "outline.nvim": { "branch": "main", "commit": "ae473fb51b7b6086de0876328c81a63f9c3ecfef" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "bb3a17efc797c34c054463174e5522442576ebd8" }, + "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, + "nvim-lspconfig": { "branch": "master", "commit": "169745f176f58becad80363c3f8f2315ed6bb365" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, + "outline.nvim": { "branch": "main", "commit": "0eb9289ab39c91caf8b3ed0e3a17764809d69558" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, - "telescope-file-browser.nvim": { "branch": "master", "commit": "626998e5c1b71c130d8bc6cf7abb6709b98287bb" }, - "telescope.nvim": { "branch": "master", "commit": "814f102cd1da3dc78c7d2f20f2ef3ed3cdf0e6e4" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "7bf55ed0ff5be182ad3301cff266581fc1c56cce" }, + "telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" }, "which-key.nvim": { "branch": "main", "commit": "370ec46f710e058c9c1646273e6b225acf47cbed" } } diff --git a/nvim/lsp/basedpyright.lua b/nvim/lsp/basedpyright.lua new file mode 100644 index 0000000..25796bc --- /dev/null +++ b/nvim/lsp/basedpyright.lua @@ -0,0 +1,25 @@ +return { + cmd = { 'basedpyright-langserver', '--stdio' }, + filetypes = { 'python' }, + root_markers = { + 'pyrightconfig.json', + 'ya.make', + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', + '.git', + }, + settings = { + python = { + analysis = { + autoSearchPaths = false, + useLibraryCodeForTypes = true, + diagnosticMode = 'openFilesOnly', + include = { + } + }, + }, + }, +} diff --git a/nvim/lsp/bashls.lua b/nvim/lsp/bashls.lua new file mode 100644 index 0000000..612caae --- /dev/null +++ b/nvim/lsp/bashls.lua @@ -0,0 +1,25 @@ +return { + cmd = { 'bash-language-server', 'start' }, + filetypes = { 'bash', 'sh', 'zsh' }, + root_markers = { '.git', vim.uv.cwd() }, + settings = { + bashIde = { + globPattern = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)', + -- Modern formatting options (requires shfmt) + tabSize = 2, + insertSpaces = true, + -- Enable comprehensive features like Ruby LSP + enableSourceErrorDiagnostics = true, + enableCodeLens = true, + includeAllWorkspaceSymbols = true, + -- Background analysis for better performance + backgroundAnalysisMaxFiles = 500, + -- ShellCheck integration for linting + shellcheckPath = 'shellcheck', + shellcheckArguments = { + '--shell=bash', + '--format=json', + }, + }, + }, +} diff --git a/nvim/lsp/gopls.lua b/nvim/lsp/gopls.lua new file mode 100644 index 0000000..8a60d91 --- /dev/null +++ b/nvim/lsp/gopls.lua @@ -0,0 +1,20 @@ +return { + cmd = { "/home/dmchumak/.ya/tools/v3/gopls-linux/gopls" }, + filetypes = { "go", "gotempl", "gowork", "gomod" }, + root_markers = { "ya.make", "YAOWNERS", ".arcadia.root", ".cloudia.root", "go.work", "go.mod", ".git" }, + -- settings = { + -- gopls = { + -- completeUnimported = true, + -- usePlaceholders = true, + -- analyses = { + -- unusedparams = true, + -- }, + -- ["ui.inlayhint.hints"] = { + -- compositeLiteralFields = true, + -- constantValues = true, + -- parameterNames = true, + -- rangeVariableTypes = true, + -- }, + -- }, + -- }, +} diff --git a/nvim/lsp/lua_ls.lua b/nvim/lsp/lua_ls.lua new file mode 100644 index 0000000..cdef273 --- /dev/null +++ b/nvim/lsp/lua_ls.lua @@ -0,0 +1,33 @@ +return { + cmd = { "lua-language-server" }, + root_markers = { ".luarc.json", ".git", "init.lua" }, + filetypes = { "lua" }, + settings = { + Lua = { + format = { + enable = true, + defaultConfig = { + indent_style = "space", + indent_size = "2", + } + }, + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + } + } +} + diff --git a/nvim/lua/lsp-config.lua b/nvim/lua/lsp-config.lua index d9e7506..30edaa8 100644 --- a/nvim/lua/lsp-config.lua +++ b/nvim/lua/lsp-config.lua @@ -4,57 +4,55 @@ require("mason-lspconfig").setup({ 'lua_ls', 'gopls', 'bashls', - 'pyright', + 'basedpyright', }, automatic_installation = true, + automatic_enable = false }) --- Customized on_attach function --- See `:help vim.diagnostic.*` for documentation on any of the below functions --- local opts = { noremap = true, silent = true } -vim.keymap.set("n", "e", vim.diagnostic.open_float, opts) -vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) +local keymap = vim.keymap.set -local on_attach = function(client, bufnr) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(ev) + local bufnr = ev.buf + local bufopts = { noremap = true, silent = true, buffer = bufnr } - if client.name == "rust_analyzer" then - -- This requires Neovim 0.10 or later - vim.lsp.inlay_hint.enable() + local client = vim.lsp.get_client_by_id(ev.data.client_id) + if not client then + return + end + + local lsp = vim.lsp + local function opt(desc, others) + return vim.tbl_extend("force", bufopts, { desc = desc }, others or {}) + end + + -- See `:help vim.lsp.*` for documentation on any of the below functions + keymap("n", "gD", lsp.buf.declaration, opt('[G]o to [d]eclaration')) + keymap("n", "gd", lsp.buf.definition, opt("[G]o to [d]efinition")) + keymap("n", "D", lsp.buf.type_definition, opt("Go to Type [D]efinition")) + keymap("n", "K", lsp.buf.hover, bufopts) + keymap("n", "gi", lsp.buf.implementation, opt("[G]o to [i]mplementation")) + keymap("n", "gr", require'telescope.builtin'.lsp_references, opt("[G]o to [r]eferences")) + keymap("n", "", lsp.buf.signature_help, bufopts) + keymap("n", "wa", lsp.buf.add_workspace_folder, bufopts) + keymap("n", "wr", lsp.buf.remove_workspace_folder, bufopts) + keymap("n", "wl", function() + print(vim.inspect(lsp.buf.list_workspace_folders())) + end, bufopts) + keymap("n", "rn", lsp.buf.rename, opt("[l]sp [R]ename")) + keymap("n", "lc", lsp.buf.code_action, opt("[l]sp [C]ode Action")) + keymap("n", "lf", function() + lsp.buf.format({ + async = true, + }) + end, opt("[l]sp [f]ormat buffer")) end - - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap = true, silent = true, buffer = bufnr } - vim.keymap.set("n", "gD", vim.lsp.buf.declaration, Append(bufopts, "desc", 'Go to declaration')) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, Append(bufopts, "desc", "Go to definition")) - vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, Append(bufopts, "desc", "Go to implementation")) - vim.keymap.set("n", "gr", require'telescope.builtin'.lsp_references, Append(bufopts, "desc", "Go to references")) - vim.keymap.set("n", "", vim.lsp.buf.signature_help, bufopts) - vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, bufopts) - vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, bufopts) - vim.keymap.set("n", "wl", function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, bufopts) - vim.keymap.set("n", "D", vim.lsp.buf.type_definition, bufopts) - vim.keymap.set("n", "rn", vim.lsp.buf.rename, bufopts) - vim.keymap.set("n", "ca", vim.lsp.buf.code_action, bufopts) - vim.keymap.set("n", "lf", function() - vim.lsp.buf.format({ - async = true, - }) - end, bufopts) -end +}) -- Add the border on hover and on signature help popup window -local handlers = { - ['textDocument/hover'] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }), - ['textDocument/signatureHelp'] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }), -} +vim.o.winborder = 'rounded' -- Add border to the diagnostic popup window vim.diagnostic.config({ @@ -65,76 +63,13 @@ vim.diagnostic.config({ underline = true, update_in_insert = false, -- Don't update diagnostics in insert mode severity_sort = true, -- Sort diagnostics by severity - float = { border = "rounded" }, + jump = { float = true }, }) -local capabilities = require('cmp_nvim_lsp').default_capabilities() +keymap("n", "e", vim.diagnostic.open_float, opts) +keymap("n", "q", vim.diagnostic.setloclist, opts) -require("lspconfig").lua_ls.setup({ - on_attach = on_attach, - settings = { - Lua = { - format = { - enable = true, - defaultConfig = { - indent_style = "space", - indent_size = "2", - } - }, - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - } - }, - capabilities = capabilities, - handlers = handlers -}) -require("lspconfig").gopls.setup { capabilities = capabilities, handlers = handlers, on_attach = on_attach, - cmd = IsYandex and { "/home/dmchumak/.ya/tools/v3/gopls-linux/gopls" }, - root_dir = IsYandex and require('lspconfig').util.root_pattern("YAOWNERS", "ya.make", ".arcadia.root", ".cloudia.root", "go.work", "go.mod", ".git"), - -- settings = { - -- gopls = { - -- arcadiaIndexDirs = { - -- "/home/horseinthesky/bl/cloud-go/cloud/cloud-go/cloudgate", - -- }, - -- }, - -- }, -} -require("lspconfig").bashls.setup { capabilities = capabilities, handlers = handlers, - on_attach = on_attach, - settings = { - bashIde = { - globPattern = "*@(.sh|.inc|.bash|.command)" - } - } -} -require("lspconfig").pyright.setup { capabilities = capabilities, handlers = handlers, - on_attach = on_attach, - -- more details on configuring pyright can be found here - -- https://microsoft.github.io/pyright/#/settings?id=pyright-settings - settings = { - python = { - analysis = { - include = { - '~/arcadia', - '~/arcadia/yt/python', - '~/arcadia/contrib/libs/protobuf/python', - '~/arcadia/contrib/python', - } - } - } - } -} +vim.lsp.enable("lua_ls") +vim.lsp.enable("bashls") +vim.lsp.enable("gopls") +vim.lsp.enable("basedpyright") diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua index a9adf06..ecd2604 100644 --- a/nvim/lua/plugins/init.lua +++ b/nvim/lua/plugins/init.lua @@ -14,10 +14,6 @@ vim.opt.rtp:prepend(lazypath) local plugins = { "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", - { - "neovim/nvim-lspconfig", - dependencies = { 'hrsh7th/cmp-nvim-lsp' } - }, { 'projekt0n/github-nvim-theme', name = 'github-theme', @@ -51,9 +47,8 @@ local plugins = { "folke/which-key.nvim", event = "VeryLazy", opts = { - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below + preset = "modern", + show_help = false, -- workaround for border glitch https://github.com/folke/which-key.nvim/issues/967#issuecomment-2842309305 }, keys = { {