From e882757fb2a2095d63b4725dc632980b20a02cd1 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 23 Sep 2022 17:25:13 +1000 Subject: [PATCH] update format_on_save setup --- README.md | 6 +++++- doc/navigator.txt | 8 +++++++- lua/navigator.lua | 6 +++++- lua/navigator/codeAction.lua | 25 ++++++++++++------------- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 81f716e..d64bd12 100644 --- a/README.md +++ b/README.md @@ -288,7 +288,11 @@ require'navigator'.setup({ code_lens_action = {enable = true, sign = true, sign_priority = 40, virtual_text = true}, document_highlight = true, -- LSP reference highlight, -- it might already supported by you setup, e.g. LunarVim - format_on_save = true, -- set to false to disable lsp code format on save (if you are using prettier/efm/formater etc) + format_on_save = true, -- {true|false} set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) + -- table: {enable = {'lua', 'go'}, disable = {'javascript', 'typescript'}} to enable/disable specific language + -- enable: a whitelist of language that will be formatted on save + -- disable: a blacklist of language that will not be formatted on save + -- function: function(bufnr) return true end to enable/disable lsp format on save format_options = {async=false}, -- async: disable by default, the option used in vim.lsp.buf.format({async={true|false}, name = 'xxx'}) disable_format_cap = {"sqls", "sumneko_lua", "gopls"}, -- a list of lsp disable format capacity (e.g. if you using efm or vim-codeformat etc), empty {} by default -- If you using null-ls and want null-ls format your code diff --git a/doc/navigator.txt b/doc/navigator.txt index b0cf6f3..1533335 100644 --- a/doc/navigator.txt +++ b/doc/navigator.txt @@ -294,7 +294,13 @@ Nondefault configuration example: -- own on_attach code_action = {enable = true, sign = true, sign_priority = 40, virtual_text = true}, code_lens_action = {enable = true, sign = true, sign_priority = 40, virtual_text = true}, - format_on_save = true, -- set to false to disable lsp code format on save (if you are using prettier/efm/formater etc) + + format_on_save = true, -- {true|false} set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) + -- table: {enable = {'lua', 'go'}, disable = {'javascript', 'typescript'}} to enable/disable specific language + -- enable: a whitelist of language that will be formatted on save + -- disable: a blacklist of language that will not be formatted on save + -- function: function(bufnr) return true end to enable/disable lsp format on save + disable_format_cap = {"sqls", "sumneko_lua", "gopls"}, -- a list of lsp disable format capacity (e.g. if you using efm or vim-codeformat etc), empty {} by default disable_lsp = {'pylsd', 'sqlls'}, -- a list of lsp server disabled for your project, e.g. denols and tsserver you may -- only want to enable one lsp server diff --git a/lua/navigator.lua b/lua/navigator.lua index c5beaaf..8434ce5 100755 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -65,7 +65,11 @@ _NgConfigValues = { update_in_insert = false, -- update diagnostic message in insert mode severity_sort = { reverse = true }, }, - format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) + format_on_save = true, -- {true|false} set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) + -- table: {enable = {'lua', 'go'}, disable = {'javascript', 'typescript'}} to enable/disable specific language + -- enable: a whitelist of language that will be formatted on save + -- disable: a blacklist of language that will not be formatted on save + -- function: function(bufnr) return true end to enable/disable lsp format on save format_options = { async = false }, -- async: disable by default, I saw something unexpected disable_nulls_codeaction_sign = true, -- do not show nulls codeactions (as it will alway has a valid action) disable_format_cap = {}, -- a list of lsp disable file format (e.g. if you using efm or vim-codeformat etc), empty by default diff --git a/lua/navigator/codeAction.lua b/lua/navigator/codeAction.lua index 2ead752..6978297 100644 --- a/lua/navigator/codeAction.lua +++ b/lua/navigator/codeAction.lua @@ -27,6 +27,8 @@ end local function _update_virtual_text(line, actions) local namespace = get_namespace() pcall(api.nvim_buf_clear_namespace, 0, namespace, 0, -1) + local bufnr = api.nvim_get_current_buf() + api.nvim_buf_del_extmark(bufnr, namespace, 1) if line then trace(line, actions) @@ -34,7 +36,7 @@ local function _update_virtual_text(line, actions) local title = actions[1].title pcall(api.nvim_buf_set_extmark, 0, namespace, line, -1, { - virt_text = { { icon_with_indent .. title, 'LspDiagnosticsSignHint' } }, + virt_text = { { icon_with_indent .. title, 'DiagnosticsSignHint' } }, virt_text_pos = 'overlay', hl_mode = 'combine', }) @@ -45,7 +47,7 @@ local function _update_sign(line) if vim.tbl_isempty(vim.fn.sign_getdefined(sign_name)) then vim.fn.sign_define(sign_name, { text = config.icons.code_action_icon, - texthl = 'LspDiagnosticsSignHint', + texthl = 'DiagnosticsSignHint', }) end local winid = get_current_winid() @@ -110,16 +112,13 @@ function code_action:render_action_virtual_text(line, diagnostics) end end - if config.lsp.code_action.virtual_text then - if need_check_diagnostic[vim.bo.filetype] then - if next(diagnostics) == nil then - _update_virtual_text(nil) - else - _update_virtual_text(line, actions) - end - else - _update_virtual_text(line, actions) - end + if not config.lsp.code_action.virtual_text then + return + end + if need_check_diagnostic[vim.bo.filetype] and not next(diagnostics) then + _update_virtual_text() + else + _update_virtual_text(line, actions) end end end @@ -190,7 +189,7 @@ code_action.range_code_action = function(startpos, endpos) vim.ui.input = require('guihua.input').input if vim.fn.has('nvim-0.8') then - vim.lsp.buf.code_action({context=context ,range={start = startpos, ['end'] = endpos}}) + vim.lsp.buf.code_action({ context = context, range = { start = startpos, ['end'] = endpos } }) else vim.lsp.buf.range_code_action(context, startpos, endpos) end