summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorLuc Sinet <[email protected]>2021-07-31 16:12:29 +0200
committerGitHub <[email protected]>2021-07-31 14:12:29 +0000
commitfe5daa722fb75ad85c24936cbb645018bb9d655b (patch)
treefbba8ec7642555e29a7b611f2dfc0e5a0c107188 /lua
parentcf16a2e826774e89d1bfe5812b6f73c3dd049db2 (diff)
[Feature] Expose lsp config (#1156)
Diffstat (limited to 'lua')
-rw-r--r--lua/default-config.lua47
-rw-r--r--lua/keymappings.lua12
-rw-r--r--lua/lsp/handlers.lua2
-rw-r--r--lua/lsp/init.lua35
-rw-r--r--lua/lsp/keybinds.lua27
-rw-r--r--lua/lsp/kind.lua33
-rw-r--r--lua/lsp/signs.lua20
-rw-r--r--lua/utils/init.lua8
8 files changed, 72 insertions, 112 deletions
diff --git a/lua/default-config.lua b/lua/default-config.lua
index 4e849688..6527ad77 100644
--- a/lua/default-config.lua
+++ b/lua/default-config.lua
@@ -34,19 +34,55 @@ lvim = {
},
lsp = {
+ completion = {
+ item_kind = {
+ "  (Text) ",
+ "  (Method)",
+ "  (Function)",
+ "  (Constructor)",
+ " ﴲ (Field)",
+ "[] (Variable)",
+ "  (Class)",
+ " ﰮ (Interface)",
+ "  (Module)",
+ " 襁 (Property)",
+ "  (Unit)",
+ "  (Value)",
+ " 練 (Enum)",
+ "  (Keyword)",
+ "  (Snippet)",
+ "  (Color)",
+ "  (File)",
+ "  (Reference)",
+ "  (Folder)",
+ "  (EnumMember)",
+ " ﲀ (Constant)",
+ " ﳤ (Struct)",
+ "  (Event)",
+ "  (Operator)",
+ "  (TypeParameter)",
+ },
+ },
diagnostics = {
+ signs = {
+ active = true,
+ values = {
+ { name = "LspDiagnosticsSignError", text = "" },
+ { name = "LspDiagnosticsSignWarning", text = "" },
+ { name = "LspDiagnosticsSignHint", text = "" },
+ { name = "LspDiagnosticsSignInformation", text = "" },
+ },
+ },
virtual_text = {
prefix = "",
spacing = 0,
},
- signs = true,
underline = true,
severity_sort = true,
},
override = {},
document_highlight = true,
popup_border = "single",
- default_keybinds = true,
on_attach_callback = nil,
on_init_callback = nil,
},
@@ -60,9 +96,10 @@ lvim = {
}
local schemas = nil
-local common_on_attach = require("lsp").common_on_attach
-local common_capabilities = require("lsp").common_capabilities()
-local common_on_init = require("lsp").common_on_init
+local lsp = require "lsp"
+local common_on_attach = lsp.common_on_attach
+local common_capabilities = lsp.common_capabilities()
+local common_on_init = lsp.common_on_init
local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
if status_ok then
schemas = jsonls_settings.get_default_schemas()
diff --git a/lua/keymappings.lua b/lua/keymappings.lua
index 3cbe797a..34116023 100644
--- a/lua/keymappings.lua
+++ b/lua/keymappings.lua
@@ -49,6 +49,18 @@ local keymaps = {
{ "<C-q>", ":call QuickFixToggle()<CR>" },
-- {'<C-TAB>', 'compe#complete()', {noremap = true, silent = true, expr = true}},
+
+ -- LSP
+ { "gd", "<cmd>lua vim.lsp.buf.definition()<CR>" },
+ { "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>" },
+ { "gr", "<cmd>lua vim.lsp.buf.references()<CR>" },
+ { "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>" },
+ { "gl", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = 'single' })<CR>" },
+ { "gp", "<cmd>lua require'lsp.peek'.Peek('definition')<CR>" },
+ { "K", "<cmd>lua vim.lsp.buf.hover()<CR>" },
+ { "<C-p>", "<cmd>lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
+ { "<C-n>", "<cmd>lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>" },
+ -- { "<tab>", "<cmd>lua vim.lsp.buf.signature_help()<CR>" },
},
term_mode = {
diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua
index 3a467d42..a25db3c1 100644
--- a/lua/lsp/handlers.lua
+++ b/lua/lsp/handlers.lua
@@ -5,7 +5,7 @@ local M = {}
function M.setup()
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = lvim.lsp.diagnostics.virtual_text,
- signs = lvim.lsp.diagnostics.signs,
+ signs = lvim.lsp.diagnostics.signs.active,
underline = lvim.lsp.document_highlight,
})
diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua
index 1488aec0..13b64dac 100644
--- a/lua/lsp/init.lua
+++ b/lua/lsp/init.lua
@@ -1,9 +1,14 @@
local M = {}
local u = require "utils"
+
function M.config()
- require("lsp.kind").setup()
+ vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind
+
+ for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do
+ vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
+ end
+
require("lsp.handlers").setup()
- require("lsp.signs").setup()
end
local function lsp_highlight_document(client)
@@ -28,16 +33,6 @@ local function lsp_highlight_document(client)
end
end
-local function formatter_handler(client)
- local formatters = lvim.lang[vim.bo.filetype].formatters
- if not vim.tbl_isempty(formatters) then
- client.resolved_capabilities.document_formatting = false
- u.lvim_log(
- string.format("Overriding [%s] formatting if exists, Using provider [%s] instead", client.name, formatters[1].exe)
- )
- end
-end
-
function M.common_capabilities()
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
@@ -56,7 +51,12 @@ function M.common_on_init(client, bufnr)
lvim.lsp.on_init_callback(client, bufnr)
return
end
- formatter_handler(client)
+
+ local formatters = lvim.lang[vim.bo.filetype].formatters
+ if not vim.tbl_isempty(formatters) then
+ client.resolved_capabilities.document_formatting = false
+ u.lvim_log(string.format("Overriding [%s] formatter with [%s]", client.name, formatters[1].exe))
+ end
end
function M.common_on_attach(client, bufnr)
@@ -64,18 +64,17 @@ function M.common_on_attach(client, bufnr)
lvim.lsp.on_attach_callback(client, bufnr)
end
lsp_highlight_document(client)
- require("lsp.keybinds").setup()
require("lsp.null-ls").setup(vim.bo.filetype)
end
function M.setup(lang)
- local lang_server = lvim.lang[lang].lsp
- local provider = lang_server.provider
- if require("utils").check_lsp_client_active(provider) then
+ local lsp = lvim.lang[lang].lsp
+ if require("utils").check_lsp_client_active(lsp.provider) then
return
end
- require("lspconfig")[provider].setup(lang_server.setup)
+ local lspconfig = require "lspconfig"
+ lspconfig[lsp.provider].setup(lsp.setup)
end
return M
diff --git a/lua/lsp/keybinds.lua b/lua/lsp/keybinds.lua
deleted file mode 100644
index 21f29994..00000000
--- a/lua/lsp/keybinds.lua
+++ /dev/null
@@ -1,27 +0,0 @@
-local M = {}
-
-function M.setup()
- if lvim.lsp.default_keybinds then
- vim.cmd "nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>"
- vim.cmd "nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>"
- vim.cmd "nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>"
- vim.cmd "nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>"
- vim.api.nvim_set_keymap(
- "n",
- "gl",
- '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = "single" })<CR>',
- { noremap = true, silent = true }
- )
-
- vim.cmd "nnoremap <silent> gp <cmd>lua require'lsp.peek'.Peek('definition')<CR>"
- vim.cmd "nnoremap <silent> K :lua vim.lsp.buf.hover()<CR>"
- vim.cmd "nnoremap <silent> <C-p> :lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})<CR>"
- vim.cmd "nnoremap <silent> <C-n> :lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})<CR>"
- -- vim.cmd "nnoremap <silent> gs <cmd>lua vim.lsp.buf.signature_help()<CR>"
- -- scroll down hover doc or scroll in definition preview
- -- scroll up hover doc
- -- vim.cmd 'command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()'
- end
-end
-
-return M
diff --git a/lua/lsp/kind.lua b/lua/lsp/kind.lua
deleted file mode 100644
index e3b95ecb..00000000
--- a/lua/lsp/kind.lua
+++ /dev/null
@@ -1,33 +0,0 @@
-local M = {}
-
-function M.setup()
- vim.lsp.protocol.CompletionItemKind = {
- -- symbols for autocomplete
- "  (Text) ",
- "  (Method)",
- "  (Function)",
- "  (Constructor)",
- " ﴲ (Field)",
- "[] (Variable)",
- "  (Class)",
- " ﰮ (Interface)",
- "  (Module)",
- " 襁 (Property)",
- "  (Unit)",
- "  (Value)",
- " 練 (Enum)",
- "  (Keyword)",
- "  (Snippet)",
- "  (Color)",
- "  (File)",
- "  (Reference)",
- "  (Folder)",
- "  (EnumMember)",
- " ﲀ (Constant)",
- " ﳤ (Struct)",
- "  (Event)",
- "  (Operator)",
- "  (TypeParameter)",
- }
-end
-return M
diff --git a/lua/lsp/signs.lua b/lua/lsp/signs.lua
deleted file mode 100644
index fab6d302..00000000
--- a/lua/lsp/signs.lua
+++ /dev/null
@@ -1,20 +0,0 @@
-local M = {}
-function M.setup()
- vim.fn.sign_define(
- "LspDiagnosticsSignError",
- { texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError" }
- )
- vim.fn.sign_define(
- "LspDiagnosticsSignWarning",
- { texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning" }
- )
- vim.fn.sign_define(
- "LspDiagnosticsSignHint",
- { texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint" }
- )
- vim.fn.sign_define(
- "LspDiagnosticsSignInformation",
- { texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation" }
- )
-end
-return M
diff --git a/lua/utils/init.lua b/lua/utils/init.lua
index 1685c1ca..a404254b 100644
--- a/lua/utils/init.lua
+++ b/lua/utils/init.lua
@@ -102,14 +102,6 @@ function utils.check_lsp_client_active(name)
return false
end
-function utils.is_table(t)
- return type(t) == "table"
-end
-
-function utils.is_string(t)
- return type(t) == "string"
-end
-
--- Extends a list-like table with the unique values of another list-like table.
---
--- NOTE: This mutates dst!