[gnome-builder] completion: Fix completion for php variables



commit 06acb84f3ac0c8bfdb04eaf805ff3078a9da855f
Author: Peter Maatman <blackwolf12333 gmail com>
Date:   Sun Mar 6 22:18:25 2022 +0100

    completion: Fix completion for php variables
    
    ide_completion_context_get_bounds does not include `$` in the bounds so
    when we delete (begin, end) from the text buffer so we can insert the
    text provided by the completion we don't remove the `$`. For php this is
    problematic because the completion includes the `$` prefix, so when we
    insert the completion we end up with 2 `$`.
    
    For example `$t` triggers autocomplete with a proposal `$tree`, we apply the
    proposal and end up with `$$tree`.
    
    This patch also removes the common prefix of the completion item and the
    `begin` GtkTextIter.
    
    Fixes #1641

 src/libide/lsp/ide-lsp-completion-provider.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/lsp/ide-lsp-completion-provider.c b/src/libide/lsp/ide-lsp-completion-provider.c
index bd4cf01d6..8c4b1ad6d 100644
--- a/src/libide/lsp/ide-lsp-completion-provider.c
+++ b/src/libide/lsp/ide-lsp-completion-provider.c
@@ -412,11 +412,13 @@ ide_lsp_completion_provider_activate_proposal (IdeCompletionProvider *provider,
                                                const GdkEventKey     *key)
 {
   g_autoptr(IdeSnippet) snippet = NULL;
+  IdeSnippetChunk *chunk;
   GtkTextBuffer *buffer;
   GtkTextView *view;
   GtkTextIter begin, end;
   g_autoptr(GPtrArray) additional_text_edits;
   IdeBufferManager *buffer_manager;
+  const gchar *text = NULL;
 
   g_assert (IDE_IS_COMPLETION_PROVIDER (provider));
   g_assert (IDE_IS_COMPLETION_CONTEXT (completion_context));
@@ -429,10 +431,15 @@ ide_lsp_completion_provider_activate_proposal (IdeCompletionProvider *provider,
   view = ide_completion_context_get_view (completion_context);
 
   snippet = ide_lsp_completion_item_get_snippet (IDE_LSP_COMPLETION_ITEM (proposal));
+  if ((chunk = ide_snippet_get_nth_chunk (snippet, 0)))
+    text = ide_snippet_chunk_get_text (chunk);
 
   gtk_text_buffer_begin_user_action (buffer);
   if (ide_completion_context_get_bounds (completion_context, &begin, &end))
-    gtk_text_buffer_delete (buffer, &begin, &end);
+    {
+      gtk_text_buffer_delete (buffer, &begin, &end);
+      ide_completion_remove_common_prefix (ide_completion_context_get_completion (completion_context), 
&begin, text);
+    }
   ide_source_view_push_snippet (IDE_SOURCE_VIEW (view), snippet, &begin);
   gtk_text_buffer_end_user_action (buffer);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]