Skip to content

Commit

Permalink
racket-pdb-mode: No longer use racket--module-path-name-at-point
Browse files Browse the repository at this point in the history
This is, for racket-pdb-mode, in the same spirit as commit f67cccd for
racket-xp-mode.

This needs from the pdb repo commit 743c105 adding the
get-require-path function.

The back end command is now called "pdb-visit", which first tries
use->def then tries get-require-path. In other words, "visit
definition or require".
  • Loading branch information
greghendershott committed Apr 28, 2023
1 parent 884f209 commit b5856a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
66 changes: 22 additions & 44 deletions racket-pdb.el
Original file line number Diff line number Diff line change
Expand Up @@ -478,57 +478,35 @@ Uses pdb to query for sites among multiple files."
'racket-pdb-xref)

(cl-defmethod xref-backend-identifier-at-point ((_backend (eql racket-pdb-xref)))
(or (racket--module-path-name-at-point)
(propertize (thing-at-point 'symbol)
'racket-pdb-xref-point (point))))
(propertize (thing-at-point 'symbol)
'racket-pdb-xref-point (point)))

(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql racket-pdb-xref)))
(completion-table-dynamic
(lambda (prefix)
(all-completions prefix racket--xp-binding-completions))))

(cl-defmethod xref-backend-definitions ((_backend (eql racket-pdb-xref)) str)
(or
(pcase (get-text-property 0 'racket-module-path str)
(`absolute
(pcase (racket--cmd/await nil `(mod ,(substring-no-properties str)))
(`(,path ,line ,col)
(list (xref-make str (xref-make-file-location path line col))))))
(`relative
(let ((path (racket--rkt-or-ss-path
(expand-file-name (substring-no-properties str 1 -1)))))
(list (xref-make str (xref-make-file-location path 1 0))))))

(pcase (racket--cmd/await nil
`(pdb-use->def
,(racket-file-name-front-to-back
(racket--buffer-file-name))
,(point)))
(`(,path ,beg ,_end)
(let ((file (racket-file-name-back-to-front path)))
(with-current-buffer
(or (get-file-buffer file)
(let ((find-file-suppress-same-file-warnings t))
(find-file-noselect file)))
(save-restriction
(widen)
(save-excursion
(goto-char beg)
(list (xref-make str
(xref-make-file-location
file
(line-number-at-pos)
(current-column))))))))))
(pcase (racket--cmd/await nil `(def ,(racket-file-name-front-to-back
(racket--buffer-file-name))
,(substring-no-properties str)))
(`(,path ,line ,col)
(list (xref-make str
(xref-make-file-location path line col))))
(`kernel
(list (xref-make str
(xref-make-bogus-location
"Defined in #%%kernel -- source not available")))))))
(pcase (racket--cmd/await nil
`(pdb-visit
,(racket-file-name-front-to-back
(racket--buffer-file-name))
,(point)))
(`(,path ,beg ,_end)
(let ((file (racket-file-name-back-to-front path)))
(with-current-buffer
(or (get-file-buffer file)
(let ((find-file-suppress-same-file-warnings t))
(find-file-noselect file)))
(save-restriction
(widen)
(save-excursion
(goto-char beg)
(list (xref-make str
(xref-make-file-location
file
(line-number-at-pos)
(current-column)))))))))))

(cl-defmethod xref-backend-references ((_backend (eql racket-pdb-xref)) str)
(let* ((back-end-path (racket-file-name-front-to-back (racket--buffer-file-name)))
Expand Down
4 changes: 2 additions & 2 deletions racket/command-server.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
(lazy-require
["commands/check-syntax.rkt" (check-syntax)]
["commands/pdb.rkt" (pdb-available?
pdb-use->def
pdb-visit
pdb-rename-sites
pdb-analyze-path
pdb-point-info
Expand Down Expand Up @@ -159,7 +159,7 @@
[`(pdb-analyze-path ,path ,code) (pdb-analyze-path path code)]
[`(pdb-point-info ,path ,pos ,beg ,end) (pdb-point-info path pos beg end)]
[`(pdb-doc-link ,path ,pos) (pdb-doc-link path pos)]
[`(pdb-use->def ,path, pos) (pdb-use->def path pos)]
[`(pdb-visit ,path, pos) (pdb-visit path pos)]
[`(pdb-rename-sites ,path ,pos) (pdb-rename-sites path pos)]

;; Commands that MIGHT need a REPL session for context (e.g. its
Expand Down
16 changes: 8 additions & 8 deletions racket/commands/pdb.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
pdb-analyze-path
pdb-point-info
pdb-doc-link
pdb-use->def
pdb-visit
pdb-rename-sites)

;;; pdb checked syntax (if available)
Expand All @@ -33,7 +33,7 @@

(define-from-pdb pdb-available?
[analyze-path get-errors get-completion-candidates
get-point-info get-doc-link
get-point-info get-doc-link get-require-path
use->def rename-sites])

(define (pdb-analyze-path path-str code-str)
Expand All @@ -58,12 +58,12 @@
(define (pdb-doc-link path-str pos)
(get-doc-link (string->path path-str) pos))

(define (pdb-use->def path-str pos)
;; The front end xref system wants line:col not [beg end) span. :(
;; Maybe pdb should change to store those, also, for arrow ends?
;; Meanwhile the front end finds the line:col using find-file
;; and goto-char.
(use->def (string->path path-str) pos))
(define (pdb-visit path-str pos)
(define path (string->path path-str))
(or (use->def path pos)
(match (get-require-path path pos)
[(? path? req-path) (list req-path 1 2)]
[#f #f])))

(define (pdb-rename-sites path-str pos)
(rename-sites (string->path path-str) pos))

0 comments on commit b5856a1

Please sign in to comment.