Repository: neovim/neovim
File: test/functional/plugin/lsp/utils_spec.lua (Lua)

Code before:
      │{100:local}{101: }{102:foo}│{1:                                          }|
      └─────────┘{1:                                          }|
      {1:~                                                    }|*9
                                                           |
    ]])
    -- This tests the valid winline code path (why doesn't the above?).
    exec_lua([[
      vim.cmd.only()
      vim.lsp.util.open_floating_preview({ 'foo', '```lua', 'local bar', '```' }, 'markdown', {
        border = 'single',
        focus = false,
      })
    ]])
    feed('<C-W>wG')
    screen:expect([[
                                                           |
      ┌─────────┐{1:                                          }|
      │{4:foo      }│{1:                                          }|
      │{100:^local}{101: }{102:bar}│{1:                                          }|
      └─────────┘{1:                                          }|
      {1:~                                                    }|*8
                                                           |
    ]])
    -- Not checking for concealed line on invalid line number #36057.
    command('set scrolloff=3')
    feed('ggvj')
    n.assert_alive()
  end)

  it('open_floating_preview height does not exceed max_height', function()
    local screen = Screen.new()
    exec_lua([[
      vim.lsp.util.open_floating_preview(vim.fn.range(1, 10), 'markdown', {
        border = 'single',
        width = 5,
        max_height = 5,
        focus = false,
      })
    ]])
    screen:expect([[
      ^                                                     |
      ┌─────┐{1:                                              }|
      │{4:1    }│{1:                                              }|
      │{4:2    }│{1:                                              }|
      │{4:3    }│{1:                                              }|
      │{4:4    }│{1:                                              }|
      │{4:5    }│{1:                                              }|
      └─────┘{1:                                              }|
      {1:~                                                    }|*5
                                                           |
    ]])

Review comment (suggestion):

a bit risky for this to live in `test/functional/plugin/lsp/utils_spec.lua` since we have plans to remove much of `lsp.utils`.

not a blocker.

Code after:
      │{100:local}{101: }{102:foo}│{1:                                          }|
      └─────────┘{1:                                          }|
      {1:~                                                    }|*9
                                                           |
    ]])
    -- This tests the valid winline code path (why doesn't the above?).
    exec_lua([[
      vim.cmd.only()
      vim.lsp.util.open_floating_preview({ 'foo', '```lua', 'local bar', '```' }, 'markdown', {
        border = 'single',
        focus = false,
      })
    ]])
    feed('<C-W>wG')
    screen:expect([[
                                                           |
      ┌─────────┐{1:                                          }|
      │{4:foo      }│{1:                                          }|
      │{100:^local}{101: }{102:bar}│{1:                                          }|
      └─────────┘{1:                                          }|
      {1:~                                                    }|*8
                                                           |
    ]])
  end)

  it('open_floating_preview height does not exceed max_height', function()
    local screen = Screen.new()
    exec_lua([[
      vim.lsp.util.open_floating_preview(vim.fn.range(1, 10), 'markdown', {
        border = 'single',
        width = 5,
        max_height = 5,
        focus = false,
      })
    ]])
    screen:expect([[
      ^                                                     |
      ┌─────┐{1:                                              }|
      │{4:1    }│{1:                                              }|
      │{4:2    }│{1:                                              }|
      │{4:3    }│{1:                                              }|
      │{4:4    }│{1:                                              }|
      │{4:5    }│{1:                                              }|
      └─────┘{1:                                              }|
      {1:~                                                    }|*5
                                                           |
    ]])
  end)
end)