ray-x / lsp_signature.nvim

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

[enhancement] add support to option `floating_window_off_y` as a function #248

Closed yao-weijie closed 1 year ago

yao-weijie commented 1 year ago

In current version, it's difficult to avoid conflict between lsp_signature.nvim and nvim-cmp, especially when the cursor at the top or bottom of window, I found a solution to solve this problem.

lsp_signature.setup({ ...

floating_window = true,
floating_window_above_cur_line = false,
floating_window_off_x = 0,
floating_window_off_y = offsety,

...

})



- modification
modify `lsp_signature.nvim/lua/init.lua`
![图片](https://user-images.githubusercontent.com/36393630/206346358-c316b4b0-440c-42db-86d7-7cecc2984b5f.png)

- final effect
  - at window top

![图片](https://user-images.githubusercontent.com/36393630/206346868-85eebe9d-7b05-4614-b186-9f7b477fdb5b.png)

  - at window bottom

![图片](https://user-images.githubusercontent.com/36393630/206347054-efc701eb-a49c-4a95-ab7d-0789a2650949.png)

  - at window middle area

![图片](https://user-images.githubusercontent.com/36393630/206347156-7438f8c7-345b-45c4-8d57-5921c6fed2ae.png)

- requirements
  the window is high enough, and it's better not to split horizontal :)
ray-x commented 1 year ago

Thanks for your suggestions. I pushed a commit based on your code snippets.

ray-x commented 1 year ago

@yao-weijie Could you check if it works for you. Also when you happy, please share your offset_x/y function setup.

yao-weijie commented 1 year ago

I replied the mail but it seems that you didn't received it. :(

The patch works (I used the offset_y function as you put in README). And I think there are some auxiliary options is important.

" better to set the two options the same
set scrolloff=10 " 
set pumheight=10 " max height of cmp menu

" lsp_signature option
" if set to false, it may still conflict with cmp at middle of window
floating_window_above_cur_line = true

I think there is still some points to improve the floating window experience. Look at the img: 图片

If it is possible to pass a parameter to the offset_x/y function that contains the floating window size (especially height) like this? Then I think the signature help will be perfect!

图片

ray-x commented 1 year ago

I am wondering how you want to pass in the opts? How about this I add a new options

setup{
  ...
  floating_opts=function() return {} end,
  ...
}

So in offset_x you can do this:

offset_x(floating_opts())
yao-weijie commented 1 year ago

setup{ floating_window_off_y = function(opts) ... end }

the opts contains the signature help window size. Actually I'm not sure of the process of generating the help window. If help window size is calculated before offset_y, then you can pass the size to the offset_y function.

ray-x commented 1 year ago

I pushed another change to allow floating_opts been passed to off_x/y. Would you take a look?