Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/dap: Return only actual completions
@ 2026-09-13 22:40 Oleg Tolmatcev
  0 siblings, 0 replies; only message in thread
From: Oleg Tolmatcev @ 2026-09-13 22:40 UTC (permalink / raw)
  To: gdb-patches; +Cc: Oleg Tolmatcev

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-13 22:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-13 22:40 [PATCH] gdb/dap: Return only actual completions Oleg Tolmatcev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox