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 {
|
require('lspconfig').gopls.setup {
|
||||||
flags = {
|
flags = {
|
||||||
debounce_text_changes = 150,
|
debounce_text_changes = 150,
|
||||||
},
|
},
|
||||||
cmd = {'gopls', '--remote=auto'},
|
cmd = {'gopls', '--remote=auto'},
|
||||||
settings = {
|
settings = {
|
||||||
gopls = {
|
gopls = {
|
||||||
vulncheck = "Imports",
|
vulncheck = "Imports",
|
||||||
gofumpt = true,
|
gofumpt = true,
|
||||||
usePlaceholders = true,
|
usePlaceholders = true,
|
||||||
completeUnimported = true,
|
completeUnimported = true,
|
||||||
completeFunctionCalls = true,
|
completeFunctionCalls = true,
|
||||||
experimentalPostfixCompletions = true,
|
experimentalPostfixCompletions = true,
|
||||||
allExperiments = true,
|
allExperiments = true,
|
||||||
semanticTokens = true,
|
semanticTokens = true,
|
||||||
analyses = {
|
analyses = {
|
||||||
assign = true,
|
appends = true,
|
||||||
atomic = true,
|
assign = true,
|
||||||
atomicalign = true,
|
atomic = true,
|
||||||
bools = true,
|
atomicalign = true,
|
||||||
buildtag = true,
|
bools = true,
|
||||||
composites = true,
|
buildtag = true,
|
||||||
copylocks = true,
|
composites = true,
|
||||||
erroras = true,
|
copylocks = true,
|
||||||
httpresponse = true,
|
erroras = true,
|
||||||
ifaceassert = true,
|
httpresponse = true,
|
||||||
infertypeargs = true,
|
ifaceassert = true,
|
||||||
loopclosure = true,
|
infertypeargs = true,
|
||||||
lostcancel = true,
|
loopclosure = true,
|
||||||
nilfunc = true,
|
lostcancel = true,
|
||||||
nilness = true,
|
nilfunc = true,
|
||||||
printf = true,
|
nilness = true,
|
||||||
shadow = true,
|
printf = true,
|
||||||
simplifyrange = true,
|
shadow = true,
|
||||||
simplifyslice = true,
|
simplifyrange = true,
|
||||||
sortslice = true,
|
simplifyslice = true,
|
||||||
stdmethods = true,
|
sortslice = true,
|
||||||
stringintconv = true,
|
stdmethods = true,
|
||||||
testinggoroutine = true,
|
stringintconv = true,
|
||||||
tests = true,
|
testinggoroutine = true,
|
||||||
unmarshal = true,
|
tests = true,
|
||||||
unreachable = true,
|
unmarshal = true,
|
||||||
unsafeptr = true,
|
unreachable = true,
|
||||||
unusedparams = true,
|
unsafeptr = true,
|
||||||
unusedresult = true,
|
unusedparams = true,
|
||||||
unusedwrite = true,
|
unusedresult = true,
|
||||||
useany = true,
|
unusedwrite = true,
|
||||||
nonewvars = true,
|
useany = true,
|
||||||
},
|
nonewvars = true,
|
||||||
codelenses = {
|
},
|
||||||
generate = true,
|
codelenses = {
|
||||||
gc_details = true,
|
generate = true,
|
||||||
run_govulncheck = true,
|
gc_details = true,
|
||||||
},
|
run_govulncheck = true,
|
||||||
hints = {
|
tidy = true,
|
||||||
assignVariableTypes = true,
|
upgrade_dependency = true,
|
||||||
compositeLiteralFields = true,
|
},
|
||||||
constantValues = true,
|
hints = {
|
||||||
functionTypeParameters = true,
|
assignVariableTypes = true,
|
||||||
parameterNames = true,
|
compositeLiteralFields = true,
|
||||||
rangeVariableTypes = 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', {
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
||||||
callback = function(ev)
|
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>
|
-- Enable completion triggered by <c-x><c-o>
|
||||||
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
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()
|
vim.keymap.set('n', '<space>wl', function()
|
||||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||||
end, opts)
|
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', '<space>D', vim.lsp.buf.type_definition, opts)
|
||||||
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, 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)
|
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
|
||||||
|
|
Loading…
Add table
Reference in a new issue