ray-x / lsp_signature.nvim

LSP signature hint as you type
Apache License 2.0
2.01k stars 56 forks source link

cmp + pyright + signature setup #253

Open zippeurfou opened 1 year ago

zippeurfou commented 1 year ago

Hey @ray-x , Thanks for this awesome plugin. I have been trying to use your plugin for my completion and I have a few questions:

  1. is it possible to edit what goes into the floating window. eg. showing "LspSignatureActiveParameter" instead of the whole thing?

  2. I do have cases where the hint position is pretty odd. Is this expected/configurable?

    Screenshot 2023-01-20 at 2 52 53 PM
  3. I would like the "LspSignatureActiveParameter" to be on the right side of my menu rather than as a hint text. See for example this

    Screenshot 2023-01-20 at 2 53 42 PM

    compared to this Screenshot 2023-01-20 at 2 54 10 PM. How could I configure it to behave like that?

  4. This might not be related to your plugin but I'd like to say that when I am inside a function call in python I'd like to only display the variable with = at the end that have a signature. See how this create noise vs the vscode equivalent.

    Screenshot 2023-01-20 at 2 57 41 PM Screenshot 2023-01-20 at 2 58 29 PM
  5. See how in vscode in the window it add the LspSignatureActiveParameter inside the window (callback in the screenshot). Is there a way to do that with your plugin?

Sorry for all theses questions. I just am not sure where to go :(

ray-x commented 1 year ago

For 1: You can try virtual text mode For 2: It related to your LSP server response. In the example you posted. The response is in string match mode, so it is not accurate. You can change to another LSP server to see if its behaviour differently

zippeurfou commented 1 year ago

@ray-x thanks, for 1, I meant instead of seeing the full list of all the argument on the window, only show the current one (so basically in my screenshot having the green text as a window not as a text next to it). For 2, this is because of pyright. that's what you're saying right? So if I want to use python I don''t have a choice unless I use another server which most likely is less good.

For 4 I have been editing my source with this:

        sources = cmp.config.sources({
          { name = "nvim_lsp", max_item_count = 15,
            entry_filter= function (entry,context)
              local kind = entry:get_kind()
              local node = ts_utils.get_node_at_cursor():type()
              if node == "ERROR" and kind == 6 then
               -- This happen when the parenthesis is open but not closed. I need to figure out a way there
              end
              if node == "argument_list" and context.filetype =="python" then
                local str = entry:get_word()
                local last_char = string.sub(str,string.len(str))
                if kind == 6 and last_char=='=' then
                  return true
                else
                  return false
                end
              end
              return true
            end
          },

This is very messy code but I am hoping I can figure out with looking at your plugin source code maybe a cleaner way.

Screenshot 2023-01-20 at 5 47 46 PM

I still see the same issues with the hint being hard to read but it is a start at least.

If I could move the hint to what I am asking for 3 this would be fantastic. I just have no idea how to do so :/

ray-x commented 1 year ago

In fact for 3, you can refer to this PR https://github.com/ray-x/lsp_signature.nvim/issues/248 Both off_y and off_x can be functions and you can calculate the position

zippeurfou commented 1 year ago

Thanks again @ray-x for your help. Really appreciate it. For 3 I am a bit confused as I guess there are 2 things to change which I am not sure how to do it.

  1. Have the hint text being a window with border rather than green text formated the same way as documentation window in cmp
  2. Position it on the right side of cmp so it looks like the same as when I try to get the documentation window. I think 248 can help for 2 (I am still a bit lost there). For 1 I just have no idea.
ray-x commented 1 year ago

For 1. I still feel you can check the virtual text only option work for you or not. If you want a floating windows with boarder and only show the active parameter. You can create a new floating window, instead of put the full signature inside, you can put the virtual text. something like this:

      _LSP_SIG_CFG.bufnr, _LSP_SIG_CFG.winnr = vim.lsp.util.open_floating_preview({'the_virtual_text_of_signature'}, syntax, config)