Fork me on GitHub
#lsp
<
2023-05-06
>
Martynas Maciulevičius07:05:01

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?

ericdallo14:05:16

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.

ericdallo14:05:32

also you can call rename in a alias to easily rename it

Martynas Maciulevičius17:05:17

> 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.

ericdallo17:05:17

could you elaborate what you are typing or record a gif showing what clojure-lsp is doing that you don't like it?

Martynas Maciulevičius18:05:07

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.

Martynas Maciulevičius18:05:45

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

Martynas Maciulevičius18:05:37

In the second flow I already typed my-ns but I ended up with sut:

Martynas Maciulevičius18:05:36

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)

escherize21:05:59

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!

Martynas Maciulevičius06:05:29

> 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.

Ellis19:05:00

Looks like the settings.md file is relative when it should be absolute

ericdallo14:05:17

Yes, where did you find that link?

Ellis14:05:12

I raised a PR that should fix it

ericdallo15:05:45

Merged, thanks both

ericdallo16:05:16

That's working right?

Caio Cascaes16:05:11

It was the last link "settings documentation". I double checked now, it's working 🙂 👍 clojure-lsp

Ellis17:05:40

I saw your 1st reply before your 2nd so I assumed you missed the PR 🙂

🙌 2