feat(nvim): enable lsp inlay hints
This commit is contained in:
parent
c9ea7179a0
commit
33b51e5dea
2 changed files with 75 additions and 64 deletions
|
@ -23,69 +23,71 @@ vim.api.nvim_create_autocmd("BufWritePre", {
|
|||
|
||||
|
||||
require('lspconfig').gopls.setup {
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
},
|
||||
cmd = {'gopls', '--remote=auto'},
|
||||
settings = {
|
||||
gopls = {
|
||||
vulncheck = "Imports",
|
||||
gofumpt = true,
|
||||
usePlaceholders = true,
|
||||
completeUnimported = true,
|
||||
completeFunctionCalls = true,
|
||||
experimentalPostfixCompletions = true,
|
||||
allExperiments = true,
|
||||
semanticTokens = true,
|
||||
analyses = {
|
||||
assign = true,
|
||||
atomic = true,
|
||||
atomicalign = true,
|
||||
bools = true,
|
||||
buildtag = true,
|
||||
composites = true,
|
||||
copylocks = true,
|
||||
erroras = true,
|
||||
httpresponse = true,
|
||||
ifaceassert = true,
|
||||
infertypeargs = true,
|
||||
loopclosure = true,
|
||||
lostcancel = true,
|
||||
nilfunc = true,
|
||||
nilness = true,
|
||||
printf = true,
|
||||
shadow = true,
|
||||
simplifyrange = true,
|
||||
simplifyslice = true,
|
||||
sortslice = true,
|
||||
stdmethods = true,
|
||||
stringintconv = true,
|
||||
testinggoroutine = true,
|
||||
tests = true,
|
||||
unmarshal = true,
|
||||
unreachable = true,
|
||||
unsafeptr = true,
|
||||
unusedparams = true,
|
||||
unusedresult = true,
|
||||
unusedwrite = true,
|
||||
useany = true,
|
||||
nonewvars = true,
|
||||
},
|
||||
codelenses = {
|
||||
generate = true,
|
||||
gc_details = true,
|
||||
run_govulncheck = true,
|
||||
},
|
||||
hints = {
|
||||
assignVariableTypes = true,
|
||||
compositeLiteralFields = true,
|
||||
constantValues = true,
|
||||
functionTypeParameters = true,
|
||||
parameterNames = true,
|
||||
rangeVariableTypes = true,
|
||||
},
|
||||
},
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
},
|
||||
cmd = {'gopls', '--remote=auto'},
|
||||
settings = {
|
||||
gopls = {
|
||||
vulncheck = "Imports",
|
||||
gofumpt = true,
|
||||
usePlaceholders = true,
|
||||
completeUnimported = true,
|
||||
completeFunctionCalls = true,
|
||||
experimentalPostfixCompletions = true,
|
||||
allExperiments = true,
|
||||
semanticTokens = true,
|
||||
analyses = {
|
||||
appends = true,
|
||||
assign = true,
|
||||
atomic = true,
|
||||
atomicalign = true,
|
||||
bools = true,
|
||||
buildtag = true,
|
||||
composites = true,
|
||||
copylocks = true,
|
||||
erroras = true,
|
||||
httpresponse = true,
|
||||
ifaceassert = true,
|
||||
infertypeargs = true,
|
||||
loopclosure = true,
|
||||
lostcancel = true,
|
||||
nilfunc = true,
|
||||
nilness = true,
|
||||
printf = true,
|
||||
shadow = true,
|
||||
simplifyrange = true,
|
||||
simplifyslice = true,
|
||||
sortslice = true,
|
||||
stdmethods = true,
|
||||
stringintconv = true,
|
||||
testinggoroutine = true,
|
||||
tests = true,
|
||||
unmarshal = true,
|
||||
unreachable = true,
|
||||
unsafeptr = true,
|
||||
unusedparams = true,
|
||||
unusedresult = true,
|
||||
unusedwrite = true,
|
||||
useany = true,
|
||||
nonewvars = true,
|
||||
},
|
||||
codelenses = {
|
||||
generate = true,
|
||||
gc_details = true,
|
||||
run_govulncheck = true,
|
||||
tidy = true,
|
||||
upgrade_dependency = true,
|
||||
},
|
||||
hints = {
|
||||
assignVariableTypes = true,
|
||||
compositeLiteralFields = true,
|
||||
compositeLiteralTypes = true,
|
||||
constantValues = true,
|
||||
functionTypeParameters = true,
|
||||
parameterNames = true,
|
||||
rangeVariableTypes = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Change local setting to separate 3rd-party and local imports with go.mod prefix
|
||||
|
|
|
@ -41,6 +41,12 @@ vim.keymap.set('n', '<space>dl', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt
|
|||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
||||
callback = function(ev)
|
||||
-- Enable inlay hints
|
||||
local client = vim.lsp.get_client_by_id(ev.data.client_id)
|
||||
if client.server_capabilities.inlayHintProvider then
|
||||
vim.lsp.inlay_hint.enable(true, { bufnr = ev.buf })
|
||||
end
|
||||
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
||||
|
||||
|
@ -57,6 +63,9 @@ vim.api.nvim_create_autocmd('LspAttach', {
|
|||
vim.keymap.set('n', '<space>wl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end, opts)
|
||||
vim.keymap.set('n', '<space>i', function()
|
||||
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
|
||||
end, opts)
|
||||
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
|
||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts)
|
||||
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
|
||||
|
|
Loading…
Add table
Reference in a new issue