3434
3535; ;; Code:
3636
37+ (require 'lsp-protocol )
3738(require 'lsp-mode )
3839(require 'xref )
3940(require 'dash )
@@ -566,7 +567,8 @@ XREFS is a list of references/definitions."
566567
567568(defun lsp-ui-peek--find-xrefs (input method param )
568569 " Find INPUT references.
569- KIND is ‘references’, ‘definitions’ or a custom kind."
570+ METHOD is ‘references’, ‘definitions’, `implementation` or a custom kind.
571+ PARAM is the request params."
570572 (setq lsp-ui-peek--method method)
571573 (let ((xrefs (lsp-ui-peek--get-references method param)))
572574 (unless xrefs
@@ -578,11 +580,12 @@ KIND is ‘references’, ‘definitions’ or a custom kind."
578580 (not (cdr xrefs))
579581 (= (length (plist-get (car xrefs) :xrefs )) 1 ))
580582 (let ((x (car (plist-get (car xrefs) :xrefs ))))
581- (-if-let (uri (gethash " uri" x))
582- (-let (((&hash " start" (&hash " line" " character" )) (gethash " range" x)))
583+ (-if-let (uri (lsp:location- uri x))
584+ (-let (((&Range : start (&Position : line : character )) (lsp:location- range x)))
583585 (lsp-ui-peek--goto-xref `(:file ,(lsp--uri-to-path uri) :line , line :column , character )))
584- (-let (((&hash " start" (&hash " line" " character" )) (or (gethash " targetSelectionRange" x) (gethash " targetRange" x))))
585- (lsp-ui-peek--goto-xref `(:file ,(lsp--uri-to-path (gethash " targetUri" x)) :line , line :column , character )))))
586+ (-let (((&Range :start (&Position :line :character )) (or (lsp:location-link-target-selection-range x)
587+ (lsp:location-link-target-range x))))
588+ (lsp-ui-peek--goto-xref `(:file ,(lsp--uri-to-path (lsp:location-link-target-uri x)) :line , line :column , character )))))
586589 (lsp-ui-peek-mode)
587590 (lsp-ui-peek--show xrefs))))
588591
@@ -610,7 +613,7 @@ The symbols are found matching PATTERN."
610613 (interactive (list (read-string " workspace/symbol: "
611614 nil 'xref--read-pattern-history )))
612615 (lsp-ui-peek--find-xrefs pattern " workspace/symbol"
613- (append extra (list :query pattern))))
616+ (append extra (lsp-make-workspace-symbol-params :query pattern))))
614617
615618(defun lsp-ui-peek-find-custom (method &optional extra )
616619 " Find custom references.
@@ -639,21 +642,23 @@ START and END are delimiters."
639642 `(, line . ,(concat before line after))))))
640643
641644(defun lsp-ui-peek--xref-make-item (filename loc )
642- " Return an item from a LOCATION in FILENAME .
645+ " Return an item from FILENAME given a LOC .
643646LOCATION can be either a LSP Location or SymbolInformation."
644647 ; ; TODO: Read more informations from SymbolInformation.
645648 ; ; For now, only the location is used.
646- (-let* ((loc (or (gethash " location" loc) loc))
647- (range (or (gethash " range" loc) (gethash " targetSelectionRange" loc) (gethash " targetRange" loc)))
648- ((&hash " start" pos-start " end" pos-end) range)
649- ((&hash " line" start-line " character" start-col) pos-start)
650- ((&hash " line" end-line " character" end-col) pos-end)
649+ (-let* ((loc (or (lsp:symbol-information-location loc) loc))
650+ (range (or (lsp:location-range loc)
651+ (lsp:location-link-target-selection-range loc)
652+ (lsp:location-link-target-range loc)))
653+ ((&Range :start pos-start :end pos-end) range)
654+ ((&Position :line start-line :character start-col) pos-start)
655+ ((&Position :line end-line :character end-col) pos-end)
651656 ((line . chunk) (lsp-ui-peek--extract-chunk-from-buffer pos-start start-col
652657 (when (= start-line end-line) end-col))))
653658 (list :summary (or line filename)
654659 :chunk (or chunk filename)
655660 :file filename
656- :line ( gethash " line " pos- start)
661+ :line start-line
657662 :column start-col)))
658663
659664(defun lsp-ui-peek--fontify-buffer (filename )
@@ -697,19 +702,23 @@ references. The function returns a list of `ls-xref-item'."
697702 " Get all references/definitions for the symbol under point.
698703Returns item(s)."
699704 (-when-let* ((locs (lsp-request method params))
700- (locs (if (listp locs) locs (if (vectorp locs) (append locs nil ) (list locs)))))
705+ (locs (if (listp locs)
706+ locs
707+ (if (vectorp locs)
708+ (append locs nil )
709+ (list locs)))))
701710 (-filter
702711 (-lambda ((&plist :file ))
703712 (or (f-file? file)
704713 (ignore
705714 (lsp-log " The following file %s is missing, ignoring from the results."
706715 file))))
707716 (mapcar #'lsp-ui-peek--get-xrefs-list
708- (if (gethash " uri" (car locs))
717+ (if (lsp:location- uri (car locs))
709718 ; ; Location[]
710- (--group-by (lsp--uri-to-path (gethash " uri" it)) locs)
719+ (--group-by (lsp--uri-to-path (lsp:location- uri it)) locs)
711720 ; ; LocationLink[]
712- (--group-by (lsp--uri-to-path (gethash " targetUri " it)) locs))))))
721+ (--group-by (lsp--uri-to-path (lsp:location-link-target-uri it)) locs))))))
713722
714723(defvar lsp-ui-mode-map )
715724
0 commit comments