Skip to content

Commit d9317f2

Browse files
authored
Add configuration for excluding declarations from xrefs/references (#3655)
1 parent 0f56580 commit d9317f2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.org

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* Add setting UPDATE_EXPECT=1 when running `expect!` tests ~lsp-rust~
3939
* Add ~lsp-use-workspace-root-for-server-default-directory~.
4040
* Add [[https://github.com/artempyanykh/marksman][marksman]] support.
41-
* ~lsp-find-references~ to include declaration by default
41+
* ~lsp-find-references~ to include declaration by default (configurable with ~lsp-references-exclude-definition~)
4242
* Add [[https://github.com/ruby-syntax-tree/syntax_tree][syntax_tree]] support for Ruby code.
4343
** Release 8.0.0
4444
* Add ~lsp-clients-angular-node-get-prefix-command~ to get the Angular server from another location which is still has ~/lib/node_modules~ in it.

lsp-mode.el

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ If this is set to nil, `eldoc' will show only the symbol information."
504504
:type 'boolean
505505
:group 'lsp-mode)
506506

507+
(defcustom lsp-references-exclude-definition nil
508+
"If non-nil, exclude declarations when finding references."
509+
:type 'boolean
510+
:group 'lsp-mode)
511+
507512
(defcustom lsp-enable-indentation t
508513
"Indent regions using the file formatting functionality provided by the
509514
language server."
@@ -5984,7 +5989,7 @@ perform the request synchronously."
59845989
(goto-char (cl-rest (or (assoc identifier lsp--symbols-cache)
59855990
(user-error "Unable to find symbol %s" identifier)))))
59865991
(lsp--locations-to-xref-items (lsp-request "textDocument/references"
5987-
(lsp--make-reference-params)))))
5992+
(lsp--make-reference-params nil lsp-references-exclude-definition)))))
59885993

59895994
(cl-defmethod xref-backend-apropos ((_backend (eql xref-lsp)) pattern)
59905995
(seq-map #'lsp--symbol-information-to-xref
@@ -6155,7 +6160,7 @@ REFERENCES? t when METHOD returns references."
61556160
"Find references of the symbol under point."
61566161
(interactive "P")
61576162
(lsp-find-locations "textDocument/references"
6158-
(list :context `(:includeDeclaration ,(lsp-json-bool (not exclude-declaration))))
6163+
(list :context `(:includeDeclaration ,(lsp-json-bool (not (or exclude-declaration lsp-references-exclude-definition)))))
61596164
:display-action display-action
61606165
:references? t))
61616166

0 commit comments

Comments
 (0)