From ea27ecbe142dc31c4879f722921b3e130666b7dc Mon Sep 17 00:00:00 2001 From: 409 <409dev@protonmail.com> Date: Thu, 10 Jul 2025 00:18:26 +0200 Subject: [PATCH] fix lsp --- lazy-lock.json | 43 +++--- lua/409/init.lua | 3 +- lua/409/lsp.lua | 188 +++++++++++++++++++++++ lua/409/plugins/completion.lua | 7 +- lua/409/plugins/lsp.lua | 267 --------------------------------- lua/409/plugins/mason.lua | 37 +++++ lua/409/plugins/treesitter.lua | 1 + 7 files changed, 255 insertions(+), 291 deletions(-) create mode 100644 lua/409/lsp.lua delete mode 100644 lua/409/plugins/lsp.lua create mode 100644 lua/409/plugins/mason.lua diff --git a/lazy-lock.json b/lazy-lock.json index e608c2d..84afddb 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,49 +1,48 @@ { "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, - "alpha-nvim": { "branch": "main", "commit": "de72250e054e5e691b9736ee30db72c65d560771" }, + "alpha-nvim": { "branch": "main", "commit": "2b3cbcdd980cae1e022409289245053f62fb50f6" }, "barbecue.nvim": { "branch": "main", "commit": "cd7e7da622d68136e13721865b4d919efd6325ed" }, "blink.cmp": { "branch": "main", "commit": "485c03400608cb6534bbf84da8c1c471fc4808c0" }, - "catppuccin": { "branch": "main", "commit": "8162a4bd9afb42837a655e404d1f937a87ba95e6" }, - "conform.nvim": { "branch": "master", "commit": "6feb2f28f9a9385e401857b21eeac3c1b66dd628" }, + "catppuccin": { "branch": "main", "commit": "fa42eb5e26819ef58884257d5ae95dd0552b9a66" }, + "conform.nvim": { "branch": "master", "commit": "973f3cb73887d510321653044791d7937c7ec0fa" }, "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, - "flutter-tools.nvim": { "branch": "main", "commit": "d5bb1dc3db78d7ab65dd8c5a6f32a38e383b9cb1" }, - "fzf-lua": { "branch": "main", "commit": "8adf950093af5361621cf52208d64995b1af78b5" }, - "gitsigns.nvim": { "branch": "main", "commit": "8b729e489f1475615dc6c9737da917b3bc163605" }, + "flutter-tools.nvim": { "branch": "main", "commit": "65b7399804315a1160933b64292d3c5330aa4e9f" }, + "fzf-lua": { "branch": "main", "commit": "f8805989fc8f164ea3fab37bdec963add9576964" }, + "gitsigns.nvim": { "branch": "main", "commit": "7bbc674278f22376850576dfdddf43bbc17e62b5" }, "harpoon": { "branch": "harpoon2", "commit": "ed1f853847ffd04b2b61c314865665e1dadf22c7" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lazydev.nvim": { "branch": "main", "commit": "2367a6c0a01eb9edb0464731cc0fb61ed9ab9d2c" }, - "lsp-zero.nvim": { "branch": "v2.x", "commit": "320d5913bc5a0b0f15537e32777331d2323ab7f8" }, - "lualine.nvim": { "branch": "master", "commit": "0c6cca9f2c63dadeb9225c45bc92bb95a151d4af" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "3856bbb0da214d1f2f3d5a2dd3fea26591f930f9" }, - "mason.nvim": { "branch": "main", "commit": "9eaedb864cdadc29c6eb7d761a6c0d8aee26c91b" }, + "lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "7815740f4d0afb74ada00956c36e18ad695ed9e3" }, + "mason.nvim": { "branch": "main", "commit": "8024d64e1330b86044fed4c8494ef3dcd483a67c" }, "mini.indentscope": { "branch": "main", "commit": "8af2569a7d7fd37300dfa760e44e71efbbf322fd" }, "mini.surround": { "branch": "main", "commit": "5aab42fcdcf31fa010f012771eda5631c077840a" }, "neogen": { "branch": "main", "commit": "d7f9461727751fb07f82011051338a9aba07581d" }, "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, - "nui.nvim": { "branch": "main", "commit": "f535005e6ad1016383f24e39559833759453564e" }, - "nvim-lspconfig": { "branch": "master", "commit": "f610208989e9c03561f9f601db3133f6ae398fcd" }, + "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, + "nvim-lspconfig": { "branch": "master", "commit": "592916db3f4ecdf062962b3aa83583aebe3c4a14" }, "nvim-navic": { "branch": "master", "commit": "f887d794a0f4594882814d7780980a949200a238" }, "nvim-spectre": { "branch": "master", "commit": "72f56f7585903cd7bf92c665351aa585e150af0f" }, "nvim-tree-docs": { "branch": "master", "commit": "5db023d783da1e55339e5e25caaf72a59597e626" }, - "nvim-treesitter": { "branch": "master", "commit": "066fd6505377e3fd4aa219e61ce94c2b8bdb0b79" }, + "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "1b212c2eee76d787bbea6aa5e92a2b534e7b4f8f" }, - "nvim-web-devicons": { "branch": "master", "commit": "1fb58cca9aebbc4fd32b086cb413548ce132c127" }, + "nvim-web-devicons": { "branch": "master", "commit": "a1366758b3a232036dc97be8ca41184aa3f50506" }, "obsidian.nvim": { "branch": "main", "commit": "ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b" }, - "oil.nvim": { "branch": "master", "commit": "685cdb4ffa74473d75a1b97451f8654ceeab0f4a" }, + "oil.nvim": { "branch": "master", "commit": "bbad9a76b2617ce1221d49619e4e4b659b3c61fc" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, - "render-markdown.nvim": { "branch": "main", "commit": "dac01bd6660af337613e8cfcb23a4aec5d3c0e38" }, - "tailwind-tools.nvim": { "branch": "master", "commit": "aa9c7497420b34cdf045d0818a7041cc39a91df6" }, + "render-markdown.nvim": { "branch": "main", "commit": "c3012098bd44381e3b96bbbbbcc21a54d45a286c" }, + "tailwind-tools.nvim": { "branch": "master", "commit": "fbe982901d4508b0dcd80e07addf0fcb6dab6c49" }, "telescope.nvim": { "branch": "master", "commit": "b4da76be54691e854d3e0e02c36b0245f945c2c7" }, "tiny-devicons-auto-colors.nvim": { "branch": "main", "commit": "51f548421f8a74680eff27d283c9d5ea6e8d0074" }, "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, "trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" }, - "tsc.nvim": { "branch": "main", "commit": "5bd25bb5c399b6dc5c00392ade6ac6198534b53a" }, - "undotree": { "branch": "master", "commit": "b951b87b46c34356d44aa71886aecf9dd7f5788a" }, + "tsc.nvim": { "branch": "main", "commit": "8c1b4ec6a48d038a79ced8674cb15e7db6dd8ef0" }, + "undotree": { "branch": "master", "commit": "15d91b0afe04ea9ba5cd53e30190d1602af9a925" }, "vim-dadbod": { "branch": "master", "commit": "e95afed23712f969f83b4857a24cf9d59114c2e6" }, "vim-dadbod-completion": { "branch": "master", "commit": "a8dac0b3cf6132c80dc9b18bef36d4cf7a9e1fe6" }, - "vim-dadbod-ui": { "branch": "master", "commit": "460432301a5cb280ea265ddfa15c9f3dcd1d26b7" }, - "vim-fugitive": { "branch": "master", "commit": "4a745ea72fa93bb15dd077109afbb3d1809383f2" }, + "vim-dadbod-ui": { "branch": "master", "commit": "2900a1617b3df1a48683d872eadbe1101146a49a" }, + "vim-fugitive": { "branch": "master", "commit": "593f831d6f6d779cbabb70a4d1e6b1b1936a88af" }, "vim-pencil": { "branch": "master", "commit": "6d70438a8886eaf933c38a7a43a61adb0a7815ed" }, - "vim-tmux-navigator": { "branch": "master", "commit": "0ecda542c0bd3ea26444044c7f03e469a6bb0bff" } + "vim-tmux-navigator": { "branch": "master", "commit": "412c474e97468e7934b9c217064025ea7a69e05e" } } diff --git a/lua/409/init.lua b/lua/409/init.lua index 40395af..b964adf 100755 --- a/lua/409/init.lua +++ b/lua/409/init.lua @@ -2,9 +2,10 @@ local M = {} function M.setup() require("409.set") - require("409.remap") + require("409.remap") require("409.lazy") require("409.autocmd") + require("409.lsp") end return M diff --git a/lua/409/lsp.lua b/lua/409/lsp.lua new file mode 100644 index 0000000..917fe42 --- /dev/null +++ b/lua/409/lsp.lua @@ -0,0 +1,188 @@ +vim.diagnostic.config({ + virtual_text = true, + update_in_insert = true, + float = { + border = "single", + }, +}) + +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(event) + local bufnr = event.buf + local client = vim.lsp.get_client_by_id(event.data.client_id) + + if not client then + return + end + + if vim.bo[bufnr].filetype == "markdown" then + return + end + + vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, { + pattern = { "*.hl", "hypr*.conf" }, + callback = function(e) + vim.lsp.start({ + name = "hyprlang", + cmd = { "hyprls" }, + root_dir = vim.fn.getcwd(), + }) + end, + }) + + local lsp_opts = { buffer = bufnr, remap = false } + + vim.keymap.set("n", "gd", function() + vim.lsp.buf.definition({ + on_list = function(list) + vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true }) + end, + }) + end, { buffer = bufnr, remap = false, nowait = true }) + vim.keymap.set("n", "gi", function() + vim.lsp.buf.implementation({ + on_list = function(list) + vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true }) + end, + }) + end, lsp_opts) + vim.keymap.set("n", "K", function() + vim.lsp.buf.hover() + end, lsp_opts) + vim.keymap.set("n", "vws", function() + vim.lsp.buf.workspace_symbol() + end, lsp_opts) + vim.keymap.set("n", "vd", function() + vim.diagnostic.open_float() + end, lsp_opts) + vim.keymap.set("n", "[d", function() + vim.diagnostic.jump({ count = 1 }) + end, lsp_opts) + vim.keymap.set("n", "]d", function() + vim.diagnostic.jump({ count = -1 }) + end, lsp_opts) + vim.keymap.set("n", "vca", function() + vim.lsp.buf.code_action() + end, lsp_opts) + vim.keymap.set("n", "vrr", function() + vim.lsp.buf.references() + end, lsp_opts) + vim.keymap.set("n", "vrn", function() + vim.lsp.buf.rename() + end, lsp_opts) + vim.keymap.set("i", "", function() + vim.lsp.buf.signature_help() + end, lsp_opts) + end +}) + +vim.lsp.config.tailwindcss = { + filetypes_exclude = { "markdown", "rust", "proto", "sh", "gitignore", "toml", "json", "fugitive" }, + hovers = true, + suggestions = true, + root_dir = function(fname) + local root_pattern = require("lspconfig").util.root_pattern( + "tailwind.config.cjs", + "talwind.config.js", + "tailwind.config.ts", + "postcss.config.js", + "postcss.config.ts" + ) + + return root_pattern(fname) + end, +} + +vim.lsp.config.vtsls = { + filetypes = { + "svelte", + "vue", + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + settings = { + vtsls = { + ts_ls = { + globalPlugins = { + { + name = "typescript-svelte-plugin", + location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin", + enableForWorkspaceTypeScriptVersions = true, + }, + }, + }, + tsserver = { + globalPlugins = { + { + name = "typescript-svelte-plugin", + location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin", + enableForWorkspaceTypeScriptVersions = true, + }, { + name = "@vue/typescript-plugin", + location = vim.fn.expand "$MASON/packages" .. + "/vue-language-server" .. "/node_modules/@vue/language-server", + languages = { "vue" }, + configNamespace = 'typescript', + }, + }, + }, + }, + typescript = { + preferences = { + quoteStyle = "single", + }, + updateImportsOnFileMove = { + enabled = "always", + }, + suggest = { + completeFunctionCalls = true, + }, + }, + javascript = { + preferences = { + quoteStyle = "single", + }, + }, + }, +} + +vim.lsp.config.vue_ls = { + on_init = function(client) + client.handlers['tsserver/request'] = function(_, result, context) + local clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'vtsls' }) + if #clients == 0 then + vim.notify('Could not found `vtsls` lsp client, vue_lsp would not work without it.', + vim.log.levels.ERROR) + return + end + local ts_client = clients[1] + + local param = unpack(result) + local id, command, payload = unpack(param) + ts_client:exec_cmd({ + title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd` + command = 'typescript.tsserverRequest', + arguments = { + command, + payload, + }, + }, { bufnr = context.bufnr }, function(_, r) + local response_data = { { id, r.body } } + ---@diagnostic disable-next-line: param-type-mismatch + client:notify('tsserver/response', response_data) + end) + end + end, +} + +vim.lsp.config.svelte = { + capabilities = { + workspace = { + didChangeWatchedFiles = { dynamicRegistration = true }, + }, + }, +} diff --git a/lua/409/plugins/completion.lua b/lua/409/plugins/completion.lua index 217744c..29284ce 100644 --- a/lua/409/plugins/completion.lua +++ b/lua/409/plugins/completion.lua @@ -122,7 +122,12 @@ return { }, opts_extend = { "sources.default" }, config = function(_, opts) - require("blink.cmp").setup(opts) + local blink = require("blink.cmp") + + blink.setup(opts) + + local capabilities = blink.get_lsp_capabilities() + vim.lsp.config("*", { capabilities = capabilities }) end, }, } diff --git a/lua/409/plugins/lsp.lua b/lua/409/plugins/lsp.lua deleted file mode 100644 index 9379d99..0000000 --- a/lua/409/plugins/lsp.lua +++ /dev/null @@ -1,267 +0,0 @@ -return { - { - "VonHeikemen/lsp-zero.nvim", - branch = "v2.x", - dependencies = { - { "neovim/nvim-lspconfig" }, - { - "williamboman/mason.nvim", - build = function() - ---@diagnostic disable-next-line: param-type-mismatch - pcall(vim.cmd, "MasonUpdate") - end, - }, - { "williamboman/mason-lspconfig.nvim" }, - }, - config = function() - local lsp = require("lsp-zero") - - -- Hyprlang LSP - vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, { - pattern = { "*.hl", "hypr*.conf" }, - callback = function(event) - vim.lsp.start({ - name = "hyprlang", - cmd = { "hyprls" }, - root_dir = vim.fn.getcwd(), - }) - end, - }) - - lsp.on_attach(function(client, bufnr) - if vim.bo[bufnr].filetype == "markdown" then - return - end - - local lsp_opts = { buffer = bufnr, remap = false } - - vim.keymap.set("n", "gd", function() - vim.lsp.buf.definition({ - on_list = function(list) - vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true }) - end, - }) - end, { buffer = bufnr, remap = false, nowait = true }) - vim.keymap.set("n", "gi", function() - vim.lsp.buf.implementation({ - on_list = function(list) - vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true }) - end, - }) - end, lsp_opts) - vim.keymap.set("n", "K", function() - vim.lsp.buf.hover() - end, lsp_opts) - vim.keymap.set("n", "vws", function() - vim.lsp.buf.workspace_symbol() - end, lsp_opts) - vim.keymap.set("n", "vd", function() - vim.diagnostic.open_float() - end, lsp_opts) - vim.keymap.set("n", "[d", function() - vim.diagnostic.jump({ count = 1 }) - end, lsp_opts) - vim.keymap.set("n", "]d", function() - vim.diagnostic.jump({ count = -1 }) - end, lsp_opts) - vim.keymap.set("n", "vca", function() - vim.lsp.buf.code_action() - end, lsp_opts) - vim.keymap.set("n", "vrr", function() - vim.lsp.buf.references() - end, lsp_opts) - vim.keymap.set("n", "vrn", function() - vim.lsp.buf.rename() - end, lsp_opts) - vim.keymap.set("i", "", function() - vim.lsp.buf.signature_help() - end, lsp_opts) - end) - end, - }, - { - "neovim/nvim-lspconfig", - dependencies = { - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - "saghen/blink.cmp", - }, - opts = { - diagnostics = { - virtual_text = true, - update_in_insert = true, - float = { - border = "single", - }, - }, - inlay_hints = { - enabled = false, - }, - servers = { - tailwindcss = { - filetypes_exclude = { "markdown", "rust", "proto", "sh", "gitignore", "toml", "json", "fugitive" }, - hovers = true, - suggestions = true, - root_dir = function(fname) - local root_pattern = require("lspconfig").util.root_pattern( - "tailwind.config.cjs", - "talwind.config.js", - "tailwind.config.ts", - "postcss.config.js", - "postcss.config.ts" - ) - - return root_pattern(fname) - end, - }, - vtsls = { - filetypes = { - "javascript", - "javascriptreact", - "javascript.jsx", - "typescript", - "typescriptreact", - "typescript.tsx", - }, - settings = { - vtsls = { - ts_ls = { - globalPlugins = { - { - name = "typescript-svelte-plugin", - location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin", - enableForWorkspaceTypeScriptVersions = true, - }, - }, - }, - tsserver = { - globalPlugins = { - { - name = "typescript-svelte-plugin", - location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin", - enableForWorkspaceTypeScriptVersions = true, - }, - }, - }, - }, - typescript = { - preferences = { - quoteStyle = "single", - }, - updateImportsOnFileMove = { - enabled = "always", - }, - suggest = { - completeFunctionCalls = true, - }, - }, - javascript = { - preferences = { - quoteStyle = "single", - }, - }, - }, - }, - svelte = { - capabilities = { - workspace = { - didChangeWatchedFiles = { dynamicRegistration = true }, - }, - }, - }, - }, - }, - config = function(_, opts) - local lspconfig = require("lspconfig") - local lsp = require("lsp-zero") - - vim.api.nvim_create_autocmd("LspAttach", { - callback = function(args) - local buffer = args.buf - local lsp_opts = { buffer = buffer, remap = false, nowait = true } - local client = vim.lsp.get_client_by_id(args.data.client_id) - - if - opts.inlay_hints.enabled - and client ~= nil - and client.supports_method(client, "textDocument/inlayHint") - then - vim.lsp.inlay_hint.enable(true) - end - - if client ~= nil then - if client.name == "svelte" then - vim.api.nvim_create_autocmd("BufWritePost", { - pattern = { "*.svelte", "*.js", "*.ts" }, - group = vim.api.nvim_create_augroup("svelte_ondidchangetsorjsfile", { clear = true }), - callback = function(ctx) - client.notify(client, "$/onDidChangeTsOrJsFile", { uri = ctx.match }) - end, - }) - end - - if vim.bo[buffer].filetype == "svelte" then - vim.api.nvim_create_autocmd("BufWritePost", { - pattern = { "*.svelte", "*.js", "*.ts" }, - callback = function(ctx) - client.notify(client, "$/onDidChangeTsOrJsFile", { uri = ctx.match }) - end, - }) - end - end - end, - }) - - vim.diagnostic.config(opts.diagnostics) - - require("lspconfig.ui.windows").default_options = { - border = "single", - } - - require("mason-lspconfig").setup({ - ensure_installed = { - "vtsls", - "eslint", - "lua_ls", - "jsonls", - "html", - "tailwindcss", - "pylsp", - "dockerls", - "bashls", - "marksman", - "rust_analyzer", - }, - handlers = { - function(server_name) - if lspconfig[server_name] ~= nil then - local config = opts.servers[server_name] or {} - config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities) - - lspconfig[server_name].setup(config) - end - end, - lua_ls = function() - local config = lsp.nvim_lua_ls() - config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities) - - require("lspconfig").lua_ls.setup(config) - end, - }, - }) - end, - }, - { - "williamboman/mason.nvim", - dependencies = {}, - opts = { - PATH = "append", - ui = { - border = "single", - }, - }, - config = function(_, opts) - require("mason").setup(opts) - end, - }, -} diff --git a/lua/409/plugins/mason.lua b/lua/409/plugins/mason.lua new file mode 100644 index 0000000..edae9b7 --- /dev/null +++ b/lua/409/plugins/mason.lua @@ -0,0 +1,37 @@ +return { + { + "williamboman/mason.nvim", + dependencies = {}, + opts = { + PATH = "append", + ui = { + border = "single", + }, + }, + config = function(_, opts) + require("mason").setup(opts) + end, + }, + { + "mason-org/mason-lspconfig.nvim", + opts = { + "vtsls", + "eslint", + "lua_ls", + "jsonls", + "html", + "tailwindcss", + "pylsp", + "dockerls", + "bashls", + "marksman", + "rust_analyzer", + }, + dependencies = { + { + "mason-org/mason.nvim", opts = {} + }, + "neovim/nvim-lspconfig", + }, + } +} diff --git a/lua/409/plugins/treesitter.lua b/lua/409/plugins/treesitter.lua index 04b80cf..adb98fc 100644 --- a/lua/409/plugins/treesitter.lua +++ b/lua/409/plugins/treesitter.lua @@ -2,6 +2,7 @@ return { { "nvim-treesitter/nvim-treesitter", dependencies = { + "neovim/nvim-lspconfig", "nvim-treesitter/nvim-tree-docs", "JoosepAlviste/nvim-ts-context-commentstring", },