From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Fangrui Song Newsgroups: gmane.emacs.bugs Subject: bug#29619: Fwd: [xref.el] Add `xref-find-references` to `xref-prompt-for-identifier` Date: Sun, 10 Dec 2017 23:18:54 -0800 Message-ID: <20171211071854.qfrignlnlj57yzgl@hacking> References: <0e97609a-eefc-6e0d-ce2b-6c69651d9990@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: blaine.gmane.org 1512977127 30560 195.159.176.226 (11 Dec 2017 07:25:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 11 Dec 2017 07:25:27 +0000 (UTC) User-Agent: NeoMutt/20170714-126-deb55f (1.8.3) Cc: 29619@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 11 08:25:23 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOISn-0007ei-3b for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Dec 2017 08:25:21 +0100 Original-Received: from localhost ([::1]:51147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOISu-0004QS-Bz for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Dec 2017 02:25:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34131) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOIRa-0003XM-FS for bug-gnu-emacs@gnu.org; Mon, 11 Dec 2017 02:24:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOIRW-0005bT-Aa for bug-gnu-emacs@gnu.org; Mon, 11 Dec 2017 02:24:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47293) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOIRW-0005bI-5R for bug-gnu-emacs@gnu.org; Mon, 11 Dec 2017 02:24:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eOIRV-0002IJ-VZ for bug-gnu-emacs@gnu.org; Mon, 11 Dec 2017 02:24:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Fangrui Song Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Dec 2017 07:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29619 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: wontfix Original-Received: via spool by 29619-submit@debbugs.gnu.org id=B29619.15129770198783 (code B ref 29619); Mon, 11 Dec 2017 07:24:01 +0000 Original-Received: (at 29619) by debbugs.gnu.org; 11 Dec 2017 07:23:39 +0000 Original-Received: from localhost ([127.0.0.1]:55974 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOIR9-0002Hb-3l for submit@debbugs.gnu.org; Mon, 11 Dec 2017 02:23:39 -0500 Original-Received: from mail-pg0-f47.google.com ([74.125.83.47]:36668) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOIR6-0002HM-5K for 29619@debbugs.gnu.org; Mon, 11 Dec 2017 02:23:37 -0500 Original-Received: by mail-pg0-f47.google.com with SMTP id k134so10350007pga.3 for <29619@debbugs.gnu.org>; Sun, 10 Dec 2017 23:23:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=uTh2q/5wAhrCDXj75zlNmMrxmppgmJX+GmTnxru0oio=; b=bZ854hgAQdzdmHz48ScYLlj8IzKWL3JLJyV6vg1xksseJIzxcuM8H6rP28NWpv1XCG afVWFzx9NTyiNmPXmzPEL439QnYcpy1X9SmUQDHZVi1q7b0rP3NRV+frbHMjY8UQf7+S un0cv70j3kiC32yM4xooC+/bcmyUJA75d3W1NvSpwbcUP+REoF/XSqVa8iuZojHW2fUe yt2O3GRS1Ki3jW6+5+Q99wOHsr3v/jGp/wtYWVXTj2thwZ09KslKZYCne9fTMjZQDpbO Xas8mncWk217i+rPtF1VEfXMD8hOEEAkym0SiiPxFLUr25Swb2719/f6VZ5sorAXmqcI HqHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=uTh2q/5wAhrCDXj75zlNmMrxmppgmJX+GmTnxru0oio=; b=QQC5bN9yftcdcsLke9o/TuysiXUjAoM5woB+a6T0nCavX6Lk5aUgUJUUhoQMNLmEA5 gOpxtrFnmtF8nTvDjrTGJPYb3XPfF7uldYudztZt54C1XyRqurwZIddJy40K9DPAJaSh H+poUyJ5UPhIWNBFBocmFSf8NzgUprsCJR/n9Ndb+zjG8Rnn7SqgjBwMfORus3widUJB BqaEbX8VMIVyMXulsLSTuowX1LCjzhpVwDEFjeCtnd+7mDZag2HAbLWQTdx+KFOnxfY4 3HJyC4cNoBUzUZkWeQtf1VIBBM9eOjCB+j0K5hJs3Xu9NfPT/7yOAWPp/FriQZIMc5r2 4VHw== X-Gm-Message-State: AKGB3mKK+pWsIKnHBaQzqn3tYxm/uzXRfD80h9oUO/evZR5k5VmWT3UP lJETphqHJHQNRfpBShvoY9I= X-Google-Smtp-Source: AGs4zMYIaAI0aYYBxCJR4jvBJ4LM4N2ENaGPPlengDHYYeEMilz+XbDhONcpTwnjCAMWcOaA3RF24g== X-Received: by 10.98.58.29 with SMTP id h29mr6430850pfa.121.1512977009855; Sun, 10 Dec 2017 23:23:29 -0800 (PST) Original-Received: from localhost (c-24-130-65-8.hsd1.ca.comcast.net. [24.130.65.8]) by smtp.gmail.com with ESMTPSA id a87sm26293122pfg.159.2017.12.10.23.23.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Dec 2017 23:23:29 -0800 (PST) Content-Disposition: inline In-Reply-To: <0e97609a-eefc-6e0d-ce2b-6c69651d9990@yandex.ru> X-PGP-Key: http://maskray.me/pubkey.asc X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:140918 Archived-At: On 2017-12-10, Dmitry Gutov wrote: >On 12/9/17 7:52 PM, Ray wrote: >>Thanks for being open to change the default if more people feel the same. >> >>With the xref system people use drifting from tag based >>(ctags,etags,GNU GLOBAL,cscope,...) tools to Language Server Protocol >>(cquery, rls, ...), >>a single identifier without position has become insufficient to >>describe the one the user wants to look up. For example, a local >>variable/struct/lambda `foo` may exist >>in different functions. > >That's fine, actually, and as designed. As long as the different >global identifiers can be represented uniquely as strings (but using >text properties for e.g. a local variable at point is good too). >>I'm using a C++ language server called cquery. This is what I get (for >>the argument `identifier`) when I hit the key bound to >>`xref-find-definitions`: >> >>#("QueryDatabase" 0 13 (fontified t ref-params (:textDocument (:uri >>"file:///home/maskray/Dev/Util/cquery/src/query_utils.h") :position >>(:line 11 :character 54) :context (:includeDeclaration :json-false)) >>def-params (:textDocument (:uri >>"file:///home/maskray/Dev/Util/cquery/src/query_utils.h") :position >>(:line 11 :character 54)))) >> >>Here the text properties are more useful than the identifier itself, >>because LSP uses position instead of identifier to sending requests to >>the language server. >>https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textdocumentpositionparams > >So it doesn't actually let you choose? Only supports the identifier at >point? The identifier (if chosen from xref prompt) is ignored by Language Server Protocol and only the position information is what matters. According to https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textDocument_references When the user wants to find a reference of an identifier, information of the following interface is sent to language servers. interface ReferenceParams extends TextDocumentPositionParams { context: ReferenceContext } TextDocumentPositionParams is the interesting one: interface TextDocumentPositionParams { textDocument: TextDocumentIdentifier; /// wrapper of filename position: Position; /// line, column; see, no identifier is used } lsp-mode provides a backend of xref generic functions. Here is how xref-find-references is implemented in lsp-mode: https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-methods.el#L1425 (cl-defmethod xref-backend-references ((_backend (eql xref-lsp)) identifier) (let* ((properties (text-properties-at 0 identifier)) (params (plist-get properties 'ref-params)) (refs (lsp--send-request (lsp--make-request "textDocument/references" (or params (lsp--make-reference-params)))))) (lsp--locations-to-xref-items refs))) The `identifier` text itself is ignored and only the text properties (which encode position information) are used.