feat: toggle inlay hint + remove lsp lints
This commit is contained in:
parent
88990c0f43
commit
58bafac26e
4 changed files with 16 additions and 43 deletions
|
@ -13,7 +13,6 @@
|
|||
"friendly-snippets": { "branch": "main", "commit": "00e191fea2cfbbdd378243f35b5953296537a116" },
|
||||
"gitsigns.nvim": { "branch": "main", "commit": "d8b52fc95e3d424e5c09b287ee2c293dcb4e26fb" },
|
||||
"lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" },
|
||||
"lsp_lines.nvim": { "branch": "main", "commit": "f53af96d4789eef39a082dbcce078d2bfc384ece" },
|
||||
"lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "dfdd771b792fbb4bad8e057d72558255695aa1a7" },
|
||||
"mason.nvim": { "branch": "main", "commit": "0942198fb9a998b6ccee36fb8dd7495eb8ba659c" },
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
local utils = require('cosmic.utils')
|
||||
local lsp_utils = require('cosmic.utils.lsp')
|
||||
local user_config = require('cosmic.core.user')
|
||||
local Logger = require('cosmic.utils.logger')
|
||||
local M = {}
|
||||
|
||||
local function toggle_inlay_hints(bufnr)
|
||||
local enabled = user_config.lsp.inlay_hint
|
||||
return function()
|
||||
enabled = not enabled
|
||||
vim.lsp.inlay_hint(bufnr, enabled)
|
||||
end
|
||||
end
|
||||
|
||||
-- Mappings.
|
||||
function M.init(client, bufnr)
|
||||
local buf_map = utils.create_buf_map(bufnr, {
|
||||
|
@ -33,6 +43,11 @@ function M.init(client, bufnr)
|
|||
-- hover
|
||||
buf_map('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', { desc = 'Show documentation' })
|
||||
|
||||
-- inlay hints
|
||||
if client.supports_method('textDocument/inlayHint') then
|
||||
buf_map('n', '<leader>lh', toggle_inlay_hints(bufnr), { desc = 'Toggle inlay hints for buffer' })
|
||||
end
|
||||
|
||||
-- code actions
|
||||
buf_map('n', 'gn', '<cmd>lua vim.lsp.buf.rename()<cr>', { desc = 'Rename' })
|
||||
buf_map('n', '<leader>la', '<cmd>lua vim.lsp.buf.code_actions()<cr>', { desc = 'Code Actions' })
|
||||
|
|
|
@ -12,7 +12,7 @@ function M.on_attach(client, bufnr)
|
|||
-- Enable completion triggered by <c-x><c-o>
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
if user_config.lsp.inlay_hint and client.server_capabilities.inlayHintProvider then
|
||||
if user_config.lsp.inlay_hint and client.supports_method('textDocument/inlayHint') then
|
||||
vim.lsp.inlay_hint(bufnr, true)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
local u = require('cosmic.utils')
|
||||
local user_config = require('cosmic.core.user')
|
||||
local vt_config = require('cosmic.lsp.diagnostics.config')
|
||||
local map = require('cosmic.utils').map
|
||||
local is_plugin_enabled = user_config.plugins.lsp_lines.enable_on_start
|
||||
local function toggle()
|
||||
if is_plugin_enabled then
|
||||
vim.diagnostic.config(u.merge(vt_config, {
|
||||
virtual_text = false,
|
||||
virtual_lines = true,
|
||||
}))
|
||||
else
|
||||
vim.diagnostic.config(u.merge(vt_config, {
|
||||
virtual_lines = false,
|
||||
}))
|
||||
end
|
||||
is_plugin_enabled = not is_plugin_enabled
|
||||
end
|
||||
|
||||
return {
|
||||
url = 'https://git.sr.ht/~whynothugo/lsp_lines.nvim',
|
||||
keys = {
|
||||
{
|
||||
'<leader>ltl',
|
||||
toggle,
|
||||
desc = 'Toggle LSP Lines',
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
-- init lsp_lines
|
||||
require('lsp_lines').setup()
|
||||
-- run once to properly show/hide based on user config
|
||||
toggle()
|
||||
-- map for toggling lines
|
||||
map('n', '<leader>ltl', '', {
|
||||
callback = toggle,
|
||||
desc = 'Toggle LSP Lines',
|
||||
})
|
||||
end,
|
||||
enabled = not vim.tbl_contains(user_config.disable_builtin_plugins, 'lsp_lines'),
|
||||
}
|
Loading…
Add table
Reference in a new issue