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

Cider cannot open Jar files by SSHx/Tramp #3409

Closed
igrishaev opened this issue Aug 14, 2023 · 18 comments
Closed

Cider cannot open Jar files by SSHx/Tramp #3409

igrishaev opened this issue Aug 14, 2023 · 18 comments
Assignees

Comments

@igrishaev
Copy link

igrishaev commented Aug 14, 2023

Expected behavior

I have a machine that runs an nREPL server. I can reach the files in Emacs by running this:

(dired "/sshx:[email protected]:~/work/XXX")

I open deps.edn file and perform cider-connet to the remote port and then cider-ns-refresh. Navigation by the files located in src works great: I can jump to definitions with M-. with ease. But when I try to open a namespace that comes from ~/.m2, say clojure.core, the following happens.

  • Emacs hangs for a while transferring the file; I can see a message like:
Tramp: Checking ‘vc-registered’ for /sshx:[email protected]:/Users/foo/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar...done
  • Then it shows a buffer titled clojure-1.10.3.jar with the following content:
M  ...   Filename
- ----- ---------------
- ----- ---------------
  • Then it reports that the search has failed:
cond: Search failed: "clojure/core.clj$"

Actual behavior

I expected to see the actual clojure/core.clj file opened at the proper line. What's interesting here, I worked before I restarted Emacs (I've have had it running for a long time).

Steps to reproduce the problem

The second way to reproduce this is to run M-x cider-find-ns RET clojure.core RET and get the same buffer and a message saying the search has failed.

Environment & Version information

CIDER version information

;; CIDER 1.7.0 (Côte d'Azur), nREPL 1.0.0
;; Clojure 1.10.3, Java 20.0.1

Lein / Clojure CLI version

Clojure 1.10.3
Clojure CLI version 1.11.1.1347

Emacs version

GNU Emacs 28.1 (build 1, aarch64-apple-darwin21.1.0, NS appkit-2113.00 Version 12.0.1 (Build 21A559)) of 2022-05-11

Operating system

MacOS 12.3.1

JDK distribution

OpenJDK 20.0.1, no docker

@vemv
Copy link
Member

vemv commented Aug 14, 2023

Hi!

Thanks for the report.

What's your defcustom cider-use-xref value? IOW, is M-. using xref for you?

@igrishaev
Copy link
Author

Yes I have cider-use-xref set to true. I've tried to jump into a jar file in several ways:

  • M-x cider-find-var
  • M-x xref-find-apropos
  • M-x cider-find-ns RET foo.bar RET

But all these three show a buffer

M  ...   Filename
- ----- ---------------
- ----- ---------------

and a message saying the search failed.

@vemv
Copy link
Member

vemv commented Aug 14, 2023

Thanks!

cider (master, must be greater than 1.7.0) and cider-nrepl 0.35.0 improve a number of things in the xref front.

Although I don't use tramp, I wouldn't be surprised if this started working, please give it a try.

@igrishaev
Copy link
Author

Sure, let me try...

@igrishaev
Copy link
Author

@vemv no it didn't help: I've installed the latest master (Cider 1.8.0-snapshot) and cider-nrepl 0.35.0 but the jar behaviour is still the same.

@igrishaev
Copy link
Author

One more interesting thing: if I step into the buffer and press g, for a moment it's get filled with machinery symbolds, and then it becomes this:

M    Mode     Size        Date&time         Filename
- ----------  -----  --------------------  ----------------
  -rw-rw-rw-    244  18-Jul-2023 12:23:36  META-INF/MANIFEST.MF
  drwxrwxrwx      0  18-Jul-2023 12:20:26  lambda/
  -rw-rw-rw-   1306  18-Jul-2023 12:19:06  lambda/aes.clj
  -rw-rw-rw-    901  18-Jul-2023 12:19:06  lambda/core.clj
  drwxrwxrwx      0  18-Jul-2023 12:20:26  lambda/test/
  drwxrwxrwx      0  18-Jul-2023 12:20:26  lambda/test/fixture/
  -rw-rw-rw-   1542  18-Jul-2023 12:19:06  lambda/test/fixture/core.clj
  -rw-rw-rw-    913  18-Jul-2023 12:19:06  
...

@igrishaev
Copy link
Author

If I open the lambda/core.clj entry and try to M-x to lambda.core, it works great: Emacs navigates to the proper file.

@vemv
Copy link
Member

vemv commented Aug 14, 2023

cond: Search failed: "clojure/core.clj$"

I wonder if that $ is a badly formed regex?

@igrishaev
Copy link
Author

igrishaev commented Aug 14, 2023

Another update:

  • when I M-. to a jar namespace the first time, it doesn't work: it shows the following buffer:
M  ...   Filename
- ----- ---------------
- ----- ---------------
  • then I press g and it becomes a table of Jar entities
  • if I switch back to code and navigate to any namespace from this Jar, it works but...
  • ...if I try to navigate to some other namespace from this namespace (e.g. jdbc.next or somethis), it doesn't work: it asks for a path to Jar file.

@vemv
Copy link
Member

vemv commented Aug 14, 2023

I wonder if that $ is a badly formed regex?

...probably not, it appears to work fine for a simple experiment.

@igrishaev, the main logic resides in cider-find-file, and specifically:

cider/cider-common.el

Lines 372 to 380 in 4a35e24

((tramp-tramp-file-p path)
(find-file path)
(goto-char (point-min))
;; anchor to eol to prevent eg. clj matching cljs.
(re-search-forward (concat entry "$"))
(let ((archive-buffer (current-buffer)))
(archive-extract)
(kill-buffer archive-buffer))
(current-buffer))

One more interesting thing: if I step into the buffer and press g, for a moment it's get filled with machinery symbolds, and then it becomes this ...

Surely the re-search-forward fails because nothing is displayed until the effect of pressing g is applied?

IDK how to automate that (IDK much about tramp in general). It would be tremendous help if you could try improving the mentioned lines (L372-L380)

@vemv
Copy link
Member

vemv commented Aug 14, 2023

..if I try to navigate to some other namespace from this namespace (e.g. jdbc.next or somethis), it doesn't work: it asks for a path to Jar file.

Could you be more specific?

@igrishaev
Copy link
Author

@vemv sure, sorry for confusion. I mean, I can navigate to the lambda.core namespace (by pressing g in a broken buffer). I can see the ns header:

(ns lambda.core
  (:gen-class)
  (:require [lambda.util :as util]
            [clojure.tools.logging :as log]
            [aws.lambda :as lambda]
            [clojure.string :as str]))

Now I want to proceed to the aws.lambda namespace. I move the point to the aws.lambda word, press M-. but it either says "No linked Cider sessions" or opens a minubufer with jar files.

@vemv
Copy link
Member

vemv commented Aug 14, 2023

Thanks!

Could you paste/screenshot that minibuffer?

@igrishaev
Copy link
Author

@vemv sure I've sent it to you in Slack (this is a private project).

@igrishaev
Copy link
Author

igrishaev commented Aug 15, 2023

UPD: the problem with Jar buffers had nothing in common with Cider. Turned out, I had it on all my computers. The culprit was the following line:

(setq-default coding-system-for-read 'utf-8)

Once I removed it, jumping into the Jar files (even via Tramp) works fine.

@igrishaev
Copy link
Author

igrishaev commented Aug 15, 2023

The only problem I have now is, sometimes, stepping into a Jar file leads to loosing the current Cider session. But it looks like there is already an existing topic for that. We can close this one, I believe, if nobody minds.

@vemv
Copy link
Member

vemv commented Aug 15, 2023

I'll try to ensure coding-system-for-read is temporarily bound for us

Thanks!

@vemv vemv reopened this Aug 15, 2023
@vemv vemv self-assigned this Aug 19, 2023
@vemv
Copy link
Member

vemv commented Aug 22, 2023

I tried to reproduce the coding-system-for-read issue, but couldn't.

e.g. I set it to 'binary or 'iso-safe to see if anything would break, but it wasn't the case.

Probably this was enough of an edge case (as most users wouldn't set this variable) to defer any fix for the time being.

btw, would love a confirmation that a workaround for session linking is no longer needed.

Cheers - V

@vemv vemv closed this as completed Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants