nvim: plugins: Drop nvim-lightbulb

Drop nvim-lightbulb and just add the needed functionality. This also
fixes a minor bug where the code action detection was incorrectly
being done under codeLensProvider instead of codeActionProvider.
This commit is contained in:
Sanchayan Maity 2023-07-06 11:16:14 +05:30
parent b24c03af09
commit 8db1867f30
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3
3 changed files with 49 additions and 31 deletions

View file

@ -1,23 +0,0 @@
require'nvim-lightbulb'.update_lightbulb {
sign = {
enabled = true,
priority = 10,
},
float = {
enabled = false,
text = "💡",
win_opts = {},
},
virtual_text = {
enabled = false,
text = "💡",
},
status_text = {
enabled = false,
text = "💡",
text_unavailable = ""
},
autocmd = {
enabled = false,
}
}

View file

@ -1,5 +1,5 @@
local protocol = require 'vim.lsp.protocol' local protocol = require 'vim.lsp.protocol'
local lightbulb = require 'nvim-lightbulb' local lsp_util = vim.lsp.util
vim.lsp.set_log_level("off") vim.lsp.set_log_level("off")
@ -73,6 +73,32 @@ local lsp_key_mappings = {
{ "codeLensProvider", 'n', '<LocalLeader>L', '<cmd>lua vim.lsp.codelens.clear()<CR>' }, { "codeLensProvider", 'n', '<LocalLeader>L', '<cmd>lua vim.lsp.codelens.clear()<CR>' },
} }
local CODE_ACTION_AVAILABLE = "CodeActionAvailable"
local CODE_ACTION_GROUP = "code-action-group"
if vim.tbl_isempty(vim.fn.sign_getdefined(CODE_ACTION_AVAILABLE)) then
vim.fn.sign_define(CODE_ACTION_AVAILABLE, { text = "💡", texthl = "DiagnosticSignInfo" })
end
local code_action_update_sign = function(old_line, new_line, bufnr)
bufnr = bufnr or "%"
if old_line then
vim.fn.sign_unplace(
CODE_ACTION_GROUP, { id = old_line, buffer = bufnr }
)
vim.b.code_action_line = nil
end
if new_line and (vim.b.code_action_line ~= new_line) then
vim.fn.sign_place(
new_line, CODE_ACTION_GROUP, CODE_ACTION_AVAILABLE, bufnr,
{ lnum = new_line, priority = 10 }
)
vim.b.code_action_line = new_line
end
end
local cargo_reload_workspace = function() local cargo_reload_workspace = function()
vim.lsp.buf_request(0, 'rust-analyzer/reloadWorkspace', nil, function(err) vim.lsp.buf_request(0, 'rust-analyzer/reloadWorkspace', nil, function(err)
if err then if err then
@ -168,17 +194,33 @@ local on_attach = function(client, bufnr)
end end
end end
if client.server_capabilities.codeActionProvider then
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {
group = lsp_augroup_id,
buffer = bufnr,
callback = function()
-- Taken from https://github.com/neovim/nvim-lspconfig/wiki/Code-Actions
local context = { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() }
local params = lsp_util.make_range_params()
params.context = context
vim.lsp.buf_request(0, 'textDocument/codeAction', params, function(err, result, ctx, config)
if result and not vim.tbl_isempty(result) then
local line = params.range.start.line
code_action_update_sign(vim.b.code_action_line, line + 1, bufnr)
else
code_action_update_sign(vim.b.code_action_line, nil, bufnr)
end
end)
end
})
end
if client.server_capabilities.codeLensProvider then if client.server_capabilities.codeLensProvider then
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI", "InsertLeave"}, { vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI", "InsertLeave"}, {
group = lsp_augroup_id, group = lsp_augroup_id,
buffer = bufnr, buffer = bufnr,
callback = vim.lsp.codelens.refresh, callback = vim.lsp.codelens.refresh,
}) })
vim.api.nvim_create_autocmd({"CursorHold", "CursorHoldI"}, {
group = lsp_augroup_id,
buffer = bufnr,
callback = lightbulb.update_lightbulb,
})
end end
if client.server_capabilities.documentHighlightProvider then if client.server_capabilities.documentHighlightProvider then

View file

@ -17,7 +17,6 @@ require "paq" {
'tpope/vim-dispatch' , 'tpope/vim-dispatch' ,
'junegunn/vim-easy-align' , 'junegunn/vim-easy-align' ,
'nvim-lua/plenary.nvim' , 'nvim-lua/plenary.nvim' ,
'kosayoda/nvim-lightbulb' ,
'mfussenegger/nvim-lint' , 'mfussenegger/nvim-lint' ,
'nvim-treesitter/nvim-treesitter' , 'nvim-treesitter/nvim-treesitter' ,
'mfussenegger/nvim-treehopper' , 'mfussenegger/nvim-treehopper' ,