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
27 changes: 17 additions & 10 deletions lua/tabi/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,23 @@ function M.get_or_create_default()
return session
end

return M.create(nil)
or {
id = DEFAULT_SESSION_ID,
name = "default",
created_at = utils.timestamp(),
updated_at = utils.timestamp(),
branch = utils.get_git_branch(),
tag = nil,
notes = {},
}
-- Create default session with fixed ID and name
local default_session = {
id = DEFAULT_SESSION_ID,
name = "default",
created_at = utils.timestamp(),
updated_at = utils.timestamp(),
branch = utils.get_git_branch(),
tag = nil,
notes = {},
}

local backend = storage.get_backend()
if backend and backend.save_session then
backend.save_session(default_session)
end

return default_session
end

--- List all sessions
Expand Down
74 changes: 28 additions & 46 deletions plugin/tabi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ display.init()
-- Command implementations
local commands = {}

--- Get the appropriate session for note operations
--- Considers retrace mode, current session, and creates default if needed
---@return SessionData
local function get_session_for_note_operation()
local session

-- If in retrace mode, use the retrace session
if retrace.is_active() then
local retrace_state = retrace.get_state()
if retrace_state then
session = retrace_state.session
end
elseif tabi.state.current_session then
session = session_module.load(tabi.state.current_session)
end

if not session then
session = session_module.get_or_create_default()
tabi.state.current_session = session.id
display.setup_autocmds(session)
end

return session
end

--- Start a new session
function commands.start_session(args)
local session_name = args[2]
Expand Down Expand Up @@ -106,22 +131,7 @@ function commands.note(args, range_start, range_end)
end

-- Get or create session
local session
-- If in retrace mode, use the retrace session
if retrace.is_active() then
local retrace_state = retrace.get_state()
if retrace_state then
session = retrace_state.session
end
elseif tabi.state.current_session then
session = session_module.load(tabi.state.current_session)
end

if not session then
session = session_module.get_or_create_default()
tabi.state.current_session = session.id
display.setup_autocmds(session)
end
local session = get_session_for_note_operation()

-- Check if note already exists at this line
local existing_note = session_module.get_note_at_line(session, file_path, line)
Expand Down Expand Up @@ -161,19 +171,7 @@ function commands.note_edit()
local cursor = vim.api.nvim_win_get_cursor(0)
local line = cursor[1]

local session
-- If in retrace mode, use the retrace session
if retrace.is_active() then
local retrace_state = retrace.get_state()
if retrace_state then
session = retrace_state.session
end
elseif tabi.state.current_session then
session = session_module.load(tabi.state.current_session)
else
session = session_module.get_or_create_default()
tabi.state.current_session = session.id
end
local session = get_session_for_note_operation()

local note = session_module.get_note_at_line(session, file_path, line)
if not note then
Expand Down Expand Up @@ -205,23 +203,7 @@ function commands.note_delete()
local cursor = vim.api.nvim_win_get_cursor(0)
local line = cursor[1]

local session
-- If in retrace mode, use the retrace session
if retrace.is_active() then
local retrace_state = retrace.get_state()
if retrace_state then
session = retrace_state.session
end
elseif tabi.state.current_session then
session = session_module.load(tabi.state.current_session)
else
session = session_module.load("default")
end

if not session then
vim.notify("Tabi: No session found", vim.log.levels.WARN)
return
end
local session = get_session_for_note_operation()

local note = session_module.get_note_at_line(session, file_path, line)
if not note then
Expand Down