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

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

Closed
yao-weijie opened this issue Dec 8, 2022 · 6 comments
Closed

Comments

@yao-weijie
Copy link

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.

  • my config:
local function offsety()
    local linenr = vim.api.nvim_win_get_cursor(0)[1] -- buf line number
    local pumheight = vim.o.pumheight -- my default 10
    local winline = vim.fn.winline() -- line number in the window
    local winheight = vim.fn.winheight(0)

    -- window top
    if linenr < pumheight then
        return pumheight
    end

    -- window bottom
    if winheight - winline < pumheight then
        return -pumheight
    end

    return 0
end

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
    图片

  • final effect

    • at window top

图片

  • at window bottom

图片

  • at window middle area

图片

  • requirements
    the window is high enough, and it's better not to split horizontal :)
@ray-x
Copy link
Owner

ray-x commented Dec 15, 2022

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

@ray-x
Copy link
Owner

ray-x commented Dec 15, 2022

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

@ray-x ray-x closed this as completed Dec 20, 2022
@yao-weijie
Copy link
Author

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
Copy link
Owner

ray-x commented Dec 20, 2022

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
Copy link
Author

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
Copy link
Owner

ray-x commented Dec 20, 2022

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

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

No branches or pull requests

2 participants