feat: implement mode_manager plugin with enhanced state management
Signed-off-by: juliano.barbosa <julianomb@gmail.com>
This commit is contained in:
		
							parent
							
								
									f8b3501df1
								
							
						
					
					
						commit
						94cd09806e
					
				
							
								
								
									
										2
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										2
									
								
								init.lua
								
								
								
								
							| 
						 | 
					@ -1266,7 +1266,7 @@ end
 | 
				
			||||||
  --    This is the easiest way to modularize your config.
 | 
					  --    This is the easiest way to modularize your config.
 | 
				
			||||||
  --
 | 
					  --
 | 
				
			||||||
  --  Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
 | 
					  --  Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
 | 
				
			||||||
  { import = 'custom.plugins' },
 | 
					  { import = 'custom.plugins' }
 | 
				
			||||||
  --
 | 
					  --
 | 
				
			||||||
  -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
 | 
					  -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
 | 
				
			||||||
  -- Or use telescope!
 | 
					  -- Or use telescope!
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,4 +7,14 @@ return {
 | 
				
			||||||
  { 'folke/trouble.nvim', event = 'VimEnter', dependencies = { 'nvim-tree/nvim-web-devicons' }, config = function()
 | 
					  { 'folke/trouble.nvim', event = 'VimEnter', dependencies = { 'nvim-tree/nvim-web-devicons' }, config = function()
 | 
				
			||||||
    require('trouble').setup {}
 | 
					    require('trouble').setup {}
 | 
				
			||||||
  end },
 | 
					  end },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  -- Mode Manager Plugin (local)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    dir = vim.fn.stdpath('config') .. '/lua/custom/plugins/mode_manager',
 | 
				
			||||||
 | 
					    name = 'mode_manager',
 | 
				
			||||||
 | 
					    event = 'VimEnter',
 | 
				
			||||||
 | 
					    config = function()
 | 
				
			||||||
 | 
					      require('custom.plugins.mode_manager').setup()
 | 
				
			||||||
 | 
					    end,
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,15 +94,12 @@ end
 | 
				
			||||||
local function restore_context(mode)
 | 
					local function restore_context(mode)
 | 
				
			||||||
  local ctx = M.state.contexts[mode]
 | 
					  local ctx = M.state.contexts[mode]
 | 
				
			||||||
  if ctx then
 | 
					  if ctx then
 | 
				
			||||||
    -- Restore window view
 | 
					 | 
				
			||||||
    if ctx.window then
 | 
					    if ctx.window then
 | 
				
			||||||
      vim.fn.winrestview(ctx.window)
 | 
					      vim.fn.winrestview(ctx.window)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    -- Restore cursor position
 | 
					 | 
				
			||||||
    if ctx.cursor then
 | 
					    if ctx.cursor then
 | 
				
			||||||
      vim.api.nvim_win_set_cursor(0, ctx.cursor)
 | 
					      vim.api.nvim_win_set_cursor(0, ctx.cursor)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    -- Restore folding
 | 
					 | 
				
			||||||
    if ctx.folding then
 | 
					    if ctx.folding then
 | 
				
			||||||
      vim.wo.foldenable = true
 | 
					      vim.wo.foldenable = true
 | 
				
			||||||
      vim.wo.foldmethod = ctx.folding
 | 
					      vim.wo.foldmethod = ctx.folding
 | 
				
			||||||
| 
						 | 
					@ -207,7 +204,7 @@ function M.save_state()
 | 
				
			||||||
      settings = M.state.settings,
 | 
					      settings = M.state.settings,
 | 
				
			||||||
      contexts = M.state.contexts,
 | 
					      contexts = M.state.contexts,
 | 
				
			||||||
      last_updated = os.time(),
 | 
					      last_updated = os.time(),
 | 
				
			||||||
      version = '1.0' -- Added versioning
 | 
					      version = '1.0'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    file:write(vim.fn.json_encode(persist_state))
 | 
					    file:write(vim.fn.json_encode(persist_state))
 | 
				
			||||||
    file:close()
 | 
					    file:close()
 | 
				
			||||||
| 
						 | 
					@ -224,13 +221,11 @@ function M.load_state()
 | 
				
			||||||
    if content and content ~= '' then
 | 
					    if content and content ~= '' then
 | 
				
			||||||
      local decoded = vim.fn.json_decode(content)
 | 
					      local decoded = vim.fn.json_decode(content)
 | 
				
			||||||
      if decoded then
 | 
					      if decoded then
 | 
				
			||||||
        -- Restore state with validation
 | 
					 | 
				
			||||||
        if decoded.version == '1.0' then
 | 
					        if decoded.version == '1.0' then
 | 
				
			||||||
          M.state.current_mode = decoded.current_mode
 | 
					          M.state.current_mode = decoded.current_mode
 | 
				
			||||||
          M.state.settings = decoded.settings or {act = {}, plan = {}}
 | 
					          M.state.settings = decoded.settings or {act = {}, plan = {}}
 | 
				
			||||||
          M.state.contexts = decoded.contexts or {act = {}, plan = {}}
 | 
					          M.state.contexts = decoded.contexts or {act = {}, plan = {}}
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          -- Handle older versions or invalid state
 | 
					 | 
				
			||||||
          M.state.current_mode = decoded.current_mode or 'act'
 | 
					          M.state.current_mode = decoded.current_mode or 'act'
 | 
				
			||||||
          M.state.settings = {act = {}, plan = {}}
 | 
					          M.state.settings = {act = {}, plan = {}}
 | 
				
			||||||
          M.state.contexts = {act = {}, plan = {}}
 | 
					          M.state.contexts = {act = {}, plan = {}}
 | 
				
			||||||
| 
						 | 
					@ -250,6 +245,16 @@ function M.load_state()
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Get mode history
 | 
				
			||||||
 | 
					function M.get_history()
 | 
				
			||||||
 | 
					  return M.state.history
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Clear mode history
 | 
				
			||||||
 | 
					function M.clear_history()
 | 
				
			||||||
 | 
					  M.state.history = {}
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Initialize the plugin
 | 
					-- Initialize the plugin
 | 
				
			||||||
function M.setup()
 | 
					function M.setup()
 | 
				
			||||||
  -- Load saved state
 | 
					  -- Load saved state
 | 
				
			||||||
| 
						 | 
					@ -272,14 +277,4 @@ function M.setup()
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Get mode history
 | 
					 | 
				
			||||||
function M.get_history()
 | 
					 | 
				
			||||||
  return M.state.history
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
-- Clear mode history
 | 
					 | 
				
			||||||
function M.clear_history()
 | 
					 | 
				
			||||||
  M.state.history = {}
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
return M
 | 
					return M
 | 
				
			||||||
| 
						 | 
					@ -1,27 +1,32 @@
 | 
				
			||||||
# Current Session Context
 | 
					# Current Session Context
 | 
				
			||||||
*Last Updated: 2025-02-17 21:57*
 | 
					*Last Updated: 2025-02-18 18:31*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Current State
 | 
					## Current State
 | 
				
			||||||
- Rolled back to v0.1.0 tag (commit 57f551e)
 | 
					- Working on mode_manager plugin integration
 | 
				
			||||||
- Backup branch created for pre-rollback state
 | 
					- Focusing on proper plugin specification and initialization
 | 
				
			||||||
 | 
					- Implementing enhanced mode state management system
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Recent Changes
 | 
					## Recent Changes
 | 
				
			||||||
- Created backup branch of pre-rollback state
 | 
					- Created backup branch of pre-rollback state
 | 
				
			||||||
- Rolled back codebase to v0.1.0 tag
 | 
					- Rolled back codebase to v0.1.0 tag
 | 
				
			||||||
- Previous state preserved in backup branch
 | 
					- Previous state preserved in backup branch
 | 
				
			||||||
 | 
					- Started mode_manager plugin implementation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Active Decisions
 | 
					## Active Decisions
 | 
				
			||||||
1. Using Memory Bank for configuration documentation
 | 
					1. Using Memory Bank for configuration documentation
 | 
				
			||||||
2. Following Kickstart.nvim's modular approach
 | 
					2. Following Kickstart.nvim's modular approach
 | 
				
			||||||
3. Implementing comprehensive LSP integration
 | 
					3. Implementing comprehensive LSP integration
 | 
				
			||||||
4. Using mode-based workflow with persistent Plan/Act toggle
 | 
					4. Using mode-based workflow with persistent Plan/Act toggle
 | 
				
			||||||
 | 
					5. Implementing enhanced mode state management system
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Current Focus
 | 
					## Current Focus
 | 
				
			||||||
- Verifying system stability after rollback
 | 
					- Implementing mode_manager plugin properly
 | 
				
			||||||
- Ensuring core functionality remains intact
 | 
					- Resolving plugin specification issues
 | 
				
			||||||
- Planning next steps based on v0.1.0 state
 | 
					- Setting up proper initialization hooks
 | 
				
			||||||
 | 
					- Integrating with custom_statusline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Open Questions
 | 
					## Open Questions
 | 
				
			||||||
- What were the key changes between v0.1.0 and the rolled back state?
 | 
					- What were the key changes between v0.1.0 and the rolled back state?
 | 
				
			||||||
- Which features need to be reimplemented or reconsidered?
 | 
					- Which features need to be reimplemented or reconsidered?
 | 
				
			||||||
- How to prevent future need for rollbacks?
 | 
					- How to prevent future need for rollbacks?
 | 
				
			||||||
 | 
					- How to best structure the mode_manager plugin initialization?
 | 
				
			||||||
| 
						 | 
					@ -1,63 +1,41 @@
 | 
				
			||||||
# Project Progress
 | 
					# Progress Update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Completed Work
 | 
					## Current Status
 | 
				
			||||||
- Initial Memory Bank setup
 | 
					Working on mode_manager plugin implementation with enhanced state management.
 | 
				
			||||||
- Basic Plan/Act mode system implementation
 | 
					 | 
				
			||||||
- Mode persistence with JSON storage
 | 
					 | 
				
			||||||
- Simple event callback system
 | 
					 | 
				
			||||||
- Status line integration
 | 
					 | 
				
			||||||
- Basic mode toggling (`<leader>tm`)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Recent Changes
 | 
					## Completed Tasks
 | 
				
			||||||
- Rolled back to v0.1.0 (commit 57f551e)
 | 
					1. System rollback to v0.1.0
 | 
				
			||||||
- Created backup branch of pre-rollback state
 | 
					   - Created backup branch
 | 
				
			||||||
 | 
					   - Successfully rolled back to stable version
 | 
				
			||||||
 | 
					   - Preserved previous state
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2. Architecture Planning
 | 
				
			||||||
 | 
					   - Defined enhanced mode state management system
 | 
				
			||||||
 | 
					   - Documented implementation phases
 | 
				
			||||||
 | 
					   - Established integration patterns
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## In Progress
 | 
					## In Progress
 | 
				
			||||||
- Verifying system stability post-rollback
 | 
					1. Mode Manager Plugin Implementation:
 | 
				
			||||||
- Reassessing implementation priorities
 | 
					   - Converting mode_manager.lua into proper plugin structure
 | 
				
			||||||
- Evaluating core functionality
 | 
					   - Setting up initialization hooks
 | 
				
			||||||
 | 
					   - Implementing state persistence layer
 | 
				
			||||||
 | 
					   - Adding event system foundations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2. Integration Work:
 | 
				
			||||||
 | 
					   - Configuring plugin specification in init.lua
 | 
				
			||||||
 | 
					   - Setting up custom_statusline integration
 | 
				
			||||||
 | 
					   - Implementing mode-aware functionality
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Next Steps
 | 
					## Next Steps
 | 
				
			||||||
 | 
					1. Complete core state management implementation
 | 
				
			||||||
 | 
					2. Add event system with hooks and queuing
 | 
				
			||||||
 | 
					3. Implement persistence layer with versioning
 | 
				
			||||||
 | 
					4. Set up plugin and UI integration components
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Phase 1: Post-Rollback Stabilization
 | 
					## Technical Requirements
 | 
				
			||||||
- [ ] Verify core functionality
 | 
					- Proper plugin specification format
 | 
				
			||||||
- [ ] Document differences from rolled back state
 | 
					- Local plugin integration
 | 
				
			||||||
- [ ] Reassess implementation priorities
 | 
					- Correct module initialization
 | 
				
			||||||
- [ ] Review backup branch for salvageable improvements
 | 
					- State persistence mechanisms
 | 
				
			||||||
 | 
					- Event handling system
 | 
				
			||||||
### Phase 2: Core State Management
 | 
					- Integration interfaces
 | 
				
			||||||
- [ ] Implement mode-specific settings store
 | 
					 | 
				
			||||||
- [ ] Add mode context preservation
 | 
					 | 
				
			||||||
- [ ] Create mode initialization hooks
 | 
					 | 
				
			||||||
- [ ] Add state validation system
 | 
					 | 
				
			||||||
- [ ] Implement error recovery mechanisms
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### Phase 3: Event System Enhancement
 | 
					 | 
				
			||||||
- [ ] Add pre-mode-change hooks
 | 
					 | 
				
			||||||
- [ ] Implement post-mode-change hooks
 | 
					 | 
				
			||||||
- [ ] Create event queueing system
 | 
					 | 
				
			||||||
- [ ] Add mode-specific event handlers
 | 
					 | 
				
			||||||
- [ ] Implement async event processing
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### Phase 4: Integration Features
 | 
					 | 
				
			||||||
- [ ] Add mode-specific colorschemes
 | 
					 | 
				
			||||||
- [ ] Implement mode-specific keymaps
 | 
					 | 
				
			||||||
- [ ] Create mode-specific status line content
 | 
					 | 
				
			||||||
- [ ] Add mode-specific buffer handling
 | 
					 | 
				
			||||||
- [ ] Implement window layout persistence
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Known Issues
 | 
					 | 
				
			||||||
- Current state persistence is basic
 | 
					 | 
				
			||||||
- No validation of stored state
 | 
					 | 
				
			||||||
- Limited error recovery options
 | 
					 | 
				
			||||||
- No mode-specific settings
 | 
					 | 
				
			||||||
- Basic event handling system
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Future Considerations
 | 
					 | 
				
			||||||
- Custom mode creation system
 | 
					 | 
				
			||||||
- Mode-specific plugin configurations
 | 
					 | 
				
			||||||
- Advanced state synchronization
 | 
					 | 
				
			||||||
- Mode templates and presets
 | 
					 | 
				
			||||||
- Mode groups
 | 
					 | 
				
			||||||
- Mode transitions animations
 | 
					 | 
				
			||||||
- Mode-specific help system
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue