2021-02-02 11:44:15 +01:00
|
|
|
local nvim_lsp = require('lspconfig')
|
|
|
|
local protocol = require('vim.lsp.protocol')
|
2021-05-07 09:33:23 +02:00
|
|
|
local signature = require('lsp_signature')
|
2020-05-29 07:24:46 +02:00
|
|
|
|
2020-06-11 08:00:15 +02:00
|
|
|
-- Taken from https://www.reddit.com/r/neovim/comments/gyb077/nvimlsp_peek_defination_javascript_ttserver/
|
|
|
|
function preview_location(location, context, before_context)
|
|
|
|
-- location may be LocationLink or Location (more useful for the former)
|
|
|
|
context = context or 10
|
|
|
|
before_context = before_context or 5
|
|
|
|
local uri = location.targetUri or location.uri
|
|
|
|
if uri == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local bufnr = vim.uri_to_bufnr(uri)
|
|
|
|
if not vim.api.nvim_buf_is_loaded(bufnr) then
|
|
|
|
vim.fn.bufload(bufnr)
|
|
|
|
end
|
|
|
|
local range = location.targetRange or location.range
|
|
|
|
local contents =
|
|
|
|
vim.api.nvim_buf_get_lines(bufnr, range.start.line - before_context, range["end"].line + 1 + context, false)
|
|
|
|
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
|
|
|
|
return vim.lsp.util.open_floating_preview(contents, filetype)
|
|
|
|
end
|
|
|
|
|
|
|
|
function preview_location_callback(_, method, result)
|
|
|
|
local context = 10
|
|
|
|
if result == nil or vim.tbl_isempty(result) then
|
|
|
|
print("No location found: " .. method)
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
if vim.tbl_islist(result) then
|
|
|
|
floating_buf, floating_win = preview_location(result[1], context)
|
|
|
|
else
|
|
|
|
floating_buf, floating_win = preview_location(result, context)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function peek_definition()
|
|
|
|
if vim.tbl_contains(vim.api.nvim_list_wins(), floating_win) then
|
|
|
|
vim.api.nvim_set_current_win(floating_win)
|
|
|
|
else
|
|
|
|
local params = vim.lsp.util.make_position_params()
|
|
|
|
return vim.lsp.buf_request(0, "textDocument/definition", params, preview_location_callback)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-02 11:15:27 +02:00
|
|
|
local on_attach = function(client, bufnr)
|
2021-05-07 09:33:23 +02:00
|
|
|
signature.on_attach({
|
|
|
|
bind = true,
|
|
|
|
hint_enable = true,
|
|
|
|
hint_prefix = "🐼 ",
|
|
|
|
hint_scheme = "String",
|
|
|
|
handler_opts = { border = "single" },
|
|
|
|
decorator = {"`", "`"}
|
|
|
|
})
|
2020-05-29 07:24:46 +02:00
|
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
|
2020-12-09 05:44:18 +01:00
|
|
|
if client.config.flags then
|
|
|
|
client.config.flags.allow_incremental_sync = true
|
2021-05-13 17:08:56 +02:00
|
|
|
client.config.flags.debounce_text_changes = 100
|
2020-12-09 05:44:18 +01:00
|
|
|
end
|
|
|
|
|
2020-05-29 07:24:46 +02:00
|
|
|
local opts = { noremap=true, silent=true }
|
2021-02-25 13:06:32 +01:00
|
|
|
|
2020-06-03 09:05:15 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
2021-02-25 13:06:32 +01:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
2020-05-29 07:24:46 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
2020-08-25 16:29:33 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ga', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
2020-05-29 07:24:46 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
2021-02-25 13:06:32 +01:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '1gd', '<cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '1gD', '<cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gR', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
2020-06-11 08:00:15 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'pd', '<cmd>lua peek_definition()<CR>', opts)
|
2021-02-25 13:06:32 +01:00
|
|
|
|
2020-11-21 06:35:07 +01:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev { wrap = false }<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next { wrap = false }<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[D', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']D', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'do', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
2021-02-25 13:06:32 +01:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', ',d', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
|
|
|
|
|
|
|
if client.resolved_capabilities.document_formatting then
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
|
|
|
elseif client.resolved_capabilities.document_range_formatting then
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
|
|
|
end
|
2021-02-02 11:44:15 +01:00
|
|
|
|
|
|
|
protocol.CompletionItemKind = {
|
|
|
|
' '; -- text
|
|
|
|
' '; -- method
|
|
|
|
' '; -- function
|
|
|
|
'全'; -- ctor
|
|
|
|
' '; -- field
|
|
|
|
' '; -- variable
|
|
|
|
' '; -- class
|
|
|
|
' '; -- interface
|
|
|
|
' '; -- module
|
|
|
|
' '; -- property
|
|
|
|
' '; -- unit
|
|
|
|
' '; -- value
|
|
|
|
'螺'; -- enum
|
|
|
|
' '; -- keyword
|
|
|
|
' '; -- snippet
|
|
|
|
' '; -- color
|
|
|
|
' '; -- file
|
|
|
|
' '; -- reference
|
|
|
|
' '; -- folder
|
|
|
|
' '; -- enum member
|
|
|
|
' '; -- constant
|
|
|
|
' '; -- struct
|
|
|
|
' '; -- event
|
|
|
|
'璉'; -- operator
|
|
|
|
' '; -- type parameter
|
|
|
|
}
|
2020-05-29 07:24:46 +02:00
|
|
|
end
|
|
|
|
|
2021-03-10 14:15:26 +01:00
|
|
|
local servers = { 'hls', 'rust_analyzer', 'pyls', 'tsserver' }
|
2020-05-29 07:24:46 +02:00
|
|
|
for _, lsp in ipairs(servers) do
|
|
|
|
nvim_lsp[lsp].setup {
|
2020-09-02 11:15:27 +02:00
|
|
|
on_attach = on_attach,
|
2020-12-14 12:46:28 +01:00
|
|
|
}
|
2020-05-29 07:24:46 +02:00
|
|
|
end
|