From c07d1d0de8594130bdc2feac846c01c84c1b368a Mon Sep 17 00:00:00 2001 From: Kurt Lachmann Date: Thu, 24 Mar 2022 20:24:47 +0100 Subject: [PATCH] Use insertText from the internal autocompletion * GDScriptLanguage::complete_code already adds parentheses to function calls, and does this a lot smarter than the language server right now. * Instead of the previous naive approach we now reuse the same logic as the internal editor. * For this to have any effect we also have to send the `insertText` field already during the completionRequest and not only during resolve. (cherry picked from commit bbb07ff8cbd182c46f988b192b2d3882ed78cd5c) --- .../gdscript/language_server/gdscript_text_document.cpp | 8 ++------ modules/gdscript/language_server/lsp.hpp | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 1412ad0e5de..3460b812a9b 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -171,6 +171,7 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) { lsp::CompletionItem item; item.label = option.display; item.data = request_data; + item.insertText = option.insert_text; switch (option.kind) { case ScriptCodeCompletionOption::KIND_ENUM: @@ -278,12 +279,7 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) { item.documentation = symbol->render(); } - if ((item.kind == lsp::CompletionItemKind::Method || item.kind == lsp::CompletionItemKind::Function) && !item.label.ends_with("):")) { - item.insertText = item.label + "("; - if (symbol && symbol->children.empty()) { - item.insertText += ")"; - } - } else if (item.kind == lsp::CompletionItemKind::Event) { + if (item.kind == lsp::CompletionItemKind::Event) { if (params.context.triggerKind == lsp::CompletionTriggerKind::TriggerCharacter && (params.context.triggerCharacter == "(")) { const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\""; item.insertText = quote_style + item.label + quote_style; diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp index 07b42bb86c0..3b7aa3b0b9f 100644 --- a/modules/gdscript/language_server/lsp.hpp +++ b/modules/gdscript/language_server/lsp.hpp @@ -1004,8 +1004,8 @@ struct CompletionItem { dict["label"] = label; dict["kind"] = kind; dict["data"] = data; + dict["insertText"] = insertText; if (resolved) { - dict["insertText"] = insertText; dict["detail"] = detail; dict["documentation"] = documentation.to_json(); dict["deprecated"] = deprecated;