Fork me on GitHub
#lsp
<
2023-04-14
>
Martynas Maciulevičius05:04:32

Hey. How do I configure LSP to do less highlighting? For instance I use nvim and when I disable the default highlighting that I used all the time then LSP still highlights my buffer... but after 1-2 seconds. I want my highlighting to be instant because this is distracting. How can I tune this to disable variable and function highlighting? Unused variables are ok to keep but I think it just does too much work to be fast. I have a really powerful laptop and it's still lagging so I think you have to remove something from your plugin. The first screenshot shows how it highlights everything in the world. I don't need this. This is over the top. The second screenshot shows what I have when I don't enable clojure_lsp . Yes, the function name highlighting and unused function highlighting could be great but it highlights just too much stuff and it's too slow (the second screenshot has + that is hardcoded in clojure.vim highlighting plugin so it's highlighted in yellow). My setup was to not use clojure_lsp at all but for some reason something made it so that I can't disable it even if I use :syntax off in nvim. It does the highlighting even if I don't want to highlight anything in the buffer (but probably this isn't the issue with clojure_lsp but with a plugin that loads the LSP server). I mainly want to understand how to tune the highlighter to output less stuff because I don't need it.

lispyclouds06:04:53

The way i understand semantic tokens is for us to interpret/configure our colorscheme etc to handle them differently, not the lsp server to highlight less. Its just sending some extra data which is up for interpretation or ignoring etc. I think tuning how your colorscheme sees the highlight groups is more relevant/useful than tuning the lsp server here.

lispyclouds06:04:32

colorschemes like https://github.com/folke/tokyonight.nvim specifically supports the semantic tokens for example

Martynas Maciulevičius06:04:25

Wouldn't it be less wasteful to not do the unneeded analysis in the first place? I understand that we live in an era where CPU and RAM are infinite. But what if I don't want to analyze what I don't need...? Especially if it takes 1-2 seconds to analyze it.

lispyclouds06:04:00

yeah can disable it then if its unneeded.

Martynas Maciulevičius07:04:25

In my opinion it takes away from nvim's speediness and immediate startup because everything else is immediate in that editor. And by making things that take 1-2 seconds we get a distraction and then we're getting used to only open one IDE at all times because it will be the same as in Emacs where you're not supposed to exit a single instance of your IDE.

ericdallo11:04:46

On emacs that's pretty fast, probably something to tune in vim side, even so, you can disable semantic tokens on client side or server side via semantic-tokens? setting https://clojure-lsp.io/settings/

ericdallo11:04:21

You should configure it in .lsp/config.edn, but keep in mind that feature should be configurable via nvim, it's part of the spec make that optional

Martynas Maciulevičius12:04:20

I tried to configure that using command line using --settings but even if the server was run using these parameters the IDE still received the highlighting information.

ericdallo12:04:51

Maybe the docs are not clear but --settings only work for clojure-lsp CLI commands, not when using via Editor

Martynas Maciulevičius12:04:22

Why is this distinction useful?

ericdallo12:04:29

via editor, what you want in this case, you have 2 options: • change .lsp/config.ednand add your setting there • change your client to send the setting you want via https://clojure-lsp.io/settings/#initializationoptions

ericdallo12:04:07

probably it's not useful, editor should consider that flag --settings as well, it just doesn't do ATM, never anyone requested it

ericdallo12:04:31

it's way more common for people configure lsp settings in .lsp/config.edn

Martynas Maciulevičius12:04:53

I tried to use nvim's plugins to load these settings and they didn't wire it correctly. Then I decided to simply use CLI but that didn't work either :thinking_face: I wanted to configure my LSP to not depend on copying files around. I wanted it to solely live in my nvim config. Of course this may prevent project-local settings but that wasn't my goal.

ericdallo12:04:27

so initializationOptions is the way to go

2
Martynas Maciulevičius12:04:04

I'll either do that or create a color scheme plugin that accomodates the new LSP changes.

Martynas Maciulevičius12:04:55

I think nvim doesn't have a way to properly do it (or at least I use a broken plugin): https://clojurians.slack.com/archives/C0DF8R51A/p1681453494605029

Martynas Maciulevičius12:04:01

This was what I wanted to do from the start but then I tried more and more but nothing worked. So now I also tried to nuke the highlighting from LSP via CLI options which didn't also work. So I think I'll instead change the colorscheme so that it would highlight correctly.

👍 2
ericdallo12:04:34

there are plenty of ways to debug if client is sending correct stuff, one way is get <https://clojure-lsp.io/troubleshooting/#client-server-log%7Cclient&lt;-&gt;server logs>, and check what vim is sending in the initialize request

Martynas Maciulevičius12:04:17

This worked:

init_options = {
      ['semantic-tokens?'] = false
    }
I think what actually helped is to take a break and take a walk.

2
👍 2
ericdallo12:04:42

Glad you found it!

Martynas Maciulevičius12:04:23

I guess... but before taking a break I found out how to make the highlighting work with correct colors. So now I'll have to make it work.

😂 2
Martynas Maciulevičius07:04:15

I tried to run this command and I think that the argument :semantic-tokens? is not picked up:

/usr/bin/clojure-lsp --settings {:semantic-tokens? false}
I want my editor to not use the extended syntax highlighting and this option should disable it but for some reason it doesn't. I start the LSP server using this command (it's started via my IDE). I forced the IDE to start it using that command. Do you think there could be a bug with how the parameter is read? Versions: clojure-lsp 2023.02.27-13.12.12 NVIM v0.9.0

borkdude15:04:12

@ericdallo Should I add a test for this somewhere? https://github.com/clojure-lsp/clojure-lsp/pull/1548/files Do you have tests with different clj-kondo configs?

borkdude19:04:09

A lot of tests are failing for me locally with bb test-lib but they aren't failing on CI. any ideas?

ericdallo19:04:14

does bb test works?

borkdude19:04:02

when a single namespace is specified FAIL
      when a single namespace is specified with dry option
      when ns does not matches uri
      when ns is already formatted FAIL FAIL
      when single filename is specified FAIL FAIL

borkdude19:04:33

I'll test the master branch

borkdude19:04:07

also failing:

263 tests, 2688 assertions, 8 failures.

borkdude19:04:57

maybe because I have:

:clojure-lsp/unused-public-var {:level :off}
in my home lsp config?

borkdude19:04:08

I think the tests should be able to handle that

borkdude19:04:19

nope, that wasn't it either

ericdallo19:04:43

ah yeah, probably

ericdallo19:04:55

for me it pass, it's something with your config env I think

ericdallo19:04:04

maybe ~/.config/clojure-lsp/config.edn ?

borkdude19:04:20

hmm maybe it's this:

:diagnostics {:range-type :simple}

borkdude19:04:31

I think the user's config should not matter for the test and this should be fixed

borkdude19:04:14

crap, still getting failures

borkdude19:04:44

this sucks since I can't write tests locally now

ericdallo19:04:44

those tests are from api_test.clj right? things you are not touching, maybe ignore until we find the root cause

borkdude20:04:32

yeah, I'll have another look tomorrow

borkdude13:04:23

The issue was

:cljfmt {:remove-multiple-non-indenting-spaces? true
          :sort-ns-references? true
          :remove-consecutive-blank-lines? false}
in my config

borkdude13:04:31

as well as:

:diagnostics {:range-type :simple}

borkdude13:04:48

maybe the tests can have something like: ignore the user's config? not sure what the best solution is, but I'll make an issue

borkdude13:04:06

I'm confused as to why this doesn't give me a proper error:

(h/load-code-and-locs "(ns cljc-ns) (let [x 1])" (h/file-uri "file:///cljc_ns.cljc"))
  (testing "clj-kondo show langs in cljc file"
    (swap! (h/db*) shared/deep-merge {:kondo-config {:output {:langs true}
                                                     :linters {:unused-binding {:level :warning}}}
                                      :settings {:linters {:clj-kondo {:level :off}}}})
    (h/assert-submaps
     [{:a 1}]
     (f.diagnostic/find-diagnostics (h/file-uri "file:///cljc_ns.cljc") (h/db))))

borkdude13:04:19

I expect a warning about the unused binding

borkdude13:04:15

I added the test here but it still needs to be finished: https://github.com/clojure-lsp/clojure-lsp/pull/1548 can you give any pointers?

borkdude13:04:04

got something working now, I needed to remove :level :off of course, I copied that from somewhere else facepalm

ericdallo14:04:25

Thanks! Will take a look soon