Skip to content

Commit

Permalink
feat!: move hover and signature_help configuration to their own s…
Browse files Browse the repository at this point in the history
…ettings in a new `defaults` table
  • Loading branch information
mehalter committed Nov 8, 2024
1 parent 6b89448 commit 9916a75
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
35 changes: 27 additions & 8 deletions lua/astrolsp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
---@field format_on_save boolean|AstroLSPFormatOnSaveOpts? control formatting on save options
---@field disabled true|string[]? true to disable all or a list like table of language server names to disable formatting

---@class AstroLSPDefaultOpts
---@field hover vim.lsp.buf.hover.Opts? control the default options for `vim.lsp.buf.hover()` (`:h vim.lsp.buf.hover.Opts`)
---@field signature_help vim.lsp.buf.signature_help.Opts? control the default options for `vim.lsp.buf.signature_help()` (`:h vim.lsp.buf.signature_help.Opts`)

---@class AstroLSPOpts
---Configuration of auto commands
---The key into the table is the group name for the auto commands (`:h augroup`) and the value
Expand Down Expand Up @@ -131,6 +135,23 @@
---}
---```
---@field config lspconfig.options?
---Configure default options passed to `vim.lsp.buf` functions
---Example:
---
---```lua
---defaults = {
--- hover = {
--- border = "rounded",
--- silent = true,
--- },
--- signature_help = {
--- border = "rounded",
--- silent = true,
--- focusable = false,
--- },
---}
---```
---@field defaults AstroLSPDefaultOpts?
---A custom flags table to be passed to all language servers (`:h lspconfig-setup`)
---Example:
--
Expand Down Expand Up @@ -187,18 +208,12 @@
---}
---```
---@field handlers table<string|integer,fun(server:string,opts:_.lspconfig.options)|boolean?>?
---Configure global LSP handlers, set a method to `false` to use the Neovim default
---Configure global LSP handlers, set a method to `false` to use the Neovim default (`:h vim.lsp.handlers`)
---Example:
--
---```lua
---handlers = {
--- -- custom function handler for pyright
--- ["textDocument/hover"] = vim.lsp.with(
--- vim.lsphandlers.hover, {
--- border = "single",
--- title = "hover",
--- }
--- )
--- ["textDocument/publishDiagnostics"] = my_custom_diagnostics_handler,
---}
---```
---@field lsp_handlers table<string,lsp.Handler|false>|false?
Expand Down Expand Up @@ -268,6 +283,10 @@ local M = {
capabilities = {},
---@diagnostic disable-next-line: missing-fields
config = {},
defaults = {
hover = {},
signature_help = {},
},
flags = {},
formatting = { format_on_save = { enabled = true }, disabled = {} },
handlers = {},
Expand Down
20 changes: 20 additions & 0 deletions lua/astrolsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,26 @@ function M.setup(opts)
return ret
end

for method, default in pairs(M.config.defaults) do
-- TODO: remove conditional after dropping support for Neovim v0.10
if vim.fn.has "nvim-0.11" == 1 then
local original_method = vim.lsp.buf[method]
if type(original_method) == "function" then
vim.lsp.buf[method] = function(user_opts)
return original_method(vim.tbl_deep_extend("force", default or {}, user_opts or {}))
end
end
else
local deprecated_handler = ({
hover = "textDocument/hover",
signature_help = "textDocument/signatureHelp",
})[method]
if deprecated_handler and default then
vim.lsp.handlers[deprecated_handler] = vim.lsp.with(vim.lsp.handlers[deprecated_handler], default)
end
end
end

for method, handler in pairs(M.config.lsp_handlers or {}) do
if handler then vim.lsp.handlers[method] = handler end
end
Expand Down

0 comments on commit 9916a75

Please sign in to comment.