This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-15
Channels
- # announcements (2)
- # babashka (27)
- # beginners (53)
- # boot (3)
- # calva (5)
- # cider (1)
- # clj-kondo (46)
- # cljdoc (38)
- # cljs-dev (40)
- # cljsrn (1)
- # clojars (5)
- # clojure (61)
- # clojure-europe (124)
- # clojure-germany (3)
- # clojure-losangeles (6)
- # clojure-nl (12)
- # clojure-uk (11)
- # clojurescript (44)
- # clojureverse-ops (7)
- # datomic (13)
- # events (3)
- # introduce-yourself (1)
- # jackdaw (5)
- # lsp (115)
- # malli (1)
- # off-topic (16)
- # polylith (2)
- # releases (1)
- # remote-jobs (6)
- # shadow-cljs (10)
- # sql (2)
- # timbre (1)
- # tools-deps (30)
- # vim (34)
- # xtdb (20)
(context: I'm taking my first steps in learning emacs & clojure-lsp) I noticed that although navigating between definitions and references (e.g. function definitions and call sites) works quite nicely, I seem to be unable to navigate from the concrete Java type of a record to the record definition. For example, if I define a record in one namespace and import
it (or rather the generated Java class to be precise) in another namespace (e.g. for using it in a extend-type
) -> should I be able to somehow navigate back to the defrecord
form from the corresponding java class or is this something that clojure-lsp doesn't support?
clojure-lsp is quite limited related to java classes manipulation, as clj-kondo doesn't have a deep java/classes analysis
> concrete Java type of a record to the record definition. I think clj-kondo should be able to support this
@U0178V2SLAY could you help with the minimal repro please?
the above may or may not be valid clojure, as I don't have a repl at hand 🙂
why don't you write the record as:
(defrecord SomeRecord [foo bar] SomeProtocol (do-stuff [this] 42))
That is probably the more idiomatic way@U0178V2SLAY your code actually works to me, I can navigate to definition and references of both record, protocol and the extend-type
Ah, most likely a case of pebkac then. And yes, I could most likely solve this by merging the namespaces.
@UKFSJSM38 from where to where are you navigation to the record definition?
I tried with different namespaces and it worked as well.
if on namespace my.other-namespace
I navigate from the SomeRecord
symbol, I go to my.fabulous-namespace/SomeRecord
(why am I using extend-type
instead of implementing the protocol inline? good question. I'm playing around with the hexagonal architecture and trying to learn it. I thought of implementing the ports as protocols and actual adapters as records. At the moment I'm thinking it might be cleaner to avoid complecting the different protocols and records directly and instead use separate namespaces to enhance the different records with appropriate protocols. This may turn out to be a bad idea and thus I may merge the protocol implementations inline with the records.)
find definition works the references doesn't work though, I managed to make it work somehow before, but now it doesn't. (I renamed the ns to match my current proejct, not sure this related to issue)
it's weird the definition find the defrecord, but there is no references to it, looks a corner case bug
This hexagonal architecture looks like a cousin to polylith, but with less of an eye for deployment.
@U04V15CAJ did you find the bug already? I'm not sure what is the issue yet
oh with the underline my navigation to the record from the imported class didn't work. are you sure you're not connected to CIDER or something?
can you try this code, literally?
(ns my.fabulous-namespace)
(defrecord SomeRecord [foo bar])
(defprotocol SomeProtocol
(do-stuff [this]))
(ns my.other-namespace
(:require [my.fabulous-namespace :as foobar])
(:import [my.fabulous_namespace SomeRecord])) ;; same
(extend-type SomeRecord ;; no navigation to record
foobar/SomeProtocol ;; this worked
(do-stuff [this]
42))
still I think this could be improved, there is no hover information on the SomeRecord
inside the import form, but definition works
hahah, I'm using clojure-lsp from master, which didn't bump clj-kondo, it's the same from latest release
are you absolutely sure you have no other tools which just make a guess to jump to an earlier symbol in the file or so?
yeah, it was doom using ripgrep
fallback because lsp-find-definition was not working
and I think it's related with the _
indeed, we can confirm that checking the analysis filename
acutally, not related with filename, I meant, if we change the _
to -
which is not a valid clojure code, it works though
yes, it's a subtle bug. clj-kondo just has to "try" if this might be a record or deftype
{:name-end-col 24,
:name-end-row 12,
:name-row 12,
:name SomeRecord,
:filename "/home/greg/dev/clojure-lsp/src/clojure_lsp/foo.clj",
:from my.other-namespace,
:col 14,
:name-col 14,
:bucket :var-usages,
:row 12,
:to my.fabulous_namespace}
Thanks to both of you for investigating this 👍
cycle-coll
doesn’t work if my collection has one element and I have cycled it into a map
probably, yeah
if I add an extra element to make it a valid map, it works again
ah bummer
Not sure the best approach here, probably make rewrite-clj understand that code somehow
would the best current solution be to remove cycling into maps? to me, it makes sense to cycle between the others (none have special restrictions about their creation) whereas maps are special because of their requirement for even entries
Hum, I think this is still useful for when user wants to cycle to map and fix the key val pairs later
Also @UEENNMX0T, you probably is calling this refactoring manually right?
as clojure-lsp already return 3 code actions when iniside a coll: • cycle to map • cycle to vec • cycle to set for example
yeah, i normally do that, right now i’ve exposed the refactoring commands like lsp-mode (`lsp-clojure-cycle-coll`, for example) and am making sure they all work
I don't see vim users use code actions normally, most of the time because they don't know it exists
> yeah, i normally do that, right now i’ve exposed the refactoring commands like lsp-mode (`lsp-clojure-cycle-coll`, for example) and am making sure they all work Looks a good approach
> I don’t see vim users use code actions normally, most of the time because they don’t know it exists I just stumbled across some refactoring with the code actions in (Neo)Vim, where I went to using “execute command” Is there a way to code action and give the action for it to use if it makes sense?
was trying to hotkey things like inline-symbol
or extract function or the let bindings, where I prompt for the name….
yeah, ATM the code action doesn't support ask to user some input, that's why it uses mocked function names
just making sure I wasn’t missing something in the way I was doing it from NeoVim and it’s LSP client
I’m writing some documentation for my forthcoming coc.nvim plugin for clojure-lsp, and I can’t quite figure out what expand-let
does
https://www.github.com/clojure-emacs/clj-refactor.el/tree/master/examples%2Fexpand-let.gif
ahhh interesting. doesn’t seem to quite do that on my machine. i’ll see if i can record to demonstrate
https://clojure-lsp.github.io/clojure-lsp/features/#refactoring doesn’t have any docs, and this one in particular doesn’t have a demonstration gif, so the one you linked probably just needs to be added to that page
here’s what i see when i use it