From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#62837: [PATCH] Add a semantic-symref backend which uses xref-matches-in-files Date: Fri, 14 Apr 2023 11:37:43 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4138"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Dmitry Gutov To: 62837@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 14 17:38:24 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pnLVI-0000tn-2z for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 14 Apr 2023 17:38:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pnLV4-0003vm-O1; Fri, 14 Apr 2023 11:38:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pnLUy-0003vV-AV for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 11:38:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pnLUw-0000zl-8d for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 11:38:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pnLUw-0007Ip-3L for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 11:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 14 Apr 2023 15:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 62837 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.168148667128051 (code B ref -1); Fri, 14 Apr 2023 15:38:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 14 Apr 2023 15:37:51 +0000 Original-Received: from localhost ([127.0.0.1]:47343 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pnLUk-0007IL-1z for submit@debbugs.gnu.org; Fri, 14 Apr 2023 11:37:50 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:49996) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pnLUi-0007IA-4r for submit@debbugs.gnu.org; Fri, 14 Apr 2023 11:37:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pnLUh-0003tR-U5 for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 11:37:47 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pnLUe-0000w4-PJ for bug-gnu-emacs@gnu.org; Fri, 14 Apr 2023 11:37:47 -0400 Received-SPF: pass client-ip=64.215.233.18; envelope-from=sbaugh@janestreet.com; helo=mxout5.mail.janestreet.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:259931 Archived-At: --=-=-= Content-Type: text/plain Tags: patch When project-files is available, this is a much more efficient fallback than the current grep fallback. Ultimately, this is motivated by making xref-find-references faster by default even in the absence of an index. * lisp/cedet/semantic/symref/project.el: Add. * lisp/cedet/semantic/symref.el (semantic-symref-tool-alist): Add project tool In GNU Emacs 29.0.60 (build 3, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2023-03-13 built on igm-qws-u22796a Repository revision: e759905d2e0828eac4c8164b09113b40f6899656 Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: CentOS Linux 7 (Core) Configured using: 'configure --with-x-toolkit=lucid --with-modules --with-gif=ifavailable' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-a-semantic-symref-backend-which-uses-xref-matche.patch >From 2241f428f0d4809d00f397aafd97270272e966e0 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Fri, 14 Apr 2023 11:26:49 -0400 Subject: [PATCH] Add a semantic-symref backend which uses xref-matches-in-files When project-files is available, this is a much more efficient fallback than the current grep fallback. Ultimately, this is motivated by making xref-find-references faster by default even in the absence of an index. * lisp/cedet/semantic/symref/project.el: Add. * lisp/cedet/semantic/symref.el (semantic-symref-tool-alist): Add project tool --- lisp/cedet/semantic/symref.el | 2 + lisp/cedet/semantic/symref/project.el | 73 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 lisp/cedet/semantic/symref/project.el diff --git a/lisp/cedet/semantic/symref.el b/lisp/cedet/semantic/symref.el index 1ebd7ea154b..7dfe892b7e8 100644 --- a/lisp/cedet/semantic/symref.el +++ b/lisp/cedet/semantic/symref.el @@ -93,6 +93,8 @@ semantic-symref-tool-alist idutils) ( (lambda (rootdir) (file-exists-p (expand-file-name "cscope.out" rootdir))) . cscope ) + ( (lambda (rootdir) (project-current nil rootdir)) . + project) ) "Alist of tools usable by `semantic-symref'. Each entry is of the form: diff --git a/lisp/cedet/semantic/symref/project.el b/lisp/cedet/semantic/symref/project.el new file mode 100644 index 00000000000..e822e7a2ba3 --- /dev/null +++ b/lisp/cedet/semantic/symref/project.el @@ -0,0 +1,73 @@ +;;; semantic/symref/project.el --- Symref implementation using project and xref -*- lexical-binding: t; -*- + +;; Copyright (C) 2008-2023 Free Software Foundation, Inc. + +;; Author: Spencer Baugh + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see . + +;;; Commentary: +;; +;; Implement the symref tool API using project-files and +;; xref-matches-in-files, which in turn use grep or more efficient +;; tools if available. +;; +;; This is basically a replacement for the symref GREP tool, as a new +;; lowest-common-denominator which works without indices or +;; project-specific configuration. It has better performance than the +;; GREP tool because project-files provides a narrower set of files to +;; search, and xref-matches-in-files is highly efficient. + +(require 'semantic/symref) +(require 'project) +(require 'xref) + +;;; Code: + +;;;###autoload +(defclass semantic-symref-tool-project (semantic-symref-tool-baseclass) () + "A symref tool implementation using project.el. +This uses `xref-matches-in-files' over `project-files'") + +(cl-defmethod semantic-symref-perform-search ((tool semantic-symref-tool-project)) + (pcase-let + (((eieio + searchfor + (searchtype (or 'symbol 'regexp)) + ;; for now, we only really support being called by + ;; xref-backend-references, and this is what it passes. + (resulttype 'line-and-text)) + tool)) + (mapcar + (pcase-lambda + ((cl-struct xref-match-item + summary (location + (cl-struct xref-file-location file line)))) + (list line file summary)) + (xref-matches-in-files searchfor (project-files (project-current)))))) + +(add-to-list 'semantic-symref-tool-alist + '((lambda (rootdir) (project-current nil rootdir)) + . project)) + +(provide 'semantic/symref/project) + +;; Local variables: +;; generated-autoload-file: "../loaddefs.el" +;; generated-autoload-load-name: "semantic/symref/project" +;; End: + +;;; semantic/symref/project.el ends here -- 2.30.2 --=-=-=--