From patchwork Thu Dec 26 22:29:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: oltolm X-Patchwork-Id: 103703 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38D6D3858C41 for ; Thu, 26 Dec 2024 22:31:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38D6D3858C41 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mAyMsiNo X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 669B33858D20 for ; Thu, 26 Dec 2024 22:30:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 669B33858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 669B33858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::631 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735252230; cv=none; b=L2SCF1AuDrkHVc+o61YKB1jWu0cG/skoruM49oX+Imlxqj3n+eX/+dFXvnEImsKnISkRZC56BVsEiCt7mt+2ISI3sGZUI3R7wG7gRQ11qMpTJ4ecjmXkHaKhv2cRmxGwW07y5Y5wisV+qi41HBMour0WA8DuDoL3pb7OJUgUYTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1735252230; c=relaxed/simple; bh=y2iWOW6i1UKFrYIVf5o/p3K5Zs/icY/HIZEk7GY3FrQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=H0O2+nXqfuicQcJRixwXB2FmVP0aqnJB3ptZvCCxqiG8vIeyBHVrw4enzRx+obq6ECTIeO2TZPS4aqUmuqY+vGGtRsAFCO3ugNt+tFE7hulSV3GryAC6DbHn5/ZBcZNIgcIF3XkdV+0uXNheMpRGV8I60MLTIZxzgY5uamVSobg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 669B33858D20 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-aaeef97ff02so409870966b.1 for ; Thu, 26 Dec 2024 14:30:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735252229; x=1735857029; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KrnecoTacpMbIs8uTXnc9r5uuglqirjEPrHNdBPBp3g=; b=mAyMsiNo5EBK5fUBCw9Vc+BBtyDOohZ5zEVKzPS/SYBjypW/wp3t85tJQ01DeZKQJl 6IAeeXzRmz9fYlECEfkEf5R+/U2heX+7n8G/a17Yj5L/+goCa0BM4m4HI+v0GLw+rkY+ wYrB15/aT2pJWqrl999iGtupVUqNPPksQ22EEniWVrVhKG+DXDtTRknNBZqx2xJ+poOK sApHf4gLkSWfTRG1dZ1R9CMa+yD40bT0KG+3Ob8Q8EZS35SKY4G2dqXiGP5idUjLQh2f w1sVHCRbY0BT4UQNVhENL2rp/Tp+XihJtTzrZzDClUJ0x8+QN444v37LHdf+LxOrKh6l igpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735252229; x=1735857029; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KrnecoTacpMbIs8uTXnc9r5uuglqirjEPrHNdBPBp3g=; b=b96t45VMoPOk/Z9bsmR0MiMOQDOCWogfJHf6APGasDkB0MSQ1Ju3pObfuHiWHY269f mZO00SanEJ2ruh0b8rJQhMoUEOY6qe/xxqrzjHmyJ/dpkoZHPzRTrFTGTmDxkRJCM+VQ NDsSHYlYkKJYQ1bfzC++CKbPMs2IFU4KDDi4n8FQC8vMt5W5Es+iM8rtHJc8Px4s9kKw x3l3bGpJZZFXuR/tWx0eNCiCrb5CAEs4wVPjQQdeKHxB9yKARdNpGCSmr+v7Ii81/jem oasDuOJ1eykoyp9Cck2q+/rdnP4ncFdRu5rw5oIXvGuSdihxXln6j8sIswSpJum019tn 0+Fw== X-Gm-Message-State: AOJu0YxHTLYnGt3tFm/jFGjQB5pYdHvsax7O4rbmx+Q7HXEYwEpT1AD/ j3IhidPjF1z7ycJkugRrjbHZI9LtAFvooCpNf4qfEyWBHwN75e+ErGH+zUZCDOU= X-Gm-Gg: ASbGncvc6DEJ9Im+RxuS0tD7FoOM/ZWw3/MXXyH7f/G1wXpJ1iGxVmn6o+AqJukQI2M 7BSG5gkf69NoPvwI16cru4MaRG4n28kFGDaon2b0DCwh8kzeGec0PXQZLcXvhuYmc3NNu96RyGg kd5R91fIoFevgraAFZ7xf3ZcJBC3R2PX2yhg0/jiscXLu94sDh5mBItvg7t2Mnan6sFVpe6A1bd aVb2sKcWVRzqx2iAEuYgS38b3mkAftzkIGQX+FMQf3uRWzeoU8NTPqOtYR0LxzMEf9HgGok2yK/ fl01vdZeJXPCp+TNryssyPr0naYr2UWtagPjwhxwTMyiB+SF3/jU8MATV36SYMyKafU4J+Y= X-Google-Smtp-Source: AGHT+IGh1U0j3k+pbSqbjqnQuB9dzJiPLkkS8fAeLSwoJRUlsFeEAcLuv7Ckr7Sex9CUSiTzrUKtHA== X-Received: by 2002:a17:907:97d2:b0:aa6:ac19:b579 with SMTP id a640c23a62f3a-aac334b5806mr2335871066b.26.1735252228464; Thu, 26 Dec 2024 14:30:28 -0800 (PST) Received: from localhost.localdomain (p200300ed8f42670069237a8cc21e1c06.dip0.t-ipconnect.de. [2003:ed:8f42:6700:6923:7a8c:c21e:1c06]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aac0f016aaasm1013288166b.165.2024.12.26.14.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2024 14:30:27 -0800 (PST) From: oltolm To: gdb-patches@sourceware.org Cc: oltolm , Simon Farre Subject: [PATCH V2] gdb/dap - Add CompletionsRequest Date: Thu, 26 Dec 2024 23:29:47 +0100 Message-ID: <20241226222946.71-2-oleg.tolmatcev@gmail.com> X-Mailer: git-send-email 2.47.1.windows.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org Use GDB/MI command "-complete" to implement. Co-authored-by: Simon Farre Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31140 --- gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/dap/__init__.py | 1 + gdb/python/lib/gdb/dap/completions.py | 50 +++++++++++++++++++++++++++ gdb/python/lib/gdb/dap/server.py | 21 +++++++++-- 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 gdb/python/lib/gdb/dap/completions.py diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index 287dc7ff73..c08a68d16d 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -97,6 +97,7 @@ PYTHON_FILE_LIST = \ gdb/command/xmethods.py \ gdb/dap/breakpoint.py \ gdb/dap/bt.py \ + gdb/dap/completions.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 d12773448e..e39e5b4e0b 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -27,6 +27,7 @@ from . import startup # server object. "F401" is the flake8 "imported but unused" code. from . import breakpoint # noqa: F401 from . import bt # noqa: F401 +from . import completions # noqa: F401 from . import disassemble # noqa: F401 from . import evaluate # noqa: F401 from . import launch # noqa: F401 diff --git a/gdb/python/lib/gdb/dap/completions.py b/gdb/python/lib/gdb/dap/completions.py new file mode 100644 index 0000000000..c89ba38929 --- /dev/null +++ b/gdb/python/lib/gdb/dap/completions.py @@ -0,0 +1,50 @@ +# Copyright 2024 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 . + +from .server import request, capability, import_line, import_column +from .startup import exec_mi_and_log + +from typing import Optional + + +@request("completions") +@capability("supportsCompletionsRequest") +@capability("completionTriggerCharacters", [" ", "."]) +def completions( + *, + frameId: Optional[int] = None, + text: str, + column: int, + line: Optional[int] = None, + **extra +): + column = import_column(column) + if line is None: + line = 1 + else: + line = import_line(line) + for i, l in enumerate(text.splitlines()): + if i + 1 == line: + text = l + break + text = text[: column - 1] + mi_result = exec_mi_and_log("-complete", text) + result = [] + if "completion" in mi_result: + completion = mi_result["completion"] + result.append({"label": completion, "length": len(completion)}) + for match in mi_result["matches"]: + result.append({"label": match, "length": len(match)}) + return {"targets": result} diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 64f48c3250..aab5aa3394 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -49,6 +49,7 @@ _server = None # These are set by the initialize request and are used when rewriting # line or column numbers. _lines_start_at_1 = False +_columns_start_at_1 = False class DeferredRequest: @@ -593,6 +594,8 @@ def initialize(**args): _server.send_event_later("initialized") global _lines_start_at_1 _lines_start_at_1 = client_bool_capability("linesStartAt1", True) + global _columns_start_at_1 + _columns_start_at_1 = client_bool_capability("columnsStartAt1", True) return _capabilities.copy() @@ -698,7 +701,7 @@ def send_gdb_with_response(fn): return val -def export_line(line): +def export_line(line: int) -> int: """Rewrite LINE according to client capability. This applies the linesStartAt1 capability as needed, when sending a line number from gdb to the client.""" @@ -710,7 +713,7 @@ def export_line(line): return line -def import_line(line): +def import_line(line: int) -> int: """Rewrite LINE according to client capability. This applies the linesStartAt1 capability as needed, when the client sends a line number to gdb.""" @@ -720,3 +723,17 @@ def import_line(line): # the client starts at 0. line = line + 1 return line + + +def export_column(column: int) -> int: + """Rewrite COLUMN according to client capability. + This applies the columnsStartAt1 capability as needed, + when sending a column number from gdb to the client.""" + return column if _columns_start_at_1 else column - 1 + + +def import_column(column: int) -> int: + """Rewrite COLUMN according to client capability. + This applies the columnsStartAt1 capability as needed, + when the client sends a column number to gdb.""" + return column if _columns_start_at_1 else column + 1