From 9d774906860bea4105a054095d843d8d656b569e Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 23 Feb 2026 15:58:07 +0900 Subject: nvim/lsp: update LSP settings for Nvim 0.11 changes --- .config/nvim/lua/vimrc/lsp.lua | 47 +++++++++++++++++++++ .config/nvim/lua/vimrc/plugins.lua | 84 +------------------------------------- 2 files changed, 48 insertions(+), 83 deletions(-) create mode 100644 .config/nvim/lua/vimrc/lsp.lua (limited to '.config/nvim/lua/vimrc') diff --git a/.config/nvim/lua/vimrc/lsp.lua b/.config/nvim/lua/vimrc/lsp.lua new file mode 100644 index 0000000..e2932a7 --- /dev/null +++ b/.config/nvim/lua/vimrc/lsp.lua @@ -0,0 +1,47 @@ +local is_deno_repo = vim.fs.root(0, { 'deno.json', 'deno.jsonc' }) ~= nil + +local servers = { 'gopls', 'phpactor', 'zls', 'efm' } +if is_deno_repo then + table.insert(servers, 'denols') +else + table.insert(servers, 'ts_ls') +end + +vim.lsp.enable(servers) + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(e) + local client = assert(vim.lsp.get_client_by_id(e.data.client_id)) + + if client:supports_method('textDocument/completion') then + vim.lsp.completion.enable(true, client.id, e.buf, { autotrigger = true }) + end + + if client:supports_method('textDocument/formatting') then + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format({ + bufnr = e.buf, + id = client.id, + async = true, + filter = function(client) return client.name ~= "ts_ls" end, + }) + end, { buffer = e.buf }) + + if not client:supports_method('textDocument/willSaveWaitUntil') then + vim.api.nvim_create_autocmd('BufWritePre', { + group = vim.api.nvim_create_augroup('UserLspConfig', { clear = false }), + buffer = e.buf, + callback = function() + vim.lsp.buf.format({ + bufnr = e.buf, + id = client.id, + timeout_ms = 5000, + filter = function(client) return client.name ~= "ts_ls" end, + }) + end + }) + end + end + end, +}) diff --git a/.config/nvim/lua/vimrc/plugins.lua b/.config/nvim/lua/vimrc/plugins.lua index ca78f87..bddf281 100644 --- a/.config/nvim/lua/vimrc/plugins.lua +++ b/.config/nvim/lua/vimrc/plugins.lua @@ -611,89 +611,7 @@ return { { 'neovim/nvim-lspconfig', config = function() - local lspconfig = require('lspconfig') - - -- TODO - -- Enable denols xor ts_ls. - local is_deno_repo - if vim.fn.executable('deno') == 1 then - is_deno_repo = vim.fs.root(0, {"deno.json", "deno.jsonc"}) ~= nil - else - is_deno_repo = false - end - - if vim.fn.executable('typescript-language-server') == 1 then - if not is_deno_repo then - lspconfig.ts_ls.setup({}) - end - end - if vim.fn.executable('deno') == 1 then - if is_deno_repo then - lspconfig.denols.setup({}) - end - end - if vim.fn.executable('gopls') == 1 then - lspconfig.gopls.setup({}) - end - if vim.fn.executable('phpactor') == 1 then - lspconfig.phpactor.setup({}) - end - if vim.fn.executable('zls') == 1 then - lspconfig.zls.setup({}) - end - if vim.fn.executable('efm-langserver') == 1 then - local biome_conf = { - rootMarkers = {"biome.json"}, - formatCommand = 'node_modules/.bin/biome format --stdin-file-path "${INPUT}"', - formatStdin = true, - } - lspconfig.efm.setup({ - init_options = { documentFormatting = true }, - settings = { - rootMarkers = {".git/"}, - languages = { - json = { - { - formatCommand = "reparojson -q", - formatStdin = true, - }, - }, - javascript = {biome_conf}, - javascriptreact = {biome_conf}, - ["javascript.jsx"] = {biome_conf}, - typescript = {biome_conf}, - typescriptreact = {biome_conf}, - ["typescript.jsx"] = {biome_conf}, - }, - } - }) - end - - vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('UserLspConfig', {}), - callback = function(e) - vim.bo[e.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' - - local opts = { buffer = e.buf } - vim.keymap.set('n', 'f', function() - vim.lsp.buf.format({ - async = true, - filter = function(client) return client.name ~= "ts_ls" end, - }) - end, opts) - - vim.api.nvim_create_autocmd('BufWritePre', { - buffer = e.buf, - callback = function() - vim.lsp.buf.format({ - async = false, - timeout_ms = 5000, - filter = function(client) return client.name ~= "ts_ls" end, - }) - end - }) - end, - }) + require('vimrc.lsp') end, }, } -- cgit v1.3-1-g0d28