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

Core functions are not highlighted for ClojureScript #3385

Closed
nikolavojicic opened this issue Jul 29, 2023 · 15 comments
Closed

Core functions are not highlighted for ClojureScript #3385

nikolavojicic opened this issue Jul 29, 2023 · 15 comments

Comments

@nikolavojicic
Copy link

Expected behavior

Core functions should be highlighted like map and range here. This is how it is for Clojure.

Screenshot 2023-07-29 121408

Actual behavior

Core functions ( map and range) are not highlighted. This is how it is for ClojureScript.

Screenshot 2023-07-29 121224

Steps to reproduce the problem

Content of shadow-cljs.edn:

{:source-paths ["src"]
 :dependencies [[binaryage/devtools "1.0.6"]
                [cider/cider-nrepl "0.32.0"]
                [net.cgrand/xforms "0.19.2"]
                [reagent "1.1.1"]
                [re-frame "1.2.0"]
                [cljs-http "0.1.46"]
                [day8.re-frame/http-fx "0.2.4"]
                [org.clojure/core.async "1.5.648"]]
 :builds       {:app {:target     :browser
                      :output-dir "public/js"
                      :asset-path "/js"
                      :modules    {:app {:entries [fisherman-fe.core]}}
                      :devtools   {:after-load fisherman-fe.core/init!}}}
 :dev-http     {3001 {:root    "public"
                      :handler user/app}}}
  1. Run cider-jack-in-cljs
  2. Choose shadow
  3. Choose :app
  4. Visit application in browser
  5. Write the code above
  6. Evaluate that code

Environment & Version information

  • shadow-cljs 2.20.13
  • For CIDER and NREPL see screenshots above
  • GNU Emacs 28.2 (build 2, x86_64-w64-mingw32) of 2022-09-13
  • OpenJDK Runtime Environment Corretto-17.0.2.8.1 (build 17.0.2+8-LTS)
  • Windows 10 (also in 11)
@bbatsov
Copy link
Member

bbatsov commented Jul 29, 2023

Why are you using cider-nrepl 0.32? I'm guessing that's some regression from the recent changes that @vemv has been doing. I guess he'll address this quickly once he sees the ticket.

@nikolavojicic
Copy link
Author

nikolavojicic commented Jul 29, 2023

@vemv has advised me to try 0.32... Same behavior is with 0.30.

image

@bbatsov
Copy link
Member

bbatsov commented Jul 29, 2023

Ah, okay. Well, I'll leave it to him to look into this. You might want to share here the part of your nREPL log related to track-state, as he'll likely need this to debug the problem.

@nikolavojicic
Copy link
Author

Where can I find that log? I enabled nrepl message logging and this was printed: https://gist.github.com/nikolavojicic/fbd8eb603ca42ecc2d2acfce393d43cd

@vemv
Copy link
Member

vemv commented Jul 30, 2023

From my side, I have never gotten special syntax coloring for clojure.core defns, but that might be some oddity related to my setup.

Anyway, @bbatsov , do you recall what is supposed to be happening, technically? Who flags clojure.core fns as such (cider-nrepl or cider), how? What font-lock face is applied to them?

@nikolavojicic
Copy link
Author

nikolavojicic commented Jul 30, 2023

Probably this setting does dynamic syntax coloring:
image
Advanced syntax coloring occurs only after I run CIDER.

@nikolavojicic
Copy link
Author

I've found this similar issue: #1889 (comment)

@vemv
Copy link
Member

vemv commented Jul 30, 2023

Probably this setting does dynamic syntax coloring:

That's right! I had it set to (cider-font-lock-dynamically '(macro deprecated)) long ago enough to completely forget about it :)

It's an accurate pointer, thanks. I'll begin investigating.

@vemv
Copy link
Member

vemv commented Jul 30, 2023

Alright, I had it easy to repro:

  • (cider-resolve-ns-symbols (cider-resolve-core-ns)) returns plenty of info when called from a jvm clj buffer
  • (cider-resolve-ns-symbols (cider-resolve-core-ns)) returns nil on cljs

This defun is buggy:

(defun cider-resolve-core-ns ()
  "Return a dict of the core namespace for current connection.
This will be clojure.core or cljs.core depending on the return value of the
function `cider-repl-type'."
  (when-let* ((repl (cider-current-repl)))
    (with-current-buffer repl
      (cider-resolve--get-in (if (eq cider-repl-type 'cljs)
                                 "cljs.core"
                               "clojure.core")))))

...because (eq cider-repl-type 'cljs) is nil even on a .cljs buffer. A possible fix is (or (eq cider-repl-type 'cljs) (eq major-mode 'clojurescript-mode)).

Even after fixing that, (cider-resolve-ns-symbols (cider-resolve-core-ns)) will be nil. That seems to be a deeper issue in the cider-nrepl middleware.

@vemv
Copy link
Member

vemv commented Jul 30, 2023

The second bug is this access https://github.com/clojure-emacs/cider-nrepl/blob/4b55dedf4cee10bda75ab2165580da72a617b721/src/cider/nrepl/middleware/track_state.clj#L222, that string should be a symbol.

With those two trivial bugs fixed, it should all work again 🍻

@vemv
Copy link
Member

vemv commented Aug 3, 2023

Please try again with cider-nrepl 0.34.0. Nothing else is needed

I believe this issue is solved by now, otherwise let me know!

@vemv vemv closed this as completed Aug 3, 2023
@nikolavojicic
Copy link
Author

Core functions are now highlighted but user-defined not.

image

@nikolavojicic
Copy link
Author

I restarted cider, loaded that buffer and increment was highlighted. But new functions are not, until restarted.

image

@vemv
Copy link
Member

vemv commented Aug 4, 2023

I cannot repro!

First I (setq cider-font-lock-dynamically '(macro core function deprecated))

Then I define a function foo, save the file, make sure that compilation succeeded.

Then, function highlighting will work immediately for all occurrences of foo.

The precise style that should be applied (per M-x describe-char) is font-lock-function-name-face. Does your theme customize it to a color of your liking?

If it persists, please create a new issue.

Cheers - V

@nikolavojicic
Copy link
Author

The problem is that you font lock dynamically '(macro core function deprecated) while I do '(macro core function var). With your setup I cannot repro either. So it seems that var makes the problem here.

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

3 participants