For the longest time I didn't have navigation in CLJS code since I'm always too lazy to setup a REPL. But now I have thanks to LSP!
One issue though: when indexing my project it (= lsp-mode?) complains about too many files and then I think it quits. As long as I visit the "other" file, the navigation to the "other" file works. But can't I just tell clojure-lsp to index my own sources without all the other shit it finds "too many to watch" ?
yes you can
this is the file watch system
I tweaked it on lsp-mode for clojure to ignore some dirs/files
but I think you may know more things to hide/ignore š
or you could customize it just for you
it may be the target folder it finds "too much", I'm not sure, it doesn't say
it's a regex variable: lsp-file-watch-ignored
you can disable the warning too with: lsp-file-watch-threshold
nil
I'd rather find out what the problem is
https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L307-L342
can I see what it is trying to watch?
There is a hack, let me find it Also, the file watch means: watch for changes on this file, doesn't mean that it'll not use LSP on that file
I don't watch these files, I just want LSP to have them analyzed once. This seems to be conflated.
https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L1718
Probably eval: (lsp--directory-files-recursively (file-truename dir) ".*" t)
change dir
with your project path
Never mind, I this is getting too complex for me
probably is the target folder
adding something like this for target show work: https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L336
but the target folder was already in that ignore list
https://github.com/emacs-lsp/lsp-mode/blob/e39c4faa9b007215db0587eec93f58a98c550846/lsp-mode.el#L327
oh, indeed
I just want to be able to say: just watch src
and src-cljs
, ignore all the rest
Hum, still shows me the target folder
somehow it's trying to watch 4000 files, while I have only 500 or so
try this and check what is the result:
M-x
eval-expression
(lsp--directory-files-recursively (file-truename "/path/to/project") ".*" t)
I tries this with eval-expression, but I get a blurp of errors, this is where I gave up
:thinking_face:
Ah now it somehow works.
Maybe your initial version wasn't working
("/Users/borkdude/dre/DocSearch/app/asco/updates/AM18-Abstracts-LBAs-Final-XML.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/AM18-Abstracts-PubOnlyAndPresented-Final-XML.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/CSS18-Abstracts-Final-XML.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/GI18-Abstracts-for-Atypon.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/GI19-Abstracts-Final-XML.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/GU18-Abstracts-Atypon.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/GU19-Abstracts-Final-XML.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/IOS18-Abstracts-for-Atypon.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates/IOS19-XML-Final.zip" "/Users/borkdude/dre/DocSearch/app/asco/updates" "/Users/borkdude/dre/DocSearch/app/asco" "/Users/borkdude/dre/DocSearch/app/clinicaltrials/clinicaltrials-sample/.gitignore" ...)
It's watching zip files... and all kinds of directories that aren't source dirs
you could add updates folder to ignored list
AFAIK there is no allow-list š
this isn't working for my use case. why aren't the watched dirs inferred from the classpath that clojure-lsp uses?
yeah, sadly those are 2 different things, the LSP client that should say to server what should be watched
Maybe the clojure-lsp server can just ignore things it can't analyze anyway?
or doesn't that help?
Hi all,
I am using lsp
layer in spacemacs and added clojure-backend ālsp to clojure variables, I get this error in *clojure-lsp::stderr*
:
Error: Invalid or corrupt jarfile /Users/erooijak/.emacs.d/.cache/lsp/clojure/clojure-lsp
thank you
okay this works, also had to remove xattr -d com.apple.quarantine ./clojure-lsp
oh, good to know, BTW latest release already makes it executable
Any idea how to fix?
Can I put a .lsp-ignore?
we already do that, we drop things we don't know
https://emacs-lsp.github.io/lsp-mode/page/performance/#ignore-watch-foldersfiles
or maybe maybe lsp-mode can look in .gitignore? I think that should work for me
lsp-file-watch-ignored <<< .gitignore
I think these are valid ideas, but lsp-mode does not support it, you should raise an issue there, or ask here: https://discord.gg/swuxy5AAgT
the gitignore idea seems valid
ok, I might do it later. Have to get on with work now
https://github.com/emacs-lsp/lsp-mode/issues/713#issuecomment-773311067
Hey @erwinrooijakkers, where did you download the clojure-lsp binary? I suggest you download it from the latest release on clojure-lsp
Not sure from where spaceemacs is downloading
or what version
I made a PR for this that was rejected. A way to specify the source paths. I also ran into this and havenāt used lsp in a while because of it
Yeah, this sucks
@dpsutton Do you still have the issue number / link? I'll make a comment that this is exactly what I want as opposed to "add everything except"
Iāll look it up. One second
@dpsutton I don't see it being rejected, it's just stalled on some discussion?
Maybe start with an issue rather than a PR, to verify what is the desired implementation?
the gitignore idea seems valid:
is just that is not that trivial to support all gitignore syntax
maybe git itself can be leveraged to list files that are not ignored?
as in "watch only what is part of my git index"
git ls-tree --full-tree -r --name-only HEAD
this seems like a no-brainer option to me
I don't see a problem, but it'd need lsp-mode depend on git installed for that feature
but I agree it makes sense
yes, it can be an option: lsp-watch-only-git-index or something
I think it's the easiest way to get done indeed
and for mono-repos: only watch the files that are actually part of the project root, not the entire index
e.g. project/.git, project/subproject
yes, would you mind bring these ideas to the discord server?
so we can discuss the possibilities
I'm not on discord a lot
which server is this
#development
@ericdallo I think my classpath isn't properly lsp-analyzed in this project. How can I fix this?
can I set the classpath manually or ..?
it's a boot project and deps.edn project at the same time (one for backend and one for front-end, so it's complicated)
Check project specs: https://clojure-lsp.github.io/clojure-lsp/settings/
but I think it should work
I don't think I see any docs of how to influence the classpath. "it works" -> how can you verify this
I can't navigate to anything I haven't visited before in my editor
e.g. navigation to libs don't work
check /tmp/clojure-lsp.out
it should tell during the initialize if something gone wrong
2021-02-04T14:57:13.936Z MBP2019.local INFO [clojure-lsp.crawler:165] - Paths analyzed, took 3.5609107 secs. Caching for next startups...
That doesn't seem like it really did anything
considering the amount of deps we have
I get a ton of warnings like:
2021-02-04T14:57:13.955Z MBP2019.local ERROR [clojure-lsp.crawler:149] - Cannot find position for: generate-drugbank-nq {:end-row nil, :name-end-col nil, :name-end-row nil, :name-row nil, :ns dre.task.populate, :name generate-drugbank-nq, :filename "/Users/borkdude/dre/DocSearch/app/src/dre/task/populate.clj", :col nil, :name-col nil, :end-col nil, :bucket :var-definitions, :row nil} nil
like hundreds, maybe thousands
I think that may not be the issue though
it doesn't specify what paths it analyzed
yeah, is not the issue
any Error while looking up classpath info
error on logs?
https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/crawler.clj#L34
no. but I don't trust any logic which tries to do this automatically because our build is pretty custom
@borkdude remove .lsp/sqlite.db
and restart the project and check the logs
ok
You can configure custom project specs
: https://clojure-lsp.github.io/clojure-lsp/settings/
on how to get the classpath
2021-02-04T15:02:04.946Z MBP2019.local INFO [clojure-lsp.crawler:111] - Analyzing 2 paths with clj-kondo with batch size of 1 ...
ah thanks
so go to external deps worked?
I will try
I think I'll make a babashka script to produce the classpath :P
hahah looks helpful
I mean, to append the clojure -Spath and the boot one
oh, for your project only seems ok
but you could have 2 project specs
this is better:
2021-02-04T15:08:00.235Z MBP2019.local INFO [clojure-lsp.crawler:111] - Analyzing 115 paths with clj-kondo with batch size of 3 ...
Oh I can have 2? niceyep, this should already work: https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/crawler.clj#L53-L60
those are the default that clojure-lsp try
nice. we have a custom clojure runner which I have to hook in here
our boot stuff is so custom and slow
it first tries to download deps from s3 for a minute
š®
this is something I want to improve on clojure-lsp somehow, getting classpath could be slow, using lein you need to wait some secs
for your case, is way worst š
but this is exactly what I wanted, this config, so thanks
This is my final config:
{:project-specs [{:project-path "deps.edn"
:classpath-cmd ["./clojure" "-Spath"]}
{:project-path "build.boot"
:classpath-cmd ["./boot" "show" "--fake-classpath""-Spath"]}]}
does it invoke this every time I visit this project... I hope not?
it caches on sqlite
maybe it can keep a sha of the files ?
I mean, does it also skip the invocation of these commands then?
2021-02-04T15:13:11.168Z MBP2019.local INFO [clojure-lsp.crawler:111] - Analyzing 123 paths with clj-kondo with batch size of 3 ...
and does it deduplicate the paths?
yes, it uses a digest/md5 on the project-file
excellent
Hum, not sure, probably don't deduplicate
oh, we create a set
so it should remove duplicates
excellent, now it can find even things from cljs.core
problems solved!
what is your general gitignore recommendation for .lsp?
.lsp/sql* ?
yep
actually, I use a global gitignore for that
since nubank has hundred of services
ok
and is not everybody that uses clojure-lsp š¢
because I want to commit my config now
this is my config if you wanna copy something: https://github.com/ericdallo/dotfiles/blob/master/.lsp/config.edn
Does lsp-find-definition or find reference works with namespaced keywords? I am thinking about re-frame where I always struggle to navigate to the definition of the event/subscription.
Not yet, that's exactly what I'm WIP right now š
Should be ready by tomorrow
Related: https://clojurians.slack.com/archives/CPABC1H61/p1612348768252400
:bananadance:
You two are my heroes, @borkdude, @ericdallo. There are so many re-frame subs and handlers in my work project, I get dizzy.
Yeah!!!! Thanks a lot :) I was waiting for this for soooo long haha :)
This will be so good. And I think this is something that wasn't available in REPL-based tooling either
Maybe Cursive has something like this? I wouldn't know
hahah thanks, but not sure it will work for re-frame as you expect š
since it's pretty common to use something like:
(dispatch [:foo/bar ...])
There is no way to know what is the definition of foo/bar
, it's not relate to a require or something like this
the support we are adding is for aliased namespaces like:
[my-foo :as foo]
::foo/bar
then we know where is the definition
@ericdallo Actually there will be something like this. The keyword "definition" is already support for clojure.spec.alpha/def
Auto-resolving keywords doesn't make it a "definition"
does clj-kondo provides the :def
for those cases?
I think it'd be possible
What I already find a win is that you could do find references
and you will get all the occurrences of :foo/bar
regardless of alias
on the same namespace, you mean?
clj-kondo provides :def
for clojure.spec.alpha/def currently, but hooks will be extended with the possibility of registering your own def'ed keywords
What I personally want is, regardless of :def
just have a list of all :foo/bar
whether they occurs as ::f/bar
or :foo/bar
Hum, we can do that I think, will confirm tonight š
I think I would want the same for find-references, I want the definition in there too and not have to do a separate search, but this might be a bigger change / option
I mean for normal fns
yeah, we'd need to know what is the keyword that defines it
Note that there can be multiple :def
s for the same keyword. E.g. (reg-event-fx [::foo])
and (reg-sub [::foo])
.
but personally I'm not interested in :def at all, I just want to see them all - good enough for me
I doubt you two will be less of my heroes when I see how this will work. Iām already super boosted in my editing by these amazing tools.
what I think I am trying to say: instead of choosing between find-definition(s?) and find-references, I want both in one overview. maybe that's a third option: find-defs-and-refs
this already works if client provides includeDeclaration
on find-references @borkdude š Calva use with this flag on already
if we make definition work, that will work too
nice. can I put this in my .lsp/config.edn?
yep š
how and where? config.edn:
{:include-declaration true}
or something?I don't see it here: https://clojure-lsp.github.io/clojure-lsp/settings/
oh, just realized it's only available via initializationOptions, so only changing the client š we need to make the code check for the config too
it's easy, but need code changes
here: https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/handlers.clj#L121
@ericdallo it's not clear to me what the alternative to .lsp/config.edn is. > "initializationOptions" where do these go?
and are these merged with config.edn?
yes, they are sent from client, in this case, lsp-mode
https://github.com/emacs-lsp/lsp-mode/blob/master/clients/lsp-clojure.el#L218
so I can set them in elisp?
yes hahah
there is no defcustom for that, but is something that we could change too on lsp-mode
not sure what to do in elisp to be honest
lsp-include-declaration t ?
oh, it won't work, now I remember why I didn't create a config for that
is not something that is configurable, it comes from the references request
and ATM lsp-mode just hard code to false š
https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L4597
it'd be necessary just to include a defcustom as the first arg of this function https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-mode.el#L5535 , something like lsp-include-declaration-on-references
yeah, I looked at that code
anyway, I'll bug the other guy on discord
also in lsp-ui for ls-ui users
lsp-ui?
:catjam:
overall there are a lot of features, bt you can disable all of them, my favorite is the lsp-ui-find-references
which shows a window just like vscode for finding references
is lsp-ui a package you have to install?
yep
just like lsp-treemacs
lsp-ivy
etc
holy crap, I think this is too fancy for me
thanks for another distracting feature!
The box on the right top that shows the docs of every var. It's nice, but also quite distracting, every time you move your cursor there's docstrings
HAHAHAH
yeah, i disable that
Actually almost all users disable that š
can I borrow you settings?
it's something that needs to change the default
sure! https://github.com/ericdallo/dotfiles/blob/master/.doom.d/config.el#L189-L195
š
Did you test the lens feature?
https://github.com/ericdallo/dotfiles/blob/master/.doom.d/config.el#L176
clojure-lsp shows references code lens š
yes, about the number of usages right?
darn, the doc still is on after your config. isn't it this thing you commented out?
;; lsp-ui-doc-enable nil
yeah, that's it
thanks
š“
Yeah, doom-emacs already disable it by default. š
Oh, just tested and the find references on a :foo/bar
already works as you expect š