From 7ea4247c3d48d1b56d97ebb81949eb2cce2ce6f9 Mon Sep 17 00:00:00 2001 From: 0x4448 <86135470+0x4448@users.noreply.github.com> Date: Sun, 17 Sep 2023 13:50:29 -0700 Subject: [PATCH] Omit quotes from completion if triggered with quote Typing a single or double quote in an external editor triggers auto-completion. The returned CompletionItem should not include quotes since they're already in the editor. CompletionParams was missing context in to_json() and this is required to detect whether a quote was typed. --- .../language_server/gdscript_text_document.cpp | 9 +++++++++ modules/gdscript/language_server/godot_lsp.h | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 1e927f9f6ed..d6779dc71c6 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -346,6 +346,15 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) { } } + if (item.kind == lsp::CompletionItemKind::Method) { + bool is_trigger_character = params.context.triggerKind == lsp::CompletionTriggerKind::TriggerCharacter; + bool is_quote_character = params.context.triggerCharacter == "\"" || params.context.triggerCharacter == "'"; + + if (is_trigger_character && is_quote_character && item.insertText.is_quoted()) { + item.insertText = item.insertText.unquote(); + } + } + return item.to_json(true); } diff --git a/modules/gdscript/language_server/godot_lsp.h b/modules/gdscript/language_server/godot_lsp.h index 1ac4267c7bf..e09adb74bd8 100644 --- a/modules/gdscript/language_server/godot_lsp.h +++ b/modules/gdscript/language_server/godot_lsp.h @@ -1429,6 +1429,17 @@ struct CompletionParams : public TextDocumentPositionParams { TextDocumentPositionParams::load(p_params); context.load(p_params["context"]); } + + Dictionary to_json() { + Dictionary ctx; + ctx["triggerCharacter"] = context.triggerCharacter; + ctx["triggerKind"] = context.triggerKind; + + Dictionary dict; + dict = TextDocumentPositionParams::to_json(); + dict["context"] = ctx; + return dict; + } }; /**