Fork me on GitHub
#lsp
<
2023-02-24
>
timo10:02:27

Hi, I am trying to rename all the namespaces in a project and I find that it does break a lot of requires and references. I am using this piece of code:

(->> (all-ns)
     (map ns-name)
     (map name)
     (filter #(s/starts-with? % "datahike."))
     #_(mapv #(symbol (s/replace-first (str %) #"datahike." "io.replikativ.datahike.")))
     (mapv (fn [ns-str]
            (lsp/rename! {:from (symbol ns-str)
                          :to (symbol (s/replace-first (str ns-str) #"datahike." "io.replikativ.datahike."))})))))
and pieces of code show up like this:
-(s/def ::index #{:datahike.index/hitchhiker-tree :datahike.index/persistent-set})
+(s/def ::index #{:io.replikativ.datahike.index/hi:io.replikativ.datahike.index/persistent-setatahike.index/persistent-setpersistent-set})
or this:
(:require
    [clojure.data]
    [clojure.walk]
-   [datahike.constants :refer [e0 tx0 emax txmax]]
+   [io.replikativ.datahike.constantshike.constants :refer [e0 tx0 emax txmax]]
    [datahike.datom :refer [datom datom-tx]]
    [datahike.db.interface :as dbi]
-   [datahike.index :as di]
+   [io.replikativ.datahike.indexdatahike.index :as di]

timo10:02:06

I am running it on main branch of https://github.com/replikativ/datahike

ericdallo14:02:44

sorry, it's not clear to me, where you are using clojure-lsp there?

timo14:02:05

lsp/rename!

timo14:02:15

in the snippet on top

ericdallo14:02:21

oh, sorry, I didn't find that call, got it

ericdallo14:02:32

right, let me test

ericdallo14:02:19

that's actually the first time I see someone heavily using lsp/rename! so curious if works that well :)

ericdallo14:02:00

I can repro with a simple

(clojure-lsp.api/rename!
    {:from (symbol "datahike.constants")
     :to (symbol "io.replikativ.datahike.constants")})

ericdallo14:02:12

so seems to be a bug, taking a closer look

👍 2
ericdallo15:02:59

Found the bug, kinda hard to find, it actually happens for editor as well and only for cljc files, will create a issue and work on that

ericdallo17:02:21

Fixed on master @U4GEXTNGZ, should be available on monday's release

❤️ 6
Carl12:02:58

Is there a way to configure clojure-lsp to work with an nbb project?

borkdude12:02:15

It depends, what do you need?

borkdude12:02:18

Usually it helps to create a deps.edn with the dependencies from nbb.edn. Perhaps clojure-lsp can detect nbb.edn and use bb --config nbb.edn print-deps to support nbb - cc @UKFSJSM38

Carl12:02:51

I made a nbb project with an nbb.edn file containing :

{:deps {com.rpl/specter {:mvn/version "1.1.4"}
        cider/cider-nrepl {:mvn/version "0.30.0"}}}
and was hoping to get completion suggestions via clojure-lsp in neovim

Carl12:02:31

oh ok, I'll try make a deps.edn with the same dependencies

borkdude12:02:21

I doubt that specter works with nbb currently, but perhaps we can look into making that work

Carl12:02:19

oh that probably explains by current problem then. I tried in include specter but it didn't work. However I do seem to have LSP diagnostics appearing in neovim now 🙂

borkdude12:02:37

specter does work with #CLX41ASCS

borkdude12:02:46

I'll take a look right now since I was working on nbb anyway

Carl12:02:02

Thanks @U04V15CAJ! No rush though, I’ll have to head off soon 💤

ericdallo13:02:11

There is this https://github.com/clojure-lsp/clojure-lsp/issues/1418 regarding that support, one of the ideas was to have a nbb.edn and a nbb --print-classpath , I didn't think about bb --config nbb.edn print-deps but I suppose that would require bb installed besides nbb

borkdude13:02:43

bb is required anyway for nbb.edn

ericdallo13:02:11

I see, so clojure-lsp could detect a nbb.edn and just run that command, right?

ericdallo13:02:15

I'll add that to the issue

borkdude13:02:32

(that just occurred to me this morning)

👍 2
borkdude13:02:43

hmm one thing that won't work is built-in libraries like promesa... but at least it will work for the deps declared in nbb.edn

ericdallo13:02:32

yeah, is it hard to support --print-classpath in nbb? maybe would be a good idea?

borkdude13:02:03

I think what nbb could do is call bb but with -Sdeps with the added dependencies

ericdallo13:02:10

sounds good as well

borkdude14:02:49

@U01TU6MLA69 I looked into specter support and pushed a couple of improvements but didn't get it completely working, maybe some other time

geraldodev11:06:22

Is the answer to the question: Not at the moment ?

geraldodev12:06:18

Using nvim-lint to trigger clj-kondo to trigger at least clj-kondo while lsp does not recognize nbb project.

use({
		"mfussenegger/nvim-lint",
		config = function()
			require("lint").linters_by_ft = {
				clojure = { "clj-kondo" },
				-- ... other linters
			}
		end,
	})
	vim.api.nvim_create_autocmd({ "BufWritePost" }, {
		callback = function()
			require("lint").try_lint()
		end,
	})

borkdude12:06:06

There’s still an open but unfinished PR for this