Fork me on GitHub
#lsp
<
2024-05-06
>
didibus03:05:22

I still can't see import missing libspec and add missing imports in the code actions. I'm not even sure how to execute add-missing-import without code actions. This is using Emacs

ericdallo11:05:12

lsp-execute-code-action will present all code actions in that line/char position

ericdallo11:05:52

otherwise if you wanna execute a specific command, lsp-clojure-* , although via code action is probably a better idea

didibus15:05:24

add-missing-import doesn't show up as a code action, and also does not exist as a lsp-clojure-* command

didibus15:05:19

There's add-import-to-namespace, but I believe that's different no? This one it asks you what is the full import you want to add

ericdallo15:05:49

We have it under other more UX friendly name in code actions

ericdallo15:05:51

The truth is that code actions should be used for that, it cover all cases that command does and even more like suggestions and so on

didibus15:05:49

Code Actions have not been very reliable for me. The libspec/missing import has not shown up in it for over a year

ericdallo15:05:16

The code action is just a friendly UX for a command, if that's not showing it's because even the command wouldn't work. Looks like a bug or misconfiguration in the project, if you manage to repro in https://github.com/ericdallo/clojure-sample would be easier to understand

didibus15:05:40

Is it not possible that it's the contextual logic that does not work? Like for showing the code action or not?

didibus15:05:17

I saw last time you said: > the missing import code action relies on java analysis, that for JDK is done after startup as an async process, you should see Analyzing JDK source after startup message from latest clojure-lsp or just check the logs, you can force java analysis scan removing ~/.cache/clojure-lsp and restart LSP

didibus15:05:51

That has never worked since I started that thread in 2022

ericdallo16:05:42

please, share a piece of code or test in that repo sample I mentioned, it's really hard to understand only saying: "it doesn't work for me"

didibus16:05:11

You mean as in, if I checkout that sample project? Or you want a similar sample project to repro?

ericdallo16:05:35

You can checkout that project, I just need to understand what you are trying to do in what snippet of code

didibus16:05:06

(Date.) Cursor over the D, run lsp-execute-code-action. Expect to see add missing import, but do not see it.

ericdallo16:05:53

but it's missing the java.util one right?

didibus16:05:15

Ya, I see at the Create private function Date. But I don't see the Add 'import above it

ericdallo16:05:32

looks like a bug

didibus16:05:34

For me, I don't see any Add import. In yours it's missing the java.util one

ericdallo16:05:02

we should suggest: Add import 'java.util.Date'

ericdallo16:05:25

on mine there is one Date from a random apache lib that project has

didibus16:05:03

Right. Ok so ya, if I try for a java class that I wrote in my project I do see it. So it seems specific to java.util.Date

ericdallo16:05:57

I deleted my ~/.cache/clojure-lsp , restarted lsp with lsp-workspace-restart and now it works, it seems clojure-lsp had a wrong cached java analaysis for some reason

didibus16:05:00

Maybe the analysis skips the JDK standard lib?

ericdallo16:05:03

could you try the same?

didibus16:05:18

Ok let me try

ericdallo16:05:40

probably some clojure-lsp bug with the post startup java sdk analysis :thinking_face:

didibus16:05:50

Hum, now I don't see any import. You say it takes a bit of time?

ericdallo16:05:26

yeah, after startup clojure-lsp will do a async task of analyze jdk, it should mention in the progress on the right bottom

didibus16:05:03

Oh weird. So I have two java classes in my project. One it works, the other it does not.

ericdallo16:05:38

first let's check if the built-in java.util.Date works, then we check the other issue

didibus16:05:54

Date does not work

didibus16:05:20

What buffer should I see the JDK Analyzing ?

didibus16:05:06

I don't think I see Analyzing JDK source in any of the log/message buffers

ericdallo16:05:37

no buffer, it's a thing in the Emacs modeline, only if you are using lsp-mode

ericdallo16:05:11

but it should show in clojure-lsp logs too, although would be nice checking why you don't see it

didibus16:05:11

I think maybe the spacemacs modeline takes over?

didibus16:05:37

Also, the content of ~/.cache/clojure-lsp is empty

didibus16:05:57

Well, there's a jdk folder, but it is empty

ericdallo16:05:24

it should show on spaceemacs too

ericdallo16:05:33

so it didn't analyze

ericdallo16:05:40

or it's analyzing still 😅

didibus16:05:10

Where are the clojure lsp logs ?

ericdallo16:05:31

try lsp-clojure-server-log

didibus16:05:02

> 2024-05-06T16:27:56.643Z WARN [clojure-lsp.feature.java-interop:303] - [Java] JDK source not found, skipping java analysis.

didibus16:05:17

> 2024-05-06T16:27:56.643Z WARN [clojure-lsp.feature.java-interop:292] - [Java] Skipping download JDK source, setting :java :download-jdk-source? is disabled.

didibus16:05:47

Is this because I don't have on my machine the JDK installed where the source files are included? And in that case, I could turn on this option and clojure-lsp would download the source on its own? Or I could try to install the JDL sources on my machine?

ericdallo16:05:33

yeah, clojure-lsp didn't find any JDK installation, and since :java :download-jdk-source? setting is disabled by default it didn't download

ericdallo16:05:57

I'm wondering if we should change that setting to true as default, I could swear it was true already :thinking_face: , but meanwhile could you try changing to true?

didibus17:05:39

Before I change it to true, I'm wondering why it didn't find a JDK install? Where does it look for the JDK and it's source files?

didibus05:05:06

@UKFSJSM38 Ok, on openSuse the jdk install does not install the sources by default, you have to install the source bundle as well. After I did that, it all works now. One thing I noticed is the issue I was having with some of my classes also not appearing in the code actions is resolved. So maybe somehow if the JDK sources are missing, it also breaks the analysis of some of the java sources in the project itself. Not sure, but at least it seems it's all working for me now.

ericdallo22:05:09

glad it works, but yeah, it could be some bug on cache consistency