Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/improve declaration handling in lsp-ui-*find-*references #759

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lsp-ui-peek.el
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,15 @@ PARAM is the request params."
(lsp-ui-peek--show xrefs))))

(defun lsp-ui-peek-find-references (&optional include-declaration extra)
"Find references to the IDENTIFIER at point."
(interactive)
"Find references to the IDENTIFIER at point.

With a prefix argument, or if INCLUDE-DECLARATION is non-nil,
includes the declaration of the identifier in the results."
(interactive "P")
(lsp-ui-peek--find-xrefs (symbol-at-point) "textDocument/references"
(append extra (lsp--make-reference-params nil include-declaration))))
(append extra (lsp--make-reference-params
nil
(not include-declaration)))))

(defun lsp-ui-peek-find-definitions (&optional extra)
"Find definitions to the IDENTIFIER at point."
Expand Down
12 changes: 6 additions & 6 deletions lsp-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ Both should have the form (FILENAME LINE COLUMN)."
(< (cadr x) (cadr y))
(< (caddr x) (caddr y)))))

(defun lsp-ui--reference-triples (include-declaration)
(defun lsp-ui--reference-triples (exclude-declaration)
"Return references as a list of (FILENAME LINE COLUMN) triples given EXTRA."
(let ((refs (lsp-request "textDocument/references"
(lsp--make-reference-params nil include-declaration))))
(lsp--make-reference-params nil exclude-declaration))))
(sort
(mapcar
(-lambda ((&Location :uri :range (&Range :start (&Position :line :character))))
Expand All @@ -139,11 +139,11 @@ Both should have the form (FILENAME LINE COLUMN)."
#'lsp-ui--location<)))

;; TODO Make it efficient
(defun lsp-ui-find-next-reference (&optional include-declaration)
(defun lsp-ui-find-next-reference (&optional exclude-declaration)
"Find next reference of the symbol at point."
(interactive)
(let* ((cur (list buffer-file-name (1- (line-number-at-pos)) (- (point) (line-beginning-position))))
(refs (lsp-ui--reference-triples include-declaration))
(refs (lsp-ui--reference-triples exclude-declaration))
(idx -1)
(res (-first (lambda (ref) (cl-incf idx) (lsp-ui--location< cur ref)) refs)))
(if res
Expand All @@ -156,11 +156,11 @@ Both should have the form (FILENAME LINE COLUMN)."
(cons 0 0))))

;; TODO Make it efficient
(defun lsp-ui-find-prev-reference (&optional include-declaration)
(defun lsp-ui-find-prev-reference (&optional exclude-declaration)
"Find previous reference of the symbol at point."
(interactive)
(let* ((cur (list buffer-file-name (1- (line-number-at-pos)) (- (point) (line-beginning-position))))
(refs (lsp-ui--reference-triples include-declaration))
(refs (lsp-ui--reference-triples exclude-declaration))
(idx -1)
(res (-last (lambda (ref) (and (lsp-ui--location< ref cur) (cl-incf idx))) refs)))
(if res
Expand Down