neovim

Personal neovim configuration files
git clone git://gtms.dev/neovim
Log | Files | Refs

commit 079ad4225cc4e94b569645dc83cc394b22ad440b
parent 4f0b24beaccbcaee1fe89cb1f7b59c91a478ba9e
Author: Tomas Nemec <owl@gtms.dev>
Date:   Tue, 16 Jan 2024 07:48:14 +0100

update

Diffstat:
Mafter/plugin/lsp.lua | 8++++----
Mftplugin/dart.lua | 21+--------------------
Mftplugin/html.lua | 21+--------------------
Alua/tms/lsp/dart.lua | 28++++++++++++++++++++++++++++
Mlua/tms/p/rename_file.lua | 30+++++++++++++++++++++++++++---
5 files changed, 61 insertions(+), 47 deletions(-)

diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua @@ -37,7 +37,7 @@ local function keymap(client, buf) if client.supports_method('textDocument/documentHighlight') then vim.keymap.set('n', '<leader>k', lb.document_highlight, opt('LSP Highlight')) vim.api.nvim_create_autocmd('CursorMoved', - { group = lsp_group, buffer = buf, callback = vim.lsp.buf.clear_references }) + { group = lsp_group, buffer = buf, callback = vim.lsp.buf.clear_references }) end if client.supports_method('textDocument/inlayHint') then vim.keymap.set('n', 'gH', function() @@ -99,13 +99,13 @@ end -- mason if pcall(require, 'mason') then - require 'mason'.setup() + require'mason'.setup() local mlsp = require 'mason-lspconfig' mlsp.setup() mlsp.setup_handlers { function(name) - local opts = require 'tms.lsp'.make_opts(name) - require 'lspconfig'[name].setup(opts) + local opts = require'tms.lsp'.make_opts(name) + require'lspconfig'[name].setup(opts) end, ['jsonls'] = function() end, diff --git a/ftplugin/dart.lua b/ftplugin/dart.lua @@ -24,26 +24,7 @@ if string.find(full_path, '%.pub%-cache') then vim.bo.modifiable = false end -vim.lsp.start { - name = 'dartls', - cmd = { -- - 'dart', - 'language-server', - '--protocol=lsp', - '--port=10000', - '--instrumentation-log-file=/tmp/dart-plugin-log', - }, - root_dir = vim.fs.dirname(vim.fs.find({ 'pubspec.yaml', '.git' }, { upward = true })[1]), - capabilities = require'tms.lsp'.capabilities(), - init_options = { closingLabels = true, outline = true, flutterOutline = true }, - settings = { dart = { completeFunctionCalls = true, showTodos = true, lineLength = 120 } }, - handlers = { - ['typeHierarchy/subtypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), - ['typeHierarchy/supertypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), - ['dart/textDocument/publishClosingLabels'] = require'dart-tools.lsp.labels'.handler(), - ['dart/textDocument/super'] = vim.lsp.handlers['textDocument/definition'], - }, -} +require'tms.lsp.dart'.start() vim.keymap.set('n', '<leader>ar', ':make<cr>', { desc = 'Dart Run' }) vim.keymap.set('n', '<leader>at', ':DartTest<cr>', { desc = 'Dart Test' }) diff --git a/ftplugin/html.lua b/ftplugin/html.lua @@ -1,20 +1 @@ -vim.lsp.start { - name = 'dartls', - cmd = { -- - 'dart', - 'language-server', - '--protocol=lsp', - '--port=10000', - '--instrumentation-log-file=/tmp/dart-plugin-log', - }, - root_dir = vim.fs.dirname(vim.fs.find({ 'pubspec.yaml', '.git' }, { upward = true })[1]), - capabilities = require'tms.lsp'.capabilities(), - init_options = { closingLabels = true, outline = true, flutterOutline = true }, - settings = { dart = { completeFunctionCalls = true, showTodos = true, lineLength = 120 } }, - handlers = { - ['typeHierarchy/subtypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), - ['typeHierarchy/supertypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), - ['dart/textDocument/publishClosingLabels'] = require'dart-tools.lsp.labels'.handler(), - ['dart/textDocument/super'] = vim.lsp.handlers['textDocument/definition'], - }, -} +require'tms.lsp.dart'.start() diff --git a/lua/tms/lsp/dart.lua b/lua/tms/lsp/dart.lua @@ -0,0 +1,28 @@ +local M = {} + +local capabilities = { workspace = { fileOperations = { willRename = true } } } + +function M.start() + vim.lsp.start { + name = 'dartls', + cmd = { -- + 'dart', + 'language-server', + '--protocol=lsp', + '--port=10000', + '--instrumentation-log-file=/tmp/dart-plugin-log', + }, + root_dir = vim.fs.dirname(vim.fs.find({ 'pubspec.yaml', '.git' }, { upward = true })[1]), + capabilities = vim.tbl_deep_extend('force', require'tms.lsp'.capabilities(), capabilities), + init_options = { closingLabels = true, outline = true, flutterOutline = true }, + settings = { dart = { completeFunctionCalls = true, showTodos = true, lineLength = 120 } }, + handlers = { + ['typeHierarchy/subtypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), + ['typeHierarchy/supertypes'] = require'dart-tools.lsp.type_hierarchy'.handler(), + ['dart/textDocument/publishClosingLabels'] = require'dart-tools.lsp.labels'.handler(), + ['dart/textDocument/super'] = vim.lsp.handlers['textDocument/definition'], + }, + } +end + +return M diff --git a/lua/tms/p/rename_file.lua b/lua/tms/p/rename_file.lua @@ -1,5 +1,17 @@ local M = {} +local function make_rename_files_params(old_fname, new_fname) + return { + files = -- + { -- + { -- + oldUri = vim.uri_from_fname(old_fname), + newUri = vim.uri_from_fname(new_fname), + }, + }, + } +end + function M.rename_file() local old_fname = vim.api.nvim_buf_get_name(0) @@ -12,11 +24,23 @@ function M.rename_file() return end - if pcall(require, 'dart-tools.lsp') then - require('dart-tools.lsp').update_imports(old_fname, new_fname) + local hasDocumentChanges = false + for _, client in pairs(vim.lsp.get_clients()) do + if vim.tbl_get(client.server_capabilities, 'workspace', 'fileOperations', 'willRename') then + local params = make_rename_files_params(old_fname, new_fname) + local response = client.request_sync('workspace/willRenameFiles', params, nil, 0) + local result = response.result + if result then + -- documentChanges will actually change files on disk inside apply_workspace_edit + hasDocumentChanges = result.documentChanges ~= nil + vim.lsp.util.apply_workspace_edit(result, client.offset_encoding) + end + end end - vim.lsp.util.rename(old_fname, new_fname) + if not hasDocumentChanges then + vim.lsp.util.rename(old_fname, new_fname) + end end) end