2021-09-27 13:45:49 +02:00
|
|
|
local nvim_lsp = require 'lspconfig'
|
|
|
|
local protocol = require 'vim.lsp.protocol'
|
|
|
|
local ts_utils = require 'nvim-lsp-ts-utils'
|
|
|
|
local util = require 'lspconfig/util'
|
|
|
|
local cmp = require 'cmp_nvim_lsp'
|
2020-05-29 07:24:46 +02:00
|
|
|
|
2021-09-25 11:50:44 +02:00
|
|
|
-- https://github.com/neovim/nvim-lspconfig/wiki/User-contributed-tips
|
2021-10-02 15:19:02 +02:00
|
|
|
function FormatRangeOperator()
|
2021-09-25 11:54:53 +02:00
|
|
|
local old_func = vim.go.operatorfunc
|
|
|
|
_G.op_func_formatting = function()
|
|
|
|
local start = vim.api.nvim_buf_get_mark(0, '[')
|
|
|
|
local finish = vim.api.nvim_buf_get_mark(0, ']')
|
|
|
|
vim.lsp.buf.range_formatting({}, start, finish)
|
|
|
|
vim.go.operatorfunc = old_func
|
|
|
|
_G.op_func_formatting = nil
|
|
|
|
end
|
|
|
|
vim.go.operatorfunc = 'v:lua.op_func_formatting'
|
|
|
|
vim.api.nvim_feedkeys('g@', 'n', false)
|
|
|
|
end
|
|
|
|
|
2021-09-25 11:50:44 +02:00
|
|
|
local function preview_location_callback(_, result)
|
|
|
|
if result == nil or vim.tbl_isempty(result) then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
vim.lsp.util.preview_location(result[1])
|
|
|
|
end
|
|
|
|
|
|
|
|
function PeekDefinition()
|
|
|
|
local params = vim.lsp.util.make_position_params()
|
|
|
|
return vim.lsp.buf_request(0, 'textDocument/definition', params, preview_location_callback)
|
|
|
|
end
|
|
|
|
|
2021-09-27 13:45:49 +02:00
|
|
|
local ts_utils_setup = function(client, bufnr, opts)
|
|
|
|
if client.name == 'tsserver' then
|
2021-11-27 07:07:11 +01:00
|
|
|
-- Disable tsserver formatting, we want formatting via prettier
|
2021-09-27 13:45:49 +02:00
|
|
|
client.resolved_capabilities.document_formatting = false
|
|
|
|
client.resolved_capabilities.document_range_formatting = false
|
|
|
|
|
|
|
|
ts_utils.setup {
|
|
|
|
debug = false,
|
|
|
|
disable_commands = false,
|
|
|
|
enable_import_on_completion = false,
|
|
|
|
|
|
|
|
import_all_timeout = 5000,
|
|
|
|
import_all_scan_buffers = 100,
|
|
|
|
import_all_select_source = false,
|
|
|
|
import_all_priorities = {
|
|
|
|
buffers = 4, -- loaded buffer names
|
|
|
|
buffer_content = 3, -- loaded buffer content
|
|
|
|
local_files = 2, -- git files or files with relative path markers
|
|
|
|
same_file = 1, -- add to existing import statement
|
|
|
|
},
|
|
|
|
|
|
|
|
update_imports_on_move = false,
|
|
|
|
require_confirmation_on_move = false,
|
|
|
|
watch_dir = nil,
|
|
|
|
|
|
|
|
filter_out_diagnostics_by_severity = {},
|
|
|
|
filter_out_diagnostics_by_code = {},
|
2021-11-15 08:55:06 +01:00
|
|
|
|
|
|
|
auto_inlay_hints = true,
|
|
|
|
inlay_hints_highlight = "Hint",
|
2021-09-27 13:45:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ts_utils.setup_client(client)
|
|
|
|
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'go', ':TSLspOrganize<CR>' , opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gf', ':TSLspFixCurrent<CR>', opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gI', ':TSLspImportAll<CR>' , opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-02 11:15:27 +02:00
|
|
|
local on_attach = function(client, bufnr)
|
2020-05-29 07:24:46 +02:00
|
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
2021-09-30 10:25:49 +02:00
|
|
|
vim.lsp.set_log_level('warn')
|
2020-05-29 07:24:46 +02:00
|
|
|
|
2020-12-09 05:44:18 +01:00
|
|
|
if client.config.flags then
|
|
|
|
client.config.flags.allow_incremental_sync = true
|
2021-09-25 08:29:48 +02:00
|
|
|
client.config.flags.debounce_text_changes = 500
|
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
|
|
|
|
2021-11-27 07:07:11 +01:00
|
|
|
-- This needs to be here, so we disable formatting with tsserver before
|
|
|
|
-- actually checking it below.
|
|
|
|
ts_utils_setup(client, bufnr, opts)
|
|
|
|
|
2021-10-09 10:34:30 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd' , '<cmd>lua vim.lsp.buf.definition()<CR>' , opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD' , '<cmd>lua vim.lsp.buf.declaration()<CR>' , opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr' , '<cmd>lua vim.lsp.buf.references()<CR>' , opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi' , '<cmd>lua vim.lsp.buf.implementation()<CR>' , opts)
|
|
|
|
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)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'pd' , '<cmd>lua PeekDefinition()<CR>' , opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>k', '<cmd>lua vim.lsp.buf.hover()<CR>' , opts)
|
2021-10-11 08:00:37 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>S', '<cmd>lua vim.lsp.buf.signature_help()<CR>' , opts)
|
2021-10-09 10:34:30 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ga' , '<cmd>lua vim.lsp.buf.code_action()<CR>' , opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'v', 'ga' , '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
|
|
|
|
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<Leader>r', '<cmd>lua vim.lsp.buf.code_action{ only = \'refactor\' }<CR>' , opts)
|
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'v', '<Leader>r', '<cmd>lua vim.lsp.buf.range_code_action{ only = \'refactor\' }<CR>', opts)
|
2021-02-25 13:06:32 +01:00
|
|
|
|
2021-09-25 14:48:12 +02:00
|
|
|
if client.resolved_capabilities.document_range_formatting then
|
2021-10-02 15:19:02 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'x', 'gq', '<cmd>lua FormatRangeOperator()<CR>', opts)
|
2021-09-27 11:47:43 +02:00
|
|
|
end
|
|
|
|
if client.resolved_capabilities.document_formatting then
|
2021-09-25 14:48:12 +02:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gq', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
2021-02-25 13:06:32 +01:00
|
|
|
end
|
2021-02-02 11:44:15 +01:00
|
|
|
|
2021-06-15 06:10:18 +02:00
|
|
|
if client.resolved_capabilities.code_lens then
|
2021-11-18 12:45:30 +01:00
|
|
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>l", "<cmd>lua vim.lsp.codelens.run()<CR>", opts)
|
2021-06-15 06:10:18 +02:00
|
|
|
vim.api.nvim_command [[autocmd CursorHold,CursorHoldI,InsertLeave <buffer> lua vim.lsp.codelens.refresh()]]
|
|
|
|
end
|
|
|
|
|
2021-10-19 16:51:29 +02:00
|
|
|
vim.api.nvim_command [[autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()]]
|
|
|
|
vim.api.nvim_command [[autocmd CursorMoved,InsertEnter <buffer> lua vim.lsp.buf.clear_references()]]
|
|
|
|
|
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
|
|
|
|
}
|
2021-05-24 13:08:25 +02:00
|
|
|
|
2021-09-27 13:45:49 +02:00
|
|
|
vim.cmd [[autocmd CursorHold,CursorHoldI <buffer> lua require'nvim-lightbulb'.update_lightbulb()]]
|
|
|
|
end
|
2021-05-24 13:08:25 +02:00
|
|
|
|
2021-10-03 09:16:40 +02:00
|
|
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
capabilities = cmp.update_capabilities(capabilities)
|
2021-05-13 17:03:21 +02:00
|
|
|
|
2021-09-26 09:01:15 +02:00
|
|
|
local rust_tool_opts = {
|
|
|
|
tools = {
|
|
|
|
autoSetHints = true,
|
|
|
|
hover_with_actions = false,
|
|
|
|
runnables = { use_telescope = false },
|
|
|
|
debuggables = { use_telescope = false },
|
|
|
|
inlay_hints = {
|
|
|
|
only_current_line = false,
|
|
|
|
only_current_line_autocmd = "CursorHold",
|
|
|
|
show_parameter_hints = true,
|
|
|
|
parameter_hints_prefix = "<- ",
|
|
|
|
other_hints_prefix = "=> ",
|
|
|
|
highlight = "Hint",
|
|
|
|
},
|
|
|
|
hover_actions = {
|
|
|
|
auto_focus = true
|
|
|
|
},
|
|
|
|
crate_graph = {
|
|
|
|
backend = "svg",
|
|
|
|
output = "crates_graph.svg",
|
|
|
|
full = false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
server = {
|
|
|
|
on_attach = on_attach,
|
2021-10-03 09:16:40 +02:00
|
|
|
capabilities = capabilities,
|
2021-09-26 09:01:15 +02:00
|
|
|
settings = {
|
|
|
|
["rust-analyzer"] = {
|
|
|
|
checkOnSave = {
|
|
|
|
command = "clippy"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-09-27 13:45:49 +02:00
|
|
|
nvim_lsp.clangd.setup {
|
|
|
|
on_attach = on_attach,
|
2021-10-03 09:16:40 +02:00
|
|
|
capabilities = capabilities,
|
2021-09-27 13:45:49 +02:00
|
|
|
default_config = {
|
2021-11-05 10:37:58 +01:00
|
|
|
cmd = { "clangd", "--background-index", "--pch-storage=memory", "--clang-tidy", "--suggest-missing-includes", "--header-insertion=never" },
|
2021-09-27 13:45:49 +02:00
|
|
|
filetypes = { 'c', 'cpp' },
|
|
|
|
root_dir = function(fname)
|
|
|
|
-- We specify build/compile_commands.json as that is where the compile_commands.json
|
|
|
|
-- gets generated automatically for meson projects.
|
|
|
|
local root_pattern = util.root_pattern('build/compile_commands.json', 'compile_commands.json', 'compile_flags.txt', '.git')
|
|
|
|
local filename = util.path.is_absolute(fname) and fname or util.path.join(vim.loop.cwd(), fname)
|
|
|
|
return root_pattern(filename) or util.path.dirname(filename)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
}
|
2021-07-17 13:40:46 +02:00
|
|
|
|
2021-11-29 07:24:53 +01:00
|
|
|
nvim_lsp.hls.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities
|
|
|
|
}
|
|
|
|
|
|
|
|
nvim_lsp.pylsp.setup {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
settings = {
|
|
|
|
pylsp = {
|
|
|
|
plugins = {
|
|
|
|
flake8 = {
|
|
|
|
enabled = true,
|
|
|
|
config = vim.fn.expand('~/.config/flake8')
|
|
|
|
},
|
|
|
|
pylint = {
|
|
|
|
enabled = true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-27 13:45:49 +02:00
|
|
|
require('rust-tools').setup(rust_tool_opts)
|
2021-07-17 13:40:46 +02:00
|
|
|
|
2021-11-15 08:55:06 +01:00
|
|
|
nvim_lsp.tsserver.setup {
|
|
|
|
init_options = require("nvim-lsp-ts-utils").init_options,
|
|
|
|
on_attach = on_attach,
|
2021-11-20 12:30:14 +01:00
|
|
|
capabilities = capabilities,
|
2021-11-15 08:55:06 +01:00
|
|
|
}
|