From da9448a88c274a60adc0e38ee2d73d71198f2aab Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 16 Jan 2022 15:36:28 +1100 Subject: [PATCH] neovim breaking changes: offset_encoding --- lua/navigator/definition.lua | 6 ++++-- lua/navigator/dochighlight.lua | 9 ++++++--- lua/navigator/formatting.lua | 17 ++++++++--------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lua/navigator/definition.lua b/lua/navigator/definition.lua index 711c3d3..42150ae 100644 --- a/lua/navigator/definition.lua +++ b/lua/navigator/definition.lua @@ -19,15 +19,17 @@ local definition_hdlr = util.mk_handler(function(err, locations, ctx, _) vim.notify('Definition not found') return end + + local client = vim.lsp.get_client_by_id(ctx.client_id) if vim.tbl_islist(locations) then if #locations > 1 then local items = locations_to_items(locations) gui.new_list_view({ items = items, api = 'Definition' }) else - vim.lsp.util.jump_to_location(locations[1]) + vim.lsp.util.jump_to_location(locations[1], client.offset_encoding) end else - vim.lsp.util.jump_to_location(locations) + vim.lsp.util.jump_to_location(locations, client.offset_encoding) end end) diff --git a/lua/navigator/dochighlight.lua b/lua/navigator/dochighlight.lua index 993564e..98e04b2 100644 --- a/lua/navigator/dochighlight.lua +++ b/lua/navigator/dochighlight.lua @@ -152,8 +152,9 @@ local handle_document_highlight = mk_handler(function(_, result, ctx) return before(a.range, b.range) end) references[ctx.bufnr] = result - - vim.lsp.util.buf_highlight_references(ctx.bufnr, result, ctx.client_id) + local client_id = ctx.client_id + local client = vim.lsp.get_client_by_id(client_id) + vim.lsp.util.buf_highlight_references(ctx.bufnr, result, client.offset_encoding) end) -- modify from vim-illuminate local function goto_adjent_reference(opt) @@ -244,8 +245,10 @@ local function documentHighlight() vim.lsp.util.buf_clear_references(bufnr) return end + local client_id = ctx.client_id + local client = vim.lsp.get_client_by_id(client_id) vim.lsp.util.buf_clear_references(bufnr) - vim.lsp.util.buf_highlight_references(bufnr, result) + vim.lsp.util.buf_highlight_references(bufnr, result, client.offset_encoding) table.sort(result, function(a, b) return before(a.range, b.range) end) diff --git a/lua/navigator/formatting.lua b/lua/navigator/formatting.lua index afff7fd..2d61df3 100644 --- a/lua/navigator/formatting.lua +++ b/lua/navigator/formatting.lua @@ -1,26 +1,26 @@ -- https://github.com/wention/dotfiles/blob/master/.config/nvim/lua/config/lsp.lua -- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/handlers.lua -local mk_handler = require"navigator.util".mk_handler +local mk_handler = require('navigator.util').mk_handler return { format_hdl = mk_handler(function(err, result, ctx, cfg) -- FIXME: bufnr is nil if err ~= nil or result == nil then return end - local util = require "navigator.util" + local util = require('navigator.util') local log = util.log + + local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding + -- If the buffer hasn't been modified before the formatting has finished, -- update the buffer -- if not vim.api.nvim_buf_get_option(ctx.bufnr, 'modified') then vim.defer_fn(function() - log('fmt callback') - if ctx.bufnr == vim.api.nvim_get_current_buf() - or not vim.api.nvim_buf_get_option(ctx.bufnr, 'modified') then - + if ctx.bufnr == vim.api.nvim_get_current_buf() or not vim.api.nvim_buf_get_option(ctx.bufnr, 'modified') then local view = vim.fn.winsaveview() - vim.lsp.util.apply_text_edits(result, ctx.bufnr) + vim.lsp.util.apply_text_edits(result, ctx.bufnr, offset_encoding) vim.fn.winrestview(view) -- FIXME: commented out as a workaround -- if bufnr == vim.api.nvim_get_current_buf() then @@ -30,7 +30,6 @@ return { vim.api.nvim_command('silent doautocmd User FormatterPost') -- end end - end, 100) - end) + end), }