Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ _cscope_maps_ comes with following defaults:
-- stack view defaults
stack_view = {
tree_hl = true, -- toggle tree highlighting
size = "default", -- "default" or "large" (large is 95% of screen)
}
}
```
Expand Down
1 change: 1 addition & 0 deletions doc/cscope_maps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ _cscope_maps_ comes with following defaults:
-- stack view defaults
stack_view = {
tree_hl = true, -- toggle tree highlighting
size = "default", -- "default" or "large" (large is 95% of screen)
}
}
<
Expand Down
35 changes: 27 additions & 8 deletions lua/cscope/stack_view/init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
local cs = require("cscope")
local tree = require("cscope.stack_view.tree")
local hl = require("cscope.stack_view.hl")
local log = require("cscope_maps.utils.log")
local utils = require("cscope_maps.utils")
local M = {}

-- Size presets for stack view window
-- width: fraction of screen width (0.85 = 85% of screen width)
-- height: fraction of screen height (0.8 = 80% of screen height)
-- Add more presets here as needed (e.g., "small", "medium")
local size_presets = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move it below opts

default = { width = 0.85, height = 0.8 },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make height=0.7 to match prev config

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we rename default to medium?

we can keep "medium" in default opts

large = { width = 0.95, height = 0.95 },
}

M.opts = {
tree_hl = true, -- toggle tree highlighting
size = "default", -- "default" or "large"
}

-- m()
Expand Down Expand Up @@ -144,14 +155,16 @@ M.set_autocmds = function()
})
end

M.buf_open = function()
M.buf_open = function(width_scale, height_scale)
local vim_height = vim.o.lines
local vim_width = vim.o.columns

local width = math.floor(vim_width * 0.8 / 2 + 3 / 2)
local height = math.floor(vim_height * 0.7)
local col = vim_width * 0.1 - 1
local row = vim_height * 0.15
local w_scale = width_scale
local h_scale = height_scale
local width = math.floor(vim_width * w_scale * 0.5)
local height = math.floor(vim_height * h_scale)
local col = vim_width * (1 - w_scale) * 0.5
local row = vim_height * (1 - h_scale) * 0.5

M.save_last_window()

Expand All @@ -163,7 +176,7 @@ M.buf_open = function()
title_pos = "center",
width = width,
height = height,
col = col + 1 + width,
col = col + width + 1,
row = row,
style = "minimal",
focusable = false,
Expand All @@ -180,7 +193,7 @@ M.buf_open = function()
title_pos = "center",
width = width,
height = height,
col = col - 1,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't remove this. i like the gap :)

col = col,
row = row,
style = "minimal",
focusable = false,
Expand Down Expand Up @@ -236,7 +249,8 @@ M.buf_open_and_update = function()
end

if not M.cache.win_opened then
M.buf_open()
local preset = size_presets[M.opts.size]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access this inside buf_open instead of passing as argument

M.buf_open(preset.width, preset.height)
end

-- print(vim.inspect(root))
Expand Down Expand Up @@ -470,6 +484,11 @@ end

M.setup = function(opts)
M.opts = vim.tbl_deep_extend("force", M.opts, opts)
-- Validate size preset (fall back to "default" if invalid)
if not size_presets[M.opts.size] then
log.warn(string.format('Invalid stack_view size "%s", using "default"', M.opts.size))
M.opts.size = "default"
end
M.set_user_cmd()
end

Expand Down