This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-07
Channels
- # announcements (2)
- # babashka (34)
- # beginners (114)
- # biff (7)
- # calva (16)
- # cider (2)
- # clj-kondo (46)
- # clj-on-windows (14)
- # clojars (13)
- # clojure (33)
- # clojure-europe (17)
- # clojure-nl (2)
- # clojure-norway (8)
- # clojure-spec (3)
- # clojure-uk (3)
- # clojurescript (25)
- # community-development (1)
- # datalevin (1)
- # emacs (53)
- # fulcro (31)
- # gratitude (2)
- # jobs (1)
- # lambdaisland (12)
- # lsp (57)
- # malli (3)
- # nbb (1)
- # off-topic (92)
- # pathom (2)
- # pedestal (2)
- # releases (5)
- # shadow-cljs (25)
- # sql (3)
- # squint (1)
- # testing (6)
- # vim (11)
Do i need to tell lsp about extra-deps defined in my global deps file .clojure/deps.edn
?
the answer seems to be yes given i get the lsp auto complete when i include the deps directly.
i can figure this out, i feel like i ask this same question in a different way ever 3 months...
i need to set the source path
I use :source-aliases
to tell Clojure LSP to include specific project and user level aliases. Aliases I use for every Clojure project go in my user level configuration for Clojure LSP, e.g :env/dev
and :env/test
https://github.com/practicalli/clojure-lsp-config#clojure-lsp-configuration
clojure-lsp will just delegate the classpath finding to lein
or clj
, and derive the source-paths from that, if you want more source-aliases to be included on lein's with-profiles
or deps -A:
you should add to source-aliases โ๏ธ
On my wishlist: Regex comments recognized as comments by lsp.
(let [pattern #"(?x) # comment flag:
# enables free whitespace
# and # delineated comments
foo # literal foo
\ # literal space
\w+ # 1+ word chars"]
(re-find pattern "tofoo bar"))
;; => "foo bar"
CLJ. I would expect it to be marked as a comment, so editor can apply comment syntax highlighting like any other comment.
I imagine it's not at the top of anybody's priorities, though. I'm probably just dreaming.
We would need clj-kondo work, also, not sure editors already know that like clojure-mode for emacs and vscode internals
Oh,, nevermind. That's just highlighting escapes. So I guess interpreted as a string like you say.
I'm looking at clojure-lsp.api since @ericdallo suggested I use it instead of our custom ns sort script. I'm a bit puzzled as to how to use it and the docs aren't helping. Our project structure might be the issue here:
wsmain -- the repo
+-- .clj-kondo
+-- .lsp
+-- clojure -- where our Clojure source code is
+-- deps.edn
In order to use clojure-lsp.api
via an alias, I need to be in wsmain/clojure
to run... well, the docs don't quite say... but it looks like it should be clojure -T:lint-ns
(since there's :replace-deps
). However, that definitely won't work since it won't know it needs to use :dev
and :everything
aliases to pick up deps and paths to find the source code (almost everything is :extra-deps
with :local/root
since this is a Polylith monorepo).
I tried changing that to :extra-deps
and running clojure -X:dev:everything:lint-ns
but that still doesn't find any code to analyze/fix.
Also, when I run it, it creates .clj-kondo
and .lsp
in the clojure
folder which is probably not what I want -- so I figure I need :project-root
but I can't supply that from the command-line because the API code requires that be a java.io.File
rather than a string.
Halp?!?!I added a shim in our development
folder so ws.lsp/clean-ns!
becomes the -T
function and it in turn calls clojure-lsp.api/clean-ns!
and passes :project-root (io/file "..")
and that seems to have resolved the problem. If :project-root
could be a string, I wouldn't need to do this.
I'm a bit surprised it seems to recompute the classpath and re-analyze the project each time -- I would have expected that to be cached?
Yes but that won't work since your deps.edn is in another folder different than your .LSP folder you mentioned which is odd
Why you would like to have clojure tools configs like clj-kondo and lsp not in the same folder of your clojure folder like deps.edn
The API works similar to the editor, if you open your project in your editor in the clojure folder, that's the project root you should pass for example
wsmain
is where the editor opens. That's the project root.
(I've already had to go through this dance with VS Code/Calva and the way it invokes LSP etc)
And how clojure-lsp knows that the deps.edn is the clojure folder? Do you customize the classpath somehow?
Yes. Like I say, I already spent a lot of time configuring this for Calva ๐
if works for calva it should work the same, clojure-lsp.api just calls what the editor code calls
wsmain/.lsp/config.edn
:
{:project-specs [{:project-path "clojure/deps.edn"
:classpath-cmd ["build/bin/classpath.sh"]}]
:source-aliases #{:build :dev :everything :runner :test}}
and classpath.sh
:
#!/bin/sh
cd /Developer/workspace/wsmain/clojure
../build/clojure/bin/clojure -A:build:dev:everything:runner:test -Spath
But we run all the build/dev/test tooling in wsmain/clojure
because that's where the main deps.edn
file is. Hence needing to specify :project-root
which, annoyingly, does not accept a string.Without :project-root
, it does not seem to look up the directory tree to find wsmain/.lsp/config.edn
and then work with the .lsp
and .clj-kondo
folders at that level.
So:
;; copyright (c) 2022 world singles networks llc
(ns ws.lsp
(:require [ :as io]))
(defn clean-ns! [opts]
((requiring-resolve 'clojure-lsp.api/clean-ns!)
(assoc opts :project-root (io/file ".."))))
And in wsmain/clojure/deps.edn
:
:sort-ns
{:replace-paths ["development/src"]
:replace-deps {com.github.clojure-lsp/clojure-lsp {:mvn/version "RELEASE"}}
:exec-fn ws.lsp/clean-ns!
:exec-args {:dry? true
:settings
{:clean
{:ns-inner-blocks-indentation :same-line
:ns-import-classes-indentation :same-line
:sort {:refer {:max-line-length 1}}}}}}
which gets us close to the behavior we want.What I've learned from this exercise is that we are not very consistent with our :import
clauses! ๐
yeah receive as a file https://github.com/clojure-lsp/clojure-lsp/pull/455#discussion_r659250513.
> Without :project-root
, it does not seem to look up the directory tree to find wsmain/.lsp/config.edn
and then work with the .lsp
and .clj-kondo
folders at that level.
without project-root will use the root as where the command was run, so we need to checks from where you are running that.
> What I've learned from this exercise is that we are not very consistent with our :import
clauses! ๐
Yeah, that's one good thing about not having custom scripts, you never know if your script is really doing that other tools do
all of that headache is probably because your deps.edn is in a place different than the project root (where you have your lsp configs), I suggest in the future you move everything related to clojure to the clojure folder indeed
The diff output from the above is about 1,600 lines... so this is going to be a big, one-off PR to reformat our code and then keep it this way. Which is fine. Now I just need to integrate this into our build.clj
file (and then I can remove the ws.lsp
shim now I have it working.
No, the deps.edn
must be in the Polylith workspace -- which is wsmain/clojure
Because Calva runs LSP in the project root -- where the editor opens -- as I said above.
so, sounds like a Calva issue, you can open a project in /foo/bar in emacs for example and have lsp start in /foo/bar/baz
You can search back in the discussions here but I went round and round with this when I switched to Calva -- and you and @U0ETXRFEW were in that discussion ๐
I tried a lot of combinations of file placements and configuration and what I've shown in this thread was pretty much the only configuration that actually works properly.
I don't care, to be honest, now that I have it working. And I really don't want to move stuff around in the repo again at this point (otherwise I'd have moved everything in clojure
up to the top-level ages ago -- even tho' that means having a build
tree full of scripts and config files and a documentation
tree full of markdown files mixed in with our Clojure code which... ugh!).
Re: issue 455 -- I should have known that it would be vemv who suggested not accepting a string :rolling_on_the_floor_laughing:
Thank you for your help/input! I have the PR in at work to switch the tooling from our custom sort script to LSP's clean-ns! and I'm now working on the actual PR for all of the reformatting changes ๐