From 52bec17fd46f281abb5b09527ba98ab65e23ddfc Mon Sep 17 00:00:00 2001 From: Maxim Reznik Date: Tue, 3 Oct 2023 20:08:28 +0300 Subject: [PATCH] Don't send snippets in completion if client doesn't support them. --- source/ada/lsp-ada_client_capabilities.adb | 18 ++++++++++++++++++ source/ada/lsp-ada_client_capabilities.ads | 4 ++++ source/ada/lsp-ada_handlers.adb | 4 +++- source/lsp_3.17/lsp-structures-unwrap.ads | 5 +++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/source/ada/lsp-ada_client_capabilities.adb b/source/ada/lsp-ada_client_capabilities.adb index 8b84a726c..6d5fa2367 100644 --- a/source/ada/lsp-ada_client_capabilities.adb +++ b/source/ada/lsp-ada_client_capabilities.adb @@ -63,6 +63,24 @@ package body LSP.Ada_Client_Capabilities is else False); end Code_ActionLiteralSupport; + ------------------------------- + -- Completion_SnippetSupport -- + ------------------------------- + + function Completion_SnippetSupport + (Self : Client_Capability'Class) return Boolean + is + use LSP.Structures.Unwrap; + + Result : constant LSP.Structures.Boolean_Optional := + snippetSupport + (completionItem + (completion + (Self.Value.capabilities.textDocument))); + begin + return (if Result.Is_Set then Result.Value else False); + end Completion_SnippetSupport; + ----------------------------------------------- -- didChangeWatchedFiles_dynamicRegistration -- ----------------------------------------------- diff --git a/source/ada/lsp-ada_client_capabilities.ads b/source/ada/lsp-ada_client_capabilities.ads index f74d2256b..9d22b3f03 100644 --- a/source/ada/lsp-ada_client_capabilities.ads +++ b/source/ada/lsp-ada_client_capabilities.ads @@ -75,6 +75,10 @@ package LSP.Ada_Client_Capabilities is (Self : Client_Capability'Class) return Boolean; -- Returns textDocument.documentSymbol.hierarchicalDocumentSymbolSupport + function Completion_SnippetSupport + (Self : Client_Capability'Class) return Boolean; + -- Returns textDocument.completion.completionItem.snippetSupport + function didChangeWatchedFiles_dynamicRegistration (Self : Client_Capability'Class) return Boolean; -- Returns capabilities.workspace.didChangeWatchedFiles.dynamicRegistration diff --git a/source/ada/lsp-ada_handlers.adb b/source/ada/lsp-ada_handlers.adb index 5b99b61ff..244cb9542 100644 --- a/source/ada/lsp-ada_handlers.adb +++ b/source/ada/lsp-ada_handlers.adb @@ -1633,7 +1633,9 @@ package body LSP.Ada_Handlers is LSP.Ada_Completions.Attributes.Attributes_Completion_Provider; P5 : aliased LSP.Ada_Completions.Names.Name_Completion_Provider - (Self.Configuration.Use_Completion_Snippets); + (Self.Configuration.Use_Completion_Snippets + and then Self.Client.Completion_SnippetSupport); + P6 : aliased LSP.Ada_Handlers.Invisibles.Invisible_Completion_Provider (Self'Access, Context); P7 : aliased diff --git a/source/lsp_3.17/lsp-structures-unwrap.ads b/source/lsp_3.17/lsp-structures-unwrap.ads index 3d766cac5..a01d83b87 100644 --- a/source/lsp_3.17/lsp-structures-unwrap.ads +++ b/source/lsp_3.17/lsp-structures-unwrap.ads @@ -44,6 +44,11 @@ package LSP.Structures.Unwrap is return resolveSupport_OfWorkspaceSymbolClientCapabilities_Optional is (if X.Is_Set then X.Value.resolveSupport else (Is_Set => False)); + function snippetSupport + (X : completionItem_OfCompletionClientCapabilities_Optional) + return Boolean_Optional is + (if X.Is_Set then X.Value.snippetSupport else (Is_Set => False)); + function properties (X : resolveSupport_OfWorkspaceSymbolClientCapabilities_Optional) return LSP.Structures.Virtual_String_Vector is