Skip to content

Commit 4484ddd

Browse files
committed
feat(advanced_lsp): signature help pop up added to AstroLSP
1 parent d5f662d commit 4484ddd

File tree

2 files changed

+4
-96
lines changed

2 files changed

+4
-96
lines changed

.typos.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# See https://github.com/crate-ci/typos/blob/master/docs/reference.md to configure typos
22
[default.extend-words]
33
fo = "fo"
4+
noice = "noice"

src/content/docs/recipes/advanced_lsp.mdx

+3-96
Original file line numberDiff line numberDiff line change
@@ -711,108 +711,15 @@ return {
711711

712712
## Automatic Signature Help
713713

714-
:::tip
715-
716-
This is available in the [AstroCommunity](https://github.com/AstroNvim/astrocommunity/tree/main/lua/astrocommunity/recipes/astrolsp-auto-signature-help)
717-
718-
```lua title="lua/community.lua" ins={3}
719-
return {
720-
"AstroNvim/astrocommunity",
721-
{ import = "astrocommunity.recipes.astrolsp-auto-signature-help" },
722-
}
723-
```
724-
725-
:::
726-
727-
Some users may want to have automatic pop ups of function signatures while editing with a language server. Using a combination of AstroCore and AstroLSP we can build a robust system for managing the signature help and automatically triggering it when necessary. Here is an in depth example:
714+
Some users may want to have automatic pop ups of function signatures while editing with a language server similar to that of functionality provided by [`noice.nvim`](https://github.com/folke/noice.nvim) and [`lsp_signature.nvim`](https://github.com/ray-x/lsp_signature.nvim). By default this behavior is disabled, but can easily be enabled by modifying `features.signature_help` in the AstroLSP `opts`:
728715

729716
```lua title="lua/plugins/signature_help.lua"
730717
return {
731718
"AstroNvim/astrolsp",
732-
specs = {
733-
{
734-
"AstroNvim/astrocore",
735-
---@type AstroCoreOpts
736-
opts = {
737-
autocmds = {
738-
signature_help_triggers = {
739-
{
740-
event = "LspAttach",
741-
desc = "Add signature help triggers as language servers attach",
742-
callback = function(args)
743-
local client = vim.lsp.get_client_by_id(args.data.client_id)
744-
if
745-
client and client.supports_method("textDocument/signatureHelp")
746-
then
747-
vim.b[args.buf].signature_help_trigger =
748-
require("astrocore").list_insert_unique(
749-
vim.b[args.buf].signature_help_trigger,
750-
client.server_capabilities.signatureHelpProvider.triggerCharacters
751-
or {}
752-
)
753-
end
754-
end,
755-
},
756-
{
757-
event = "LspDetach",
758-
desc = "Safely remove LSP signature help triggers when language servers detach",
759-
callback = vim.schedule_wrap(function(args)
760-
if not vim.api.nvim_buf_is_valid(args.buf) then
761-
return
762-
end
763-
local signature_help_trigger = {}
764-
for _, client in
765-
pairs(
766-
(vim.lsp.get_clients or vim.lsp.get_active_clients)({
767-
bufnr = args.buf,
768-
})
769-
)
770-
do
771-
if
772-
client.id ~= args.data.client_id
773-
and client.supports_method("textDocument/signatureHelp")
774-
then
775-
require("astrocore").list_insert_unique(
776-
signature_help_trigger,
777-
client.server_capabilities.signatureHelpProvider.triggerCharacters
778-
or {}
779-
)
780-
end
781-
end
782-
vim.b[args.buf].signature_help_trigger = signature_help_trigger
783-
end),
784-
},
785-
},
786-
},
787-
},
788-
},
789-
},
790719
---@type AstroLSPOpts
791720
opts = {
792-
autocmds = {
793-
auto_signature_help = {
794-
cond = "textDocument/signatureHelp",
795-
{
796-
event = "TextChangedI",
797-
desc = "Automatically trigger signature help when a trigger character is typed",
798-
callback = function(args)
799-
local signature_help_trigger =
800-
vim.b[args.buf].signature_help_trigger
801-
if signature_help_trigger then
802-
local cur_line = vim.api.nvim_get_current_line():gsub("%s+$", "") -- rm trailing spaces
803-
local pos = vim.api.nvim_win_get_cursor(0)[2]
804-
local cur_char = cur_line:sub(pos, pos)
805-
806-
for _, char in ipairs(signature_help_trigger) do
807-
if cur_char == char then
808-
vim.lsp.buf.signature_help()
809-
return
810-
end
811-
end
812-
end
813-
end,
814-
},
815-
},
721+
features = {
722+
signature_help = true, -- enable automatic signature help popup globally on startup
816723
},
817724
},
818725
}

0 commit comments

Comments
 (0)