public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v1] gdb/DAP - Add completionsRequest
@ 2023-06-28 16:26 Simon Farre
  2023-06-29  8:33 ` Lancelot SIX
  2023-07-03 19:11 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Simon Farre @ 2023-06-28 16:26 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Farre

Self-explanatory.
---
 gdb/data-directory/Makefile.in       |  1 +
 gdb/python/lib/gdb/dap/__init__.py   |  1 +
 gdb/python/lib/gdb/dap/completion.py | 45 ++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 gdb/python/lib/gdb/dap/completion.py

diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index a3775a4a666..c1794b5acc7 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -89,6 +89,7 @@ PYTHON_FILE_LIST = \
 	gdb/command/xmethods.py \
 	gdb/dap/breakpoint.py \
 	gdb/dap/bt.py \
+	gdb/dap/completion.py \
 	gdb/dap/disassemble.py \
 	gdb/dap/evaluate.py \
 	gdb/dap/events.py \
diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py
index f3dd3ff7ea8..e2dcde251ee 100644
--- a/gdb/python/lib/gdb/dap/__init__.py
+++ b/gdb/python/lib/gdb/dap/__init__.py
@@ -32,6 +32,7 @@ from . import pause
 from . import scopes
 from . import sources
 from . import threads
+from . import completion
 
 from .server import Server
 
diff --git a/gdb/python/lib/gdb/dap/completion.py b/gdb/python/lib/gdb/dap/completion.py
new file mode 100644
index 00000000000..861d1b28ac9
--- /dev/null
+++ b/gdb/python/lib/gdb/dap/completion.py
@@ -0,0 +1,45 @@
+# Copyright 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gdb
+
+from .server import request, capability
+from .startup import send_gdb_with_response
+
+from typing import Optional
+
+
+def _completions(text: str, column: int, line: Optional[int], frameId: Optional[int]):
+    cmd_output = gdb.execute("complete " + text, to_string=True)
+    result = []
+    for line in cmd_output.splitlines():
+        if "List may be truncated" not in line:
+            result.append({"label": line, "type": "function", "length": len(text)})
+    return {"targets": result}
+
+
+@request("completions")
+@capability("supportsCompletionsRequest")
+@capability("completionTriggerCharacters", [" ", "."])
+def completions(
+    *,
+    text: str,
+    column: int,
+    line: Optional[int] = None,
+    frameId: Optional[int] = None,
+    **extra
+):
+
+    return send_gdb_with_response(lambda: _completions(text, column, line, frameId))
-- 
2.41.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-06 15:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 16:26 [PATCH v1] gdb/DAP - Add completionsRequest Simon Farre
2023-06-29  8:33 ` Lancelot SIX
2023-06-29 12:01   ` Simon Farre
2023-07-03 19:11 ` Tom Tromey
2023-07-05 14:02   ` Simon Farre
2023-07-06 15:16     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).