Skip to content
Merged
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
28 changes: 0 additions & 28 deletions lua/overlook/adapter/cursor.lua

This file was deleted.

29 changes: 0 additions & 29 deletions lua/overlook/adapter/definition.lua

This file was deleted.

53 changes: 0 additions & 53 deletions lua/overlook/adapter/marks.lua

This file was deleted.

8 changes: 3 additions & 5 deletions lua/overlook/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
---
---@tag overlook-api

local Peek = require("overlook.peek")
local Window = require("overlook.window")

local M = {}
Expand All @@ -36,7 +35,7 @@ local M = {}
---@tag overlook-api.peek_definition
---@toc_entry
M.peek_definition = function()
Peek.definition()
require("overlook.peek.definition")()
end

--- Switch focus between the top popup and the root window.
Expand Down Expand Up @@ -66,7 +65,7 @@ end
---@tag overlook-api.peek_cursor
---@toc_entry
M.peek_cursor = function()
Peek.cursor()
require("overlook.peek.cursor")()
end

--- Peek at a specific mark location.
Expand All @@ -83,14 +82,13 @@ end
---@tag overlook-api.peek_mark
---@toc_entry
M.peek_mark = function()
Peek.marks()
vim.ui.input({ prompt = "Overlook Mark:" }, function(input)
if input == nil or input == "" then
return
end

if #input == 1 then
Peek.marks(input)
require("overlook.peek.marks")(input)
else
vim.notify("Overlook Error: Invalid mark. Please enter a single character.", vim.log.levels.ERROR)
end
Expand Down
19 changes: 1 addition & 18 deletions lua/overlook/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,11 @@ local M = {}
---@field size_ratio number Default size ratio (0.0 to 1.0) used to calculate initial size.
---@field keys? table<string, string> Keymaps specific to the popup UI.

--- *OverlookAdapterOptions*
---
---@class OverlookAdapterOptions
---
---@field marks? table Configuration for the 'marks' adapter.
-- ---@field lsp? table Placeholder for future LSP adapter config

--- *OverlookOptions*
---
---@class OverlookOptions
---
---@field ui OverlookOptions.UI UI settings for the popup windows.
---@field adapters OverlookAdapterOptions Adapter-specific configurations.
---@field on_stack_empty? fun() Optional function called when the last Overlook popup closes.

--- Default configuration options for overlook.nvim.
Expand Down Expand Up @@ -132,15 +124,6 @@ local defaults = {
},
},

-- Adapter-specific configurations
adapters = {
-- check `overlook.adapter.cursor` for implementation details
your_custom_adapter = {
---@return OverlookPopupOptions? @Table suitable for Window:open_popup, or nil on error.
get = function() end,
},
},

-- Optional hook called when the last Overlook popup closes
on_stack_empty = nil,
}
Expand All @@ -154,7 +137,7 @@ local options = vim.deepcopy(defaults)
---@param user_opts? table User configuration options. Can contain any subset of OverlookOptions fields.
function M.setup(user_opts)
if user_opts then
-- Use deep_extend to merge nested tables like 'ui' and 'adapters'.
-- Use deep_extend to merge nested tables like 'ui'.
-- 'force' mode replaces arrays entirely if present, usually desired for config.
options = vim.tbl_deep_extend("force", options, user_opts or {})
end
Expand Down
72 changes: 0 additions & 72 deletions lua/overlook/peek.lua

This file was deleted.

21 changes: 21 additions & 0 deletions lua/overlook/peek/cursor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- Peek at the current cursor position: opens a popup of the current buffer
--- anchored at the cursor. A peek source is just a function that builds
--- OverlookPopupOptions and hands them to the window layer.
---@return nil
return function()
local file_path = vim.api.nvim_buf_get_name(0)
if file_path == "" then
vim.notify("Overlook: Cannot peek in unnamed buffer.", vim.log.levels.WARN)
return
end

---@diagnostic disable-next-line: unused-local
local _bufnum, lnum, col, _off = unpack(vim.fn.getpos("."))

require("overlook.window").open_popup {
title = vim.fn.fnamemodify(file_path, ":~:."),
target_bufnr = vim.api.nvim_get_current_buf(),
lnum = lnum,
col = col,
}
end
32 changes: 32 additions & 0 deletions lua/overlook/peek/definition.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--- Peek at the LSP definition under the cursor. Asynchronous: the popup opens
--- from the LSP on_list callback once the server responds. Guards the common
--- "no definition" / malformed-result cases and simply does not open a popup
--- in those cases.
---@param location_opts? vim.lsp.LocationOpts
---@return nil
return function(location_opts)
location_opts = location_opts or {}

vim.lsp.buf.definition {
on_list = function(tt)
local item = tt and tt.items and tt.items[1]
if not item then
vim.notify("Overlook: No definition found.", vim.log.levels.INFO)
return
end

local uri = item.user_data and (item.user_data.targetUri or item.user_data.uri)
if not uri then
vim.notify("Overlook: No URI found in LSP definition item.", vim.log.levels.WARN)
return
end

require("overlook.window").open_popup {
target_bufnr = vim.uri_to_bufnr(uri),
lnum = item.lnum,
col = item.col,
title = item.filename,
}
end,
}
end
42 changes: 42 additions & 0 deletions lua/overlook/peek/marks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local api = vim.api

--- Peek at a mark's location. Validates the mark, then opens a popup of its
--- buffer at the mark position. Notifies and returns early on any invalid /
--- unset / unloaded case (it never opens a popup in those cases).
---@param mark_char string Single-character mark name.
---@return nil
return function(mark_char)
if not mark_char or #mark_char ~= 1 then
vim.notify("Overlook Error: Invalid mark character provided.", vim.log.levels.ERROR)
return
end

local pos = vim.fn.getpos("'" .. mark_char)
local bufnum = pos[1]
local lnum = pos[2]
local col = pos[3]

if bufnum == 0 or lnum == 0 then
vim.notify("Overlook: Mark '" .. mark_char .. "' is not set.", vim.log.levels.INFO)
return
end

if not api.nvim_buf_is_loaded(bufnum) then
vim.notify("Overlook Info: Buffer for mark '" .. mark_char .. "' is not loaded.", vim.log.levels.INFO)
return
end
if not api.nvim_buf_is_valid(bufnum) then
vim.notify(
"Overlook Error: Buffer for mark '" .. mark_char .. "' (" .. bufnum .. ") is invalid.",
vim.log.levels.ERROR
)
return
end

require("overlook.window").open_popup {
target_bufnr = bufnum,
lnum = lnum,
col = col,
title = vim.fn.fnamemodify(api.nvim_buf_get_name(bufnum), ":~:."),
}
end
2 changes: 1 addition & 1 deletion lua/overlook/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function Popup:snapshot_state()
self.opts.target_bufnr = api.nvim_win_get_buf(self.winid)
local cursor = api.nvim_win_get_cursor(self.winid)
self.opts.lnum = cursor[1]
-- opts.col is 1-indexed (the adapters use vim.fn.getpos which returns
-- opts.col is 1-indexed (the peek sources use vim.fn.getpos which returns
-- 1-indexed); nvim_win_get_cursor returns 0-indexed. Convert.
-- set_cursor_position converts back via math.max(0, col - 1) on restore.
self.opts.col = cursor[2] + 1
Expand Down
9 changes: 9 additions & 0 deletions lua/overlook/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
---@field lnum integer The line number to position the popup.
---@field col integer The column number to position the popup.
---@field title? string Optional title for the popup.

--- A peek source is just a function. It gathers some context (the cursor, a
--- mark, an LSP result, ...), builds OverlookPopupOptions, and hands them to
--- `require("overlook.window").open_popup(opts)`. It opens nothing (and
--- typically notifies) when there is nothing to peek. Async sources (e.g.
--- vim.lsp.buf.*) simply call open_popup later from their own callback. The
--- built-in sources live under `overlook.peek.*`; a custom source is any
--- function following the same shape, bound to a key.
---@alias OverlookPeekSource fun(...): nil
Loading
Loading