Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not call textDocument/documentColor when LSP server doesn't support it #117

Open
simonmandlik opened this issue Apr 24, 2024 · 7 comments · May be fixed by #118
Open

Do not call textDocument/documentColor when LSP server doesn't support it #117

simonmandlik opened this issue Apr 24, 2024 · 7 comments · May be fixed by #118
Labels
enhancement New feature or request

Comments

@simonmandlik
Copy link

simonmandlik commented Apr 24, 2024

Request for other features

Some LSP servers do not support textDocument/documentColor. This leads to warnings, and, in worse cases, crashes.

For example, LS for julia crashes when receiving a request for textDocument/documentColor.

Would it be possible to not generate these requests when the LSP does not support it? This can be deduced from server capabilities, i.e.

vim.lsp.get_clients()[1].server_capabilities

For example, julia LS declares here that it doesn't support textDocument/documentColor.

Thanks!

@simonmandlik simonmandlik added the enhancement New feature or request label Apr 24, 2024
@uga-rosa
Copy link
Owner

Thanks for the report. I know how to do the checks, and I'm doing some of them. It's just that doing something like Promise.all in lua is a bit of a pain, so I've been putting off dealing with it strictly. Most servers don't crash when they are asked to use unsupported methods.
Well, now that you've reported it, we'll deal with it. Please wait a while.

@uga-rosa
Copy link
Owner

@simonmandlik
Please test fix/117 branch

@lcw
Copy link

lcw commented May 21, 2024

I just tested fix/117 and it didn't work for me.

@uga-rosa
Copy link
Owner

uga-rosa commented May 22, 2024

@lcw
What does “it didn't work for me” mean? Do you still get the same warnings and LS crashes (the issue is not resolved), or does the highlighting with LS itself no longer work?

@lcw
Copy link

lcw commented May 22, 2024

Good questions. When I updated ccc to the branch with the proposed fix 9dd83ea I still see LS for julia crashing when receiving a request for textDocument/documentColor.

My Lazy config for loading ccc is:

  {
    'uga-rosa/ccc.nvim',
    branch = 'fix/117',
    config = function()
      local ColorInput = require 'ccc.input'
      local convert = require 'ccc.utils.convert'

      local RgbHslCmykInput = setmetatable({
        name = 'RGB/HSL/CMYK',
        max = { 1, 1, 1, 360, 1, 1, 1, 1, 1, 1 },
        min = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        delta = { 1 / 255, 1 / 255, 1 / 255, 1, 0.01, 0.01, 0.005, 0.005, 0.005, 0.005 },
        bar_name = { 'R', 'G', 'B', 'H', 'S', 'L', 'C', 'M', 'Y', 'K' },
      }, { __index = ColorInput })

      function RgbHslCmykInput.format(n, i)
        if i <= 3 then
          -- RGB
          n = n * 255
        elseif i == 5 or i == 6 then
          -- S or L of HSL
          n = n * 100
        elseif i >= 7 then
          -- CMYK
          return ('%5.1f%%'):format(math.floor(n * 200) / 2)
        end
        return ('%6d'):format(n)
      end

      function RgbHslCmykInput.from_rgb(RGB)
        local HSL = convert.rgb2hsl(RGB)
        local CMYK = convert.rgb2cmyk(RGB)
        local R, G, B = unpack(RGB)
        local H, S, L = unpack(HSL)
        local C, M, Y, K = unpack(CMYK)
        return { R, G, B, H, S, L, C, M, Y, K }
      end

      function RgbHslCmykInput.to_rgb(value)
        return { value[1], value[2], value[3] }
      end

      function RgbHslCmykInput:_set_rgb(RGB)
        self.value[1] = RGB[1]
        self.value[2] = RGB[2]
        self.value[3] = RGB[3]
      end

      function RgbHslCmykInput:_set_hsl(HSL)
        self.value[4] = HSL[1]
        self.value[5] = HSL[2]
        self.value[6] = HSL[3]
      end

      function RgbHslCmykInput:_set_cmyk(CMYK)
        self.value[7] = CMYK[1]
        self.value[8] = CMYK[2]
        self.value[9] = CMYK[3]
        self.value[10] = CMYK[4]
      end

      function RgbHslCmykInput:callback(index, new_value)
        self.value[index] = new_value
        local v = self.value
        if index <= 3 then
          local RGB = { v[1], v[2], v[3] }
          local HSL = convert.rgb2hsl(RGB)
          local CMYK = convert.rgb2cmyk(RGB)
          self:_set_hsl(HSL)
          self:_set_cmyk(CMYK)
        elseif index <= 6 then
          local HSL = { v[4], v[5], v[6] }
          local RGB = convert.hsl2rgb(HSL)
          local CMYK = convert.rgb2cmyk(RGB)
          self:_set_rgb(RGB)
          self:_set_cmyk(CMYK)
        else
          local CMYK = { v[7], v[8], v[9], v[10] }
          local RGB = convert.cmyk2rgb(CMYK)
          local HSL = convert.rgb2hsl(RGB)
          self:_set_rgb(RGB)
          self:_set_hsl(HSL)
        end
      end

      local ccc = require 'ccc'
      ccc.setup {
        inputs = {
          RgbHslCmykInput,
        },
        -- highlighter = {
        --   auto_enable = false,
        --   lsp = false,
        -- },
      }
    end,
  },

Interestingly, I just tried the following config:

 {
    'uga-rosa/ccc.nvim',
    branch = 'fix/117',
 },

and I don't see any LS crashes. I don't know if the highlighing is still working. I just use ccc for the color picker.

@uga-rosa
Copy link
Owner

I can't try julia lsp because it won't start...
Is there a polite way to set up julia lsp or an example of how to reproduce this on another lsp?

@simonmandlik
Copy link
Author

Have you seen this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants