Fork me on GitHub
#vim
<
2023-04-14
>
Martynas Maciulevičius06:04:54

Did anyone manage to pass custom options to clojure_lsp when using lspconfig? I want to pass an option and there is simply no way it works for me:

lspconfig.clojure_lsp.setup({
...
    settings     = {
      -- 
      clojure_lsp = {
        ['semantic-tokens'] = false,
        ['semantic-tokens?'] = false
      },
      ['clojure-lsp'] = {
        ['semantic-tokens'] = false,
        ['semantic-tokens?'] = false
      },
      clojure = {
        ['semantic-tokens'] = false,
        ['semantic-tokens?'] = false
      },
      ['semantic-tokens'] = false,
      ['semantic-tokens?'] = false
    },
    ['semantic-tokens'] = false,
    ['semantic-tokens?'] = false
  })

lispyclouds06:04:23

I think this cannot be configured from the client side. need to set {:semantic-tokens? false} in either .lsp/config.edn or ~/.config/clojure-lsp/config.edn i think

lispyclouds06:04:32

root_dir is the only client side config that's passed to it as of now

Martynas Maciulevičius06:04:38

My goal is to keep the config inside of nvim's config file so that I wouldn't have it all scattered around. I also tried this and it actually starts clojure_lsp with the right arg and clojure_lsp doesn't crash

cmd = {
      '/usr/bin/clojure-lsp', '--settings', '{:semantic-tokens? false :semantic-tokens false}'
    },
But then the LSP highlighting still works. I don't know what's going on 😕 Maybe it's a wrong option.

Martynas Maciulevičius06:04:04

Alright. Using --settings worked the way I intended in my previous message.

lispyclouds06:04:47

yeah this is the only way to configure it as of now

Martynas Maciulevičius06:04:07

No, it didn't work. I submitted a bad config. semantic-tokens gets ignored. I don't know how to configure this anymore :thinking_face: The binary runs with the correct args and doesn't crash but the highlighting is still enabled:

>  ps aux | grep clojure-lsp
/usr/bin/clojure-lsp --settings {:semantic-tokens? false :semantic-tokens false}

Martynas Maciulevičius06:04:43

I know but it's simply ignored. And I even passed one without ? too

lispyclouds06:04:22

im assuming youre on nvim 0.9?

Martynas Maciulevičius06:04:45

NVIM v0.9.0 clojure-lsp 2023.02.27-13.12.12 But this can't be nvim's issue because the command line is constructed by me. And then there is no other LSP server that could analyze that extended highlighting because I checked that there is only one clojure-lsp running with that specified arg. I'll ask in lsp channel.

lispyclouds07:04:11

yeah im thinking of a way for nvim to ignore the lsp tokens

lispyclouds07:04:11

try

vim.api.nvim_create_autocmd("LspAttach", {
  callback = function(args)
    local client = vim.lsp.get_client_by_id(args.data.client_id)
    client.server_capabilities.semanticTokensProvider = nil
  end,
});

lispyclouds07:04:48

also vim.lsp.semantic_tokens.stop() should work too i think

lispyclouds07:04:13

you can call this when the lsp attaches

Martynas Maciulevičius07:04:34

If vim.lsp.semantic_tokens.stop() works then it could be better because it would be stopped from LSP's side and not from editor's side :thinking_face: But wait, wouldn't it stop tokens for all LSP sessions?

lispyclouds07:04:27

its for the buffer i think

lispyclouds07:04:59

as for the lsp config, not quite sure why it doesnt pick up the settings from the command line arg, have only used the edn file configs. the clojure-lsp maintainers would know better

Martynas Maciulevičius07:04:08

I wrote it in the chat. Maybe something is wrong. This is the second time I try some config that nobody tried before and it doesn't work.

lispyclouds07:04:15

ah yeah, you need to pass the buffer number and client id to stop:

stop({bufnr}, {client_id})                    *vim.lsp.semantic_tokens.stop()*
    Stop the semantic token highlighting engine for the given buffer with the
    given client.

    NOTE: This is automatically called by a |LspDetach| autocmd that is set up
    as part of `start()`, so you should only need this function to manually
    disengage the semantic token engine without fully detaching the LSP client
    from the buffer.

    Parameters: ~
      • {bufnr}      (integer)
      • {client_id}  (integer)
never used it, reading the help now

lispyclouds07:04:40

clojure-lsp has been sending these tokens for a while now i think, nvim from 0.9 started to use them now

Martynas Maciulevičius07:04:45

Well for me vim.lsp.semantic_tokens.stop() doesn't work to disable the tokens. I think they didn't expect that some random guy would want this stupid feature.

lispyclouds07:04:26

well like i said, your colorscheme needs to handle these in a way that you want

lispyclouds07:04:44

i think you have regex based highlighting too

lispyclouds07:04:55

these two are at odds

Martynas Maciulevičius07:04:36

Regex-based highlighting is very fast. And also there will be a treesitter highlighting at some point which in theory should be faster and better. And this LSP one... it's good but I want to keep it simple. Three highlighting providers is quite much.

lispyclouds07:04:20

yes, you need to stick to either regex or the semantic/treesitter ones. combining both isnt good as they approch the issue with very different and incompatible perspectives

lispyclouds07:04:02

having both on would have issues like this

Martynas Maciulevičius07:04:33

The problem with LSP highlighting is that when I type :syntax off it doesn't turn off. It doesn't care whether I want highlighting at all or not.

lispyclouds07:04:59

that maybe coming from tressiter too

Martynas Maciulevičius07:04:07

> that maybe coming from tressiter too I disabled treesitter because it wasn't highlighting parts of keywords and for other cases I didn't need any highlighting. LSP highlights unused vars correctly but it's intrusive to the point that it highlights everything where it's actually harming the readability. And I already can find unused vars using clj-kondo and LSP messages. Which means that LSP highlighting only gets in the way and lags for no reason.

lispyclouds07:04:30

> Regex-based highlighting is very fast. it has issues in things like very long lines etc, hence the other methods

lispyclouds07:04:02

id wanna say you see the laggy ones more due to the regex one doing it first, then the lsp changing it. but yes if its an annoyance you can turn it off. it there for other reasons, which may not be yours

Martynas Maciulevičius07:04:32

I use LSP for jumping around in the code and for that it works very well. But I only want the jumping part and not highlighting one. Of course it would be good if it can highlight functions and macros correctly but I want to understand what it does first instead of letting myself into the 1-2s lag. For now I don't think it's useful to have it.

lispyclouds07:04:40

id just say again, lsp is just sending some data, your colorscheme is interpreting this differently now. the longer term fix should be to adapt the colorscheme and not turn the tokens off

Martynas Maciulevičius08:04:51

I can't run nvim with syntax off and LSP. LSP just doesn't highlight parens and everything. And then it also breaks existing themes too because now it colors things as it wants. For instance when I turn :syntax off then I can't have :syntax command which would display why a token is colored the way it is. So the only way I try to debug it is to find a colorscheme that colors the thing I want and override it.

Martynas Maciulevičius09:04:12

Turns out this is the syntax variable that I was looking for: @lsp.type.keyword Oh my.