lspconfig
This commit is contained in:
parent
df6dba4e66
commit
c16794addd
|
|
@ -156,6 +156,133 @@ M.comment = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
M.lspconfig = {
|
||||||
|
plugin = true,
|
||||||
|
|
||||||
|
-- See `<cmd> :help vim.lsp.*` for documentation on any of the below functions
|
||||||
|
|
||||||
|
n = {
|
||||||
|
["gD"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.declaration()
|
||||||
|
end,
|
||||||
|
"lsp declaration",
|
||||||
|
},
|
||||||
|
|
||||||
|
["gd"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.definition()
|
||||||
|
end,
|
||||||
|
"lsp definition",
|
||||||
|
},
|
||||||
|
|
||||||
|
["K"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.hover()
|
||||||
|
end,
|
||||||
|
"lsp hover",
|
||||||
|
},
|
||||||
|
|
||||||
|
["gi"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.implementation()
|
||||||
|
end,
|
||||||
|
"lsp implementation",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>ls"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.signature_help()
|
||||||
|
end,
|
||||||
|
"lsp signature_help",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>D"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.type_definition()
|
||||||
|
end,
|
||||||
|
"lsp definition type",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>ra"] = {
|
||||||
|
function()
|
||||||
|
require("nvchad_ui.renamer").open()
|
||||||
|
end,
|
||||||
|
"lsp rename",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>ca"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.code_action()
|
||||||
|
end,
|
||||||
|
"lsp code_action",
|
||||||
|
},
|
||||||
|
|
||||||
|
["gr"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.references()
|
||||||
|
end,
|
||||||
|
"lsp references",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>f"] = {
|
||||||
|
function()
|
||||||
|
vim.diagnostic.open_float()
|
||||||
|
end,
|
||||||
|
"floating diagnostic",
|
||||||
|
},
|
||||||
|
|
||||||
|
["[d"] = {
|
||||||
|
function()
|
||||||
|
vim.diagnostic.goto_prev()
|
||||||
|
end,
|
||||||
|
"goto prev",
|
||||||
|
},
|
||||||
|
|
||||||
|
["d]"] = {
|
||||||
|
function()
|
||||||
|
vim.diagnostic.goto_next()
|
||||||
|
end,
|
||||||
|
"goto_next",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>q"] = {
|
||||||
|
function()
|
||||||
|
vim.diagnostic.setloclist()
|
||||||
|
end,
|
||||||
|
"diagnostic setloclist",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>fm"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.formatting {}
|
||||||
|
end,
|
||||||
|
"lsp formatting",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>wa"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.add_workspace_folder()
|
||||||
|
end,
|
||||||
|
"add workspace folder",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>wr"] = {
|
||||||
|
function()
|
||||||
|
vim.lsp.buf.remove_workspace_folder()
|
||||||
|
end,
|
||||||
|
"remove workspace folder",
|
||||||
|
},
|
||||||
|
|
||||||
|
["<leader>wl"] = {
|
||||||
|
function()
|
||||||
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||||
|
end,
|
||||||
|
"list workspace folders",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
M.blankline = {
|
M.blankline = {
|
||||||
plugin = true,
|
plugin = true,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,15 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
local merge_tb = vim.tbl_deep_extend
|
local merge_tb = vim.tbl_deep_extend
|
||||||
|
|
||||||
|
M.close_buffer = function(bufnr)
|
||||||
|
if vim.bo.buftype == "terminal" then
|
||||||
|
vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide")
|
||||||
|
else
|
||||||
|
bufnr = bufnr or vim.api.nvim_get_current_buf()
|
||||||
|
vim.cmd("confirm bd" .. bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.load_mappings = function(section, mapping_opt)
|
M.load_mappings = function(section, mapping_opt)
|
||||||
local function set_section_map(section_values)
|
local function set_section_map(section_values)
|
||||||
if section_values.plugin then
|
if section_values.plugin then
|
||||||
|
|
|
||||||
|
|
@ -1,117 +1,126 @@
|
||||||
-- Mappings.
|
local present, lspconfig = pcall(require, "lspconfig")
|
||||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
|
||||||
local opts = { noremap=true, silent=true }
|
|
||||||
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
|
|
||||||
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
|
|
||||||
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
|
|
||||||
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
|
|
||||||
|
|
||||||
-- Use an on_attach function to only map the following keys
|
if not present then
|
||||||
-- after the language server attaches to the current buffer
|
return
|
||||||
local on_attach = function(client, bufnr)
|
|
||||||
-- Enable completion triggered by <c-x><c-o>
|
|
||||||
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
||||||
|
|
||||||
-- Mappings.
|
|
||||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
||||||
local bufopts = { noremap=true, silent=true, buffer=bufnr }
|
|
||||||
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
|
|
||||||
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
|
|
||||||
vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
|
|
||||||
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
|
|
||||||
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
|
|
||||||
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
|
|
||||||
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
|
|
||||||
vim.keymap.set('n', '<space>wl', function()
|
|
||||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
||||||
end, bufopts)
|
|
||||||
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
|
|
||||||
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
|
|
||||||
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
|
|
||||||
vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
|
|
||||||
vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local lsp_flags = {
|
local M = {}
|
||||||
-- This is the default in Nvim 0.7+
|
local utils = require "core.utils"
|
||||||
debounce_text_changes = 150,
|
|
||||||
}
|
|
||||||
|
|
||||||
local function lspSymbol(name, icon)
|
-- export on_attach & capabilities for custom lspconfigs
|
||||||
local hl = "DiagnosticSign" .. name
|
|
||||||
vim.fn.sign_define(hl, { text = icon, numhl = hl, texthl = hl })
|
|
||||||
end
|
|
||||||
|
|
||||||
lspSymbol("Error", "")
|
M.on_attach = function(client, bufnr)
|
||||||
lspSymbol("Info", "")
|
if vim.g.vim_version > 7 then
|
||||||
lspSymbol("Hint", "")
|
-- nightly
|
||||||
lspSymbol("Warn", "")
|
client.server_capabilities.documentFormattingProvider = false
|
||||||
|
client.server_capabilities.documentRangeFormattingProvider = false
|
||||||
vim.diagnostic.config {
|
|
||||||
virtual_text = {
|
|
||||||
prefix = "",
|
|
||||||
},
|
|
||||||
signs = true,
|
|
||||||
underline = true,
|
|
||||||
update_in_insert = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
|
|
||||||
border = "single",
|
|
||||||
})
|
|
||||||
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
|
|
||||||
border = "single",
|
|
||||||
focusable = false,
|
|
||||||
relative = "cursor",
|
|
||||||
})
|
|
||||||
|
|
||||||
-- suppress error messages from lang servers
|
|
||||||
vim.notify = function(msg, log_level)
|
|
||||||
if msg:match "exit code" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if log_level == vim.log.levels.ERROR then
|
|
||||||
vim.api.nvim_err_writeln(msg)
|
|
||||||
else
|
else
|
||||||
vim.api.nvim_echo({ { msg } }, true, {})
|
-- stable
|
||||||
|
client.resolved_capabilities.document_formatting = false
|
||||||
|
client.resolved_capabilities.document_range_formatting = false
|
||||||
|
end
|
||||||
|
|
||||||
|
utils.load_mappings("lspconfig", { buffer = bufnr })
|
||||||
|
|
||||||
|
if client.server_capabilities.signatureHelpProvider then
|
||||||
|
local function lspSymbol(name, icon)
|
||||||
|
local hl = "DiagnosticSign" .. name
|
||||||
|
vim.fn.sign_define(hl, { text = icon, numhl = hl, texthl = hl })
|
||||||
|
end
|
||||||
|
|
||||||
|
lspSymbol("Error", "")
|
||||||
|
lspSymbol("Info", "")
|
||||||
|
lspSymbol("Hint", "")
|
||||||
|
lspSymbol("Warn", "")
|
||||||
|
|
||||||
|
vim.diagnostic.config {
|
||||||
|
virtual_text = {
|
||||||
|
prefix = "",
|
||||||
|
},
|
||||||
|
signs = true,
|
||||||
|
underline = true,
|
||||||
|
update_in_insert = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
|
||||||
|
border = "single",
|
||||||
|
})
|
||||||
|
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
|
||||||
|
border = "single",
|
||||||
|
focusable = false,
|
||||||
|
relative = "cursor",
|
||||||
|
})
|
||||||
|
|
||||||
|
-- suppress error messages from lang servers
|
||||||
|
vim.notify = function(msg, log_level)
|
||||||
|
if msg:match "exit code" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if log_level == vim.log.levels.ERROR then
|
||||||
|
vim.api.nvim_err_writeln(msg)
|
||||||
|
else
|
||||||
|
vim.api.nvim_echo({ { msg } }, true, {})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Borders for LspInfo winodw
|
||||||
|
local win = require "lspconfig.ui.windows"
|
||||||
|
local _default_opts = win.default_opts
|
||||||
|
|
||||||
|
win.default_opts = function(options)
|
||||||
|
local opts = _default_opts(options)
|
||||||
|
opts.border = "single"
|
||||||
|
return opts
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Borders for LspInfo winodw
|
M.capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
local win = require "lspconfig.ui.windows"
|
|
||||||
local _default_opts = win.default_opts
|
|
||||||
|
|
||||||
win.default_opts = function(options)
|
M.capabilities.textDocument.completion.completionItem = {
|
||||||
local opts = _default_opts(options)
|
documentationFormat = { "markdown", "plaintext" },
|
||||||
opts.border = "single"
|
snippetSupport = true,
|
||||||
return opts
|
preselectSupport = true,
|
||||||
end
|
insertReplaceSupport = true,
|
||||||
|
labelDetailsSupport = true,
|
||||||
require('lspconfig')['sumneko_lua'].setup{
|
deprecatedSupport = true,
|
||||||
on_attach = on_attach,
|
commitCharactersSupport = true,
|
||||||
flags = lsp_flags,
|
tagSupport = { valueSet = { 1 } },
|
||||||
settings = {
|
resolveSupport = {
|
||||||
Lua = {
|
properties = {
|
||||||
diagnostics = {
|
"documentation",
|
||||||
globals = { "vim" },
|
"detail",
|
||||||
},
|
"additionalTextEdits",
|
||||||
workspace = {
|
|
||||||
library = {
|
|
||||||
[vim.fn.expand "$VIMRUNTIME/lua"] = true,
|
|
||||||
[vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
|
|
||||||
},
|
|
||||||
maxpreload = 100000,
|
|
||||||
preloadFileSize = 10000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
require('lspconfig')['rust_analyzer'].setup{
|
lspconfig.sumneko_lua.setup {
|
||||||
on_attach = on_attach,
|
on_attach = M.on_attach,
|
||||||
flags = lsp_flags,
|
capabilities = M.capabilities,
|
||||||
-- Server-specific settings...
|
|
||||||
settings = {
|
settings = {
|
||||||
["rust-analyzer"] = {}
|
Lua = {
|
||||||
}
|
diagnostics = {
|
||||||
|
globals = { "vim" },
|
||||||
|
},
|
||||||
|
workspace = {
|
||||||
|
library = {
|
||||||
|
[vim.fn.expand "$VIMRUNTIME/lua"] = true,
|
||||||
|
[vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
|
||||||
|
},
|
||||||
|
maxPreload = 100000,
|
||||||
|
preloadFileSize = 10000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lspconfig.rust_analyzer.setup {
|
||||||
|
on_attach = M.on_attach,
|
||||||
|
capabilities = M.capabilities,
|
||||||
|
|
||||||
|
settings = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
|
||||||
Reference in New Issue