improve lsp configuration
This commit is contained in:
parent
a74219cf8e
commit
9bc32324d3
5
init.vim
5
init.vim
|
@ -423,5 +423,10 @@ augroup END
|
||||||
|
|
||||||
"----------------------------------------------------------------------------}}}
|
"----------------------------------------------------------------------------}}}
|
||||||
"
|
"
|
||||||
|
"
|
||||||
|
" require lua init
|
||||||
|
lua <<EOF
|
||||||
|
require('init')
|
||||||
|
EOF
|
||||||
|
|
||||||
" vim: set foldmethod=marker:
|
" vim: set foldmethod=marker:
|
||||||
|
|
|
@ -1,17 +1,3 @@
|
||||||
vim.diagnostic.config({
|
|
||||||
virtual_text = false,
|
|
||||||
signs = true,
|
|
||||||
underline = false,
|
|
||||||
update_in_insert = false,
|
|
||||||
severity_sort = false,
|
|
||||||
})
|
|
||||||
|
|
||||||
local signs = { Error = "● ", Warn = "● ", Hint = "● ", Info = "● " }
|
|
||||||
for type, icon in pairs(signs) do
|
|
||||||
local hl = "DiagnosticSign" .. type
|
|
||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.cmd [[
|
vim.cmd [[
|
||||||
sign define LspDiagnosticsSignError text= texthl= linehl= numhl=LspDiagnosticsLineNrError
|
sign define LspDiagnosticsSignError text= texthl= linehl= numhl=LspDiagnosticsLineNrError
|
||||||
sign define LspDiagnosticsSignWarning text= texthl= linehl= numhl=LspDiagnosticsLineNrWarning
|
sign define LspDiagnosticsSignWarning text= texthl= linehl= numhl=LspDiagnosticsLineNrWarning
|
||||||
|
@ -72,8 +58,8 @@ local on_attach = function(client, bufnr)
|
||||||
-- Mappings.
|
-- Mappings.
|
||||||
local opts = { noremap=true, silent=true }
|
local opts = { noremap=true, silent=true }
|
||||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||||
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev({float = {...}})<CR>', opts)
|
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev({float = false})<CR>', opts)
|
||||||
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next({float = {...}})<CR>', opts)
|
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next({float = false})<CR>', opts)
|
||||||
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||||
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||||
|
@ -101,6 +87,16 @@ local on_attach = function(client, bufnr)
|
||||||
vim.cmd [[autocmd BufWritePre <buffer> :lua vim.lsp.buf.formatting_seq_sync({}, 3000)]]
|
vim.cmd [[autocmd BufWritePre <buffer> :lua vim.lsp.buf.formatting_seq_sync({}, 3000)]]
|
||||||
vim.cmd [[augroup END]]
|
vim.cmd [[augroup END]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if client.resolved_capabilities.document_highlight then
|
||||||
|
vim.cmd [[
|
||||||
|
augroup lsp_document_highlight
|
||||||
|
autocmd! * <buffer>
|
||||||
|
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||||
|
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||||
|
augroup END
|
||||||
|
]]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
vim.diagnostic.config({
|
||||||
|
virtual_text = false,
|
||||||
|
signs = true,
|
||||||
|
underline = false,
|
||||||
|
update_in_insert = false,
|
||||||
|
severity_sort = true,
|
||||||
|
float = {
|
||||||
|
source = "always", -- Or "if_many"
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.cmd [[
|
||||||
|
augroup diagnostic_on_hover
|
||||||
|
autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})
|
||||||
|
augroup END
|
||||||
|
]]
|
||||||
|
|
||||||
|
local signs = { Error = "● ", Warn = "● ", Hint = "● ", Info = "● " }
|
||||||
|
for type, icon in pairs(signs) do
|
||||||
|
local hl = "DiagnosticSign" .. type
|
||||||
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
||||||
|
end
|
||||||
|
|
||||||
|
local border = {
|
||||||
|
{"┌", "FloatBorder"},
|
||||||
|
{"─", "FloatBorder"},
|
||||||
|
{"┐", "FloatBorder"},
|
||||||
|
{"│", "FloatBorder"},
|
||||||
|
{"┘", "FloatBorder"},
|
||||||
|
{"─", "FloatBorder"},
|
||||||
|
{"└", "FloatBorder"},
|
||||||
|
{"│", "FloatBorder"},
|
||||||
|
}
|
||||||
|
|
||||||
|
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
|
||||||
|
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
|
||||||
|
opts = opts or {}
|
||||||
|
opts.border = opts.border or border
|
||||||
|
return orig_util_open_floating_preview(contents, syntax, opts, ...)
|
||||||
|
end
|
Loading…
Reference in New Issue