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

feat: autoresize popup window #60

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*.lua]
charset = utf-8
indent_style = space
indent_size = 2
quote_style = single
trim_trailing_whitespace = true
insert_final_newline = true
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ use {
preview_opts = {
border = 'single'
},
-- Whether the contents of a currently open hover window should be moved
-- to a :h preview-window when pressing the hover keymap.
preview_window = false,
-- What to do if hover() is called when a hover popup is already open:
-- "cycle_providers" - cycle to the next enabled provider
-- "focus" - move the cursor into the popup
-- "preview_window" - move the popup contents to a :h preview-window
-- "close" - close the popup
-- "ignore" - do nothing
multiple_hover = "cycle_providers"
title = true,
mouse_providers = {
'LSP'
Expand Down Expand Up @@ -138,10 +142,10 @@ Call `require('hover').register(<provider>)` with a table containing the followi
- `execute`: function, executes the hover. Has the following arguments:
- `opts`: Additional options:
- `bufnr` (integer)
- `winid` (integer)
- `pos` ({[1]: integer, [2]: integer})
- `relative` (string)
- `done`: callback. First argument should be passed:
- `nil`/`false` if the hover failed to execute. This will allow other lower priority hovers to run.
- `nil` if the hover failed to execute. This will allow other lower priority hovers to run.
- A table with the following fields:
- `lines` (string array)
- `filetype` (string)
Expand All @@ -154,23 +158,29 @@ Call `require('hover').register(<provider>)` with a table containing the followi
```lua
-- Simple
require('hover').register {
name = 'Simple',
--- @param bufnr integer
enabled = function(bufnr)
return true
end,
--- @param opts Hover.Options
--- @param done fun(result: any)
execute = function(opts, done)
done{lines={'TEST'}, filetype="markdown"}
end
name = 'Simple',
--- @param bufnr integer
enabled = function(bufnr)
return true
end,
--- @param opts Hover.Options
--- @param done fun(result?: Hover.Result)
execute = function(opts, done)
done { lines = { 'TEST' }, filetype = 'markdown' }
end
}
```

```lua
--- @class Hover.Options
--- @field bufnr integer
--- @field winid integer
--- (1,0)-based
--- @field pos {[1]: integer, [2]: integer}
--- @field relative? string
--- @field providers? string[]

--- @class Hover.Result
--- @field lines? string[]
--- @field bufnr? integer
--- @field filetype? string
```
15 changes: 7 additions & 8 deletions lua/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ function M.register(provider)
require('hover.providers').register(provider)
end

--- @param opts Hover.Options
--- @param opts? Hover.PartialOptions
function M.hover(opts)
require('hover.actions').hover(opts)
end

--- @param opts Hover.Options
--- @param opts? Hover.PartialOptions
function M.hover_select(opts)
require('hover.actions').hover_select(opts)
end

--- @param direction string, 'previous' | 'next'
--- @param opts Hover.Options
--- @param direction 'previous'|'next'
--- @param opts? Hover.PartialOptions
function M.hover_switch(direction, opts)
require('hover.actions').hover_switch(direction, opts)
end
Expand All @@ -25,12 +25,11 @@ function M.hover_mouse()
require('hover.actions').hover_mouse()
end

--- @param bufnr integer
function M.close(bufnr)
require('hover.actions').close(bufnr)
function M.close()
require('hover.actions').close()
end

---@param user_config Hover.Config
--- @param user_config Hover.Config
function M.setup(user_config)
require('hover.config').set(user_config)
end
Expand Down
Loading