Skip to content

fix(hover): incorrect doc positions#1123

Open
cameronr wants to merge 4 commits intofolke:mainfrom
cameronr:lsp-doc-position
Open

fix(hover): incorrect doc positions#1123
cameronr wants to merge 4 commits intofolke:mainfrom
cameronr:lsp-doc-position

Conversation

@cameronr
Copy link
Copy Markdown

@cameronr cameronr commented Jul 7, 2025

Description

The code to layout the lsp hover window was not handling a number of edge cases (anchoring E without a border, anchoring S and/or E with a border, and when hover window is too large to fit). These are all fixed and all combinations of position, padding, and border are handled correctly (afaik).

To fix all of these cases, we calculate position correctly, accounting for border and padding, and then set the maximum size accordingly.

Here are a bunch of screenshots to show the fixed layout:

No border:

  1. below the cursor (anchoring NE)
Screenshot 2025-07-08 at 13 54 55 2. above the cursor (anchoring SE) Screenshot 2025-07-08 at 13 55 04 3. anchoring NW Screenshot 2025-07-08 at 13 55 16 4. anchoring SW Screenshot 2025-07-08 at 13 55 27

Border:

  1. NE
Screenshot 2025-07-08 at 13 55 40 2. SE Screenshot 2025-07-08 at 13 55 56 3. NW Screenshot 2025-07-08 at 13 56 08 4.SW Screenshot 2025-07-08 at 14 06 17

Overlapping other windows:
Screenshot 2025-07-08 at 13 56 35

Resizing (so window doesn't get pushed onto cursor line, last line is statusline):
Screenshot 2025-07-08 at 14 18 30

Resizing with small window:
Screenshot 2025-07-08 at 14 23 19
Screenshot 2025-07-08 at 14 23 15

Unusual position, padding with border and large max_height:

      lsp = {
        hover = {
          opts = {
            size = {
              max_height = 30,
            },
            position = { row = 5, col = 4 },
            border = {
              style = 'rounded',
              padding = { 2, 4 },
            },
          },
        },
      },
  1. NE
Screenshot 2025-07-08 at 14 01 29 2. SE Screenshot 2025-07-08 at 14 01 38 3. NW Screenshot 2025-07-08 at 14 01 44 4. SW Screenshot 2025-07-08 at 14 01 56

Related Issue(s)

Fixes #1122

Screenshots

cameronr added 2 commits July 6, 2025 18:06
The border was not being factored in when deciding how to anchor the
signature window, causing it to sometimes overlap the current line.

Similarly, the border was not being considered when drawing the
signature window above teh current line, causing it to be offset two
lines away from the current line.
Previous fix for folke#1122 didn't handle the case where the hover window was
still larger than the available space to display it. This fixes that
case as well as correctly aligns hover when displaying to the left.

Also use vim.go.lines instead of vim.fn.winheight to allow popups to
overlap other windows. That seems like a better choice since it's a
momentary popup vs making the popup potentially very small
@cameronr cameronr changed the title fix(hover): incorrect position with border. Fixes #1122 fix(hover): incorrect doc positions. Fixes #1122 Jul 8, 2025
cameronr added 2 commits July 8, 2025 14:20
I think I finally have position, padding, and border figured out.

position is where you want the content to start, i.e. where the doc
content begins

borders and padding are drawn "before" that position (where what before
means depends on anchoring)

The code should now handle all position, padding, border combinations
Also remove debug notifs
@whymidnight
Copy link
Copy Markdown

whymidnight commented Aug 6, 2025

<3 for relieving my headaches. until this gets merged - packer:

  use({
  "cameronr/noice.nvim",
  branch = "lsp-doc-position",
  requires = {
    "MunifTanjim/nui.nvim",
    "rcarriga/nvim-notify",
    }
  })

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 6, 2025

This PR is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the stale This issue or PR has been inactive for a while label Sep 6, 2025
@DrKJeff16
Copy link
Copy Markdown

DrKJeff16 commented Sep 13, 2025

PR Labeler bot will ask you to rename this PR to something like:

fix: incorrect doc positions

@cameronr cameronr changed the title fix(hover): incorrect doc positions. Fixes #1122 fix: incorrect doc positions Sep 13, 2025
@cameronr cameronr changed the title fix: incorrect doc positions fix(hover): incorrect doc positions Sep 13, 2025
@github-actions github-actions bot removed the stale This issue or PR has been inactive for a while label Sep 14, 2025
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

Successfully merging this pull request may close these issues.

bug: lsp doc hover incorrectly positioned

3 participants