summaryrefslogtreecommitdiff
path: root/lua/lsp/init.lua
diff options
context:
space:
mode:
authorkylo252 <[email protected]>2021-07-31 06:06:08 +0200
committerGitHub <[email protected]>2021-07-31 00:06:08 -0400
commit9d89929d9bb47d1f78c2d3945b761da2f24a5643 (patch)
tree7f5d281ddb4bbdcecffe01c0234d02be32ede1f7 /lua/lsp/init.lua
parent6f4dd8471b24f71ed6712fb6b9acc0ac79b9137a (diff)
Enable querying lang-server formatting capabilities (#1078)
Diffstat (limited to 'lua/lsp/init.lua')
-rw-r--r--lua/lsp/init.lua98
1 files changed, 61 insertions, 37 deletions
diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua
index 62c42fd8..67007e81 100644
--- a/lua/lsp/init.lua
+++ b/lua/lsp/init.lua
@@ -1,55 +1,79 @@
-local utils = require "utils"
-local service = require "lsp.service"
-local null_ls = require "lsp.null-ls"
local M = {}
-
+local u = require "utils"
function M.config()
require("lsp.kind").setup()
require("lsp.handlers").setup()
require("lsp.signs").setup()
- require("lsp.keybinds").setup()
end
-function M.setup(lang)
- local lang_server = lvim.lang[lang].lsp
- local provider = lang_server.provider
- if utils.check_lsp_client_active(provider) then
- return
+local function lsp_highlight_document(client)
+ if lvim.lsp.document_highlight == false then
+ return -- we don't need further
+ end
+ -- Set autocommands conditional on server_capabilities
+ if client.resolved_capabilities.document_highlight then
+ vim.api.nvim_exec(
+ [[
+ hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
+ hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
+ hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
+ 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
+ ]],
+ false
+ )
end
+end
- local overrides = lvim.lsp.override
+local function formatter_handler(client)
+ local buffer_filetype = vim.bo.filetype
+ local ext_provider = lvim.lang[buffer_filetype].formatter.exe
- if utils.is_table(overrides) then
- if utils.has_value(overrides, lang) then
- return
- end
+ if ext_provider then
+ client.resolved_capabilities.document_formatting = false
+ u.lvim_log(
+ string.format("Overriding [%s] formatting if exists, Using provider [%s] instead", client.name, ext_provider)
+ )
end
+end
- if utils.is_string(overrides) then
- if overrides == lang then
- return
- end
+function M.common_capabilities()
+ local capabilities = vim.lsp.protocol.make_client_capabilities()
+ capabilities.textDocument.completion.completionItem.snippetSupport = true
+ capabilities.textDocument.completion.completionItem.resolveSupport = {
+ properties = {
+ "documentation",
+ "detail",
+ "additionalTextEdits",
+ },
+ }
+ return capabilities
+end
+
+function M.common_on_init(client, bufnr)
+ if lvim.lsp.on_init_callback then
+ lvim.lsp.on_init_callback(client, bufnr)
+ return
end
- local sources = null_ls.setup(lang)
-
- for _, source in pairs(sources) do
- local method = source.method
- local format_method = "NULL_LS_FORMATTING"
-
- if utils.is_table(method) then
- if utils.has_value(method, format_method) then
- lang_server.setup.on_attach = service.no_formatter_on_attach
- end
- end
-
- if utils.is_string(method) then
- if method == format_method then
- lang_server.setup.on_attach = service.no_formatter_on_attach
- end
- end
+ formatter_handler(client)
+end
+
+function M.common_on_attach(client, bufnr)
+ if lvim.lsp.on_attach_callback then
+ 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
- if provider == "" or provider == nil then
+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
return
end