diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-02-23 15:58:07 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-02-23 15:59:24 +0900 |
| commit | 9d774906860bea4105a054095d843d8d656b569e (patch) | |
| tree | 5e4cf9e40b501a99e55d9d35b6d69fc166eacf6e /.config/nvim/lua/vimrc/lsp.lua | |
| parent | bf63936430497e843a26888924095ccb6747b0b9 (diff) | |
| download | dotfiles-9d774906860bea4105a054095d843d8d656b569e.tar.gz dotfiles-9d774906860bea4105a054095d843d8d656b569e.tar.zst dotfiles-9d774906860bea4105a054095d843d8d656b569e.zip | |
nvim/lsp: update LSP settings for Nvim 0.11 changes
Diffstat (limited to '.config/nvim/lua/vimrc/lsp.lua')
| -rw-r--r-- | .config/nvim/lua/vimrc/lsp.lua | 47 |
1 files changed, 47 insertions, 0 deletions
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', '<space>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, +}) |
