-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Make jump-to-definition work in projects needing cider-path-translations
#3414
Changes from all commits
4175aee
8065664
c78de45
a6e6e8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -614,8 +614,9 @@ REPL defaults to the current REPL." | |
(sesman-more-recent-p (cdr session1) (cdr session2))) | ||
|
||
(declare-function cider-classpath-entries "cider-client") | ||
(cl-defmethod sesman-friendly-session-p ((_system (eql CIDER)) session) | ||
"Check if SESSION is a friendly session." | ||
|
||
(defun cider--sesman-friendly-session-p (session &optional debug) | ||
"Check if SESSION is a friendly session, DEBUG optionally." | ||
(setcdr session (seq-filter #'buffer-live-p (cdr session))) | ||
(when-let* ((repl (cadr session)) | ||
(proc (get-buffer-process repl)) | ||
|
@@ -644,7 +645,33 @@ REPL defaults to the current REPL." | |
(or (seq-find (lambda (path) (string-prefix-p path file)) | ||
classpath) | ||
(seq-find (lambda (path) (string-prefix-p path file)) | ||
classpath-roots)))))) | ||
classpath-roots) | ||
(when-let* ((cider-path-translations (cider--all-path-translations)) | ||
(translated (cider--translate-path file 'to-nrepl :return-all))) | ||
(seq-find (lambda (translated-path) | ||
(or (seq-find (lambda (path) | ||
(string-prefix-p path translated-path)) | ||
classpath) | ||
(seq-find (lambda (path) | ||
(string-prefix-p path translated-path)) | ||
classpath-roots))) | ||
translated)) | ||
(when debug | ||
(list file "was not determined to belong to classpath:" classpath "or classpath-roots:" classpath-roots))))))) | ||
|
||
(defun cider-debug-sesman-friendly-session-p () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this named as a predicate? You might want to mention it somewhere in the troubleshooting/sesman docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Funny you ask, I intended it to read Alternative welcome. Good call on adding it to the manual! |
||
"`message's debugging information relative to friendly sessions. | ||
|
||
This is useful for when one sees 'No linked CIDER sessions' | ||
in an unexpected place." | ||
(interactive) | ||
(message (prin1-to-string (mapcar (lambda (session) | ||
(cider--sesman-friendly-session-p session t)) | ||
(sesman--all-system-sessions 'CIDER))))) | ||
|
||
(cl-defmethod sesman-friendly-session-p ((_system (eql CIDER)) session) | ||
"Check if SESSION is a friendly session." | ||
(cider--sesman-friendly-session-p session)) | ||
|
||
(defvar cider-sesman-browser-map | ||
(let ((map (make-sparse-keymap))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
((nil . ((eval . (customize-set-variable 'cider-path-translations | ||
(list | ||
(cons "/src" (clojure-project-dir)) | ||
(cons "/root/.m2" (concat (getenv "HOME") "/.m2")))))))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM clojure:temurin-17-lein-bullseye | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This is a different Dockerfile from that of #3412) |
||
ENV DEBIAN_FRONTEND=noninteractive | ||
ENV NREPL_PORT=7888 | ||
WORKDIR /root/app | ||
COPY . /root/app | ||
RUN lein deps | ||
EXPOSE 7888 | ||
RUN lein classpath | ||
CMD ["lein", "repl", ":headless", ":host", "0.0.0.0", ":port", "7888"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build: | ||
DOCKER_BUILDKIT=0 docker build --no-cache -t cider-docker-dev . | ||
|
||
run: build | ||
docker run -v $$PWD/src:/app/src -p 7888:7888 cider-docker-dev |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This project spins up a Clojure project within a Docker image. | ||
|
||
The Docker image exposes an nREPL server. | ||
|
||
This way, for development purposes, we can exercise CIDER's Docker-related capabilities. | ||
|
||
To get started: | ||
|
||
* From a terminal tab, run `make run` to run the Docker image | ||
* Note that it has a volume mapping for `src`, so any local changes will be visible in the Docker image. | ||
* Also note that the root of this subproject has a .dir-locals.el setting up `cider-path-translations`. | ||
* `M-x cider-connect-clj`, choose localhost, 7888 | ||
* `M-x cider-load-buffer` the foo.clj namespace. | ||
* From now on, you can `M-.` (jump to definition) recursively, starting from `clj-http.client`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(defproject cider-docker-dev "0" | ||
:dependencies [[org.clojure/clojure "1.11.1"] | ||
[clj-http "3.12.3"]] | ||
:source-paths ["src"] | ||
:plugins [[cider/cider-nrepl "0.35.1"]]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(ns bar | ||
(:require [foo])) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(ns foo | ||
(:require | ||
[clj-http.client :as client])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remind me why we can have multiple mappings for the same path? I never used TRAMP, so I don't remember very well how this was supposed to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally we don't expect that to be the case, however I'm using the new
cider--all-path-translations
function (it has a comment justifying its existence) which gets the buffer-localcider-path-translations
value from all buffers.I imagine it's possible that some unrelated buffer's cider-path-translations can unexpectedly work for a given path.
So by specifying
return-all
, we get all possible matches - good and bad ones. Later, in the 'friendly session' computation, we compare them against the classpath. The bad ones won't matter - they won't be found in the classpath, so nothing is changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems overly complicated to me, but given that I don't use or care about this functionality I'll assume you know what you're doing. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish it could be less complicated. 😄