public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Farre <simon.farre.cx@gmail.com>
To: gdb-patches@sourceware.org
Cc: Simon Farre <simon.farre.cx@gmail.com>
Subject: [PATCH v1] gdb/DAP - Add completionsRequest
Date: Wed, 28 Jun 2023 18:26:16 +0200	[thread overview]
Message-ID: <20230628162616.102268-1-simon.farre.cx@gmail.com> (raw)

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


             reply	other threads:[~2023-06-28 16:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28 16:26 Simon Farre [this message]
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

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=20230628162616.102268-1-simon.farre.cx@gmail.com \
    --to=simon.farre.cx@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).