This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-06
Channels
- # babashka (130)
- # beginners (97)
- # biff (36)
- # calva (6)
- # cherry (23)
- # clojure (29)
- # clojure-dev (1)
- # clojure-europe (9)
- # clojurescript (5)
- # datomic (24)
- # emacs (13)
- # fulcro (5)
- # hyperfiddle (33)
- # interop (2)
- # jobs (18)
- # kaocha (1)
- # london-clojurians (1)
- # lsp (20)
- # nrepl (1)
- # off-topic (60)
- # pathom (4)
- # reitit (7)
- # releases (1)
- # remote-jobs (4)
- # scittle (3)
- # specter (1)
- # tools-deps (7)
- # xtdb (16)
I'd like to know whether it's possible to prompt my editor to enter an alias to a namespace that I import using the refactoring command.
Example:
I create a namespace my.namespace
and then create test my.namespace-test
.
Then I import [my.namespace :as sut]
in the test and everything is fine.
But when I want to use this namespace in a different setting then it suggests that I import it under sut
name which I don't want to do.
What would be a good way to resolve this kind of QoL issue?
But sut is the alias right? it's suggesting what you typed. There is the consistent-alias linter from clj-kondo which you can opt-in and it will warm if you use a different alias.
> But sut is the alias right? Yes. But I simply didn't want to use that alias in my import even if I typed it previously.
could you elaborate what you are typing or record a gif showing what clojure-lsp is doing that you don't like it?
The first flow (on the left) doesn't have a test and it tries to figure out the alias for the namespace in some way.
This works because I already typed what I want and if I'd import it now I actually would want to have it.
In the second flow I already typed my-ns
and I want to keep it as my-ns
. But when I apply the refactoring then I get sut/my-fn
even though I already typed what I wanted.
I think this could be fixed in two ways (probably both of them could be applied too): 1. List the names from the first mode of operation every time 2. Respect what user has typed when he is applying the code action
In the second flow I already typed my-ns
but I ended up with sut
:
So this means that if I want to rename it back to my-ns
from sut
I have to type my-ns
twice:
1. importing itself (type my-ns/my-fn
2. refactor to rename alias (type my-ns
)
Not really an answer, but I prefer using the same namespace alias in both, so it looks the same when you are calling it, and you can more easily avoid something like file-system/delete-file!
<-> sut/delete-file!
> using the same namespace alias
Yeah. I was thinking about doing both too :thinking_face: it would avoid these kinds of issues.
But as I came from CIDER and they include the ns
by default (if I remember correctly they simply include at the top of the file when I create a test file) I started doing it too as it's a short name.
This page seems broken: https://clojure-lsp.io/api/what-is-it/settings.md or it's just me?
It was the last link "settings documentation". I double checked now, it's working 🙂 👍