Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>
To: gdb-patches@sourceware.org
Cc: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>
Subject: [PATCH] gdb/dap: Return only actual completions
Date: Mon, 14 Sep 2026 00:40:07 +0200	[thread overview]
Message-ID: <20260913224006.1748-2-oleg.tolmatcev@gmail.com> (raw)

The MI completion result may repeat the input text when completion is
ambiguous.  Do not expose that common-prefix value as a DAP completion
item; return only the actual matches instead.

Update the completion test to compare the complete label list and verify
that the input text is omitted.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34592
---
 gdb/python/lib/gdb/dap/completions.py | 12 ------------
 gdb/testsuite/gdb.dap/completions.exp | 23 ++++++++++++++---------
 2 files changed, 14 insertions(+), 21 deletions(-)

This patch is based on the patch in https://sourceware.org/pipermail/gdb-patches/2026-September/230035.html.

diff --git a/gdb/python/lib/gdb/dap/completions.py b/gdb/python/lib/gdb/dap/completions.py
index 8495e4f8b6b..48f698a084f 100644
--- a/gdb/python/lib/gdb/dap/completions.py
+++ b/gdb/python/lib/gdb/dap/completions.py
@@ -46,18 +46,6 @@ def completions(
         text = ""
     mi_result = exec_mi_and_log("-complete", text)
     result = []
-    completion = None
-    if "completion" in mi_result:
-        completion = mi_result["completion"]
-        result.append({"label": completion, "length": len(text)})
-    # If `-complete' finds one match then `completion' and `matches'
-    # will contain the same one match.
-    if (
-        completion is not None
-        and len(mi_result["matches"]) == 1
-        and completion == mi_result["matches"][0]
-    ):
-        return {"targets": result}
     for match in mi_result["matches"]:
         result.append({"label": match, "length": len(text)})
     return {"targets": result}
diff --git a/gdb/testsuite/gdb.dap/completions.exp b/gdb/testsuite/gdb.dap/completions.exp
index f79f9ba07a1..b5b0ad840b7 100644
--- a/gdb/testsuite/gdb.dap/completions.exp
+++ b/gdb/testsuite/gdb.dap/completions.exp
@@ -58,11 +58,18 @@ set pfx "print unique_enough_prefix_"
 set col [string length $pfx]
 
 proc check_results {actual args} {
-    foreach item $actual suffix $args {
-	set value [dict get $item label]
-	gdb_assert {$value == [string cat $::pfx $suffix]} \
-	    "checking suffix $suffix"
+    set actual_labels {}
+    foreach item $actual {
+	lappend actual_labels [dict get $item label]
     }
+
+    set expected_labels {}
+    foreach suffix $args {
+	lappend expected_labels [string cat $::pfx $suffix]
+    }
+
+    gdb_assert {$actual_labels == $expected_labels} \
+	"checking completion results"
 }
 
 set result [lindex [dap_check_request_and_response \
@@ -72,7 +79,7 @@ set result [lindex [dap_check_request_and_response \
 		0]
 
 with_test_prefix inner_frame {
-    check_results [dict get $result body targets] "" 1 2 4
+    check_results [dict get $result body targets] 1 2 4
 }
 
 set result [lindex [dap_check_request_and_response \
@@ -82,9 +89,7 @@ set result [lindex [dap_check_request_and_response \
 		0]
 
 with_test_prefix outer_frame {
-    # The empty string here is wrong.  gdb should not return the
-    # argument text.  See PR dap/34592.
-    check_results [dict get $result body targets] "" 1 2 3
+    check_results [dict get $result body targets] 1 2 3
 }
 
 set result [lindex [dap_check_request_and_response \
@@ -96,7 +101,7 @@ set result [lindex [dap_check_request_and_response \
 with_test_prefix "no frame" {
     # Note that the result '3' here is actually wrong.  gdb should
     # ignore the selected frame.  See PR dap/34591.
-    check_results [dict get $result body targets] "" 1 2 3
+    check_results [dict get $result body targets] 1 2 3
 }
 
 # The result here isn't important, this is just checking that the
-- 
2.55.0.windows.5


                 reply	other threads:[~2026-09-13 22:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260913224006.1748-2-oleg.tolmatcev@gmail.com \
    --to=oleg.tolmatcev@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox