Now I have a complete picture. Let me analyze the workspace_enhancer module's design and implementation:
Analysis of workspace_enhancer Module
Design Philosophy
The workspace_enhancer module follows a declarative, configuration-driven approach. It's designed to:
- Dynamically discover plugin directories from lazy.nvim and packer
- Aggregate runtime paths from Neovim's runtimepath
- Provide enhanced configuration for lua_ls with workspace library, completion, and diagnostics
- Apply configuration via
vim.lsp.config() API
Implementation Quality
Strengths:
- Dynamic discovery: Uses
vim.fn.glob() to find plugins at runtime
- Comprehensive coverage: Covers both lazy.nvim and packer (legacy support)
- Modular design: Separate functions for plugins, runtime, config, completion, diagnostics
- Sensible defaults: Includes common ignore patterns and reasonable limits
Weaknesses:
- No caching: Scans directories on every call (could be expensive)
- No filtering: Includes ALL plugins, even those not relevant to current project
- No workspace awareness: Doesn't differentiate between project-specific vs global plugins
- No incremental updates: Can't add/remove paths dynamically
Dependencies
The module depends on:
Neovim APIs:
vim.fn.stdpath("data") - Plugin directory location
vim.fn.glob() - File pattern matching
vim.fn.isdirectory() - Directory validation
vim.opt.runtimepath:get() - Runtime paths
vim.lsp.config() - LSP configuration API
vim.notify() - User notifications
Neovim runtime:
vim.list_extend() - Table concatenation
vim.tbl_deep_extend() - Table merging (not currently used)
Interaction Points
Current Interactions (None - Commented Out):
lua/lsp/completions.lua - Lines 5, 10 (commented out)
- Would call
workspace_enhancer.apply_enhanced_config()
Potential Integration Points:
- lua_ls configuration (
lsp/lua_ls.lua) - Could be called in on_init or settings
- LSP initialization (
lua/lsp/init.lua) - Could be called after VimEnter
- TypeScript workspace (
lua/config/typescript_workspace.lua) - Similar pattern
- Code suggestions (
lua/code_suggestions/index/) - Could provide context
Design Comparison with TypeScript Workspace
| Aspect |
workspace_enhancer |
typescript_workspace |
| Scope |
Global (all plugins) |
Project-specific (monorepo) |
| Management |
Static config |
Dynamic add/remove |
| Integration |
One-time apply |
Event-driven (LspAttach) |
| User Commands |
None |
TswAdd, TswRemove, TswList, TswInit |
| Auto-init |
No |
Yes (LspAttach) |
Issues and Improvements
Critical Issues:
- Not being used - The module is completely disabled
- No caching - Scans directories on every call
- No workspace awareness - Includes all plugins regardless of project
- No incremental updates - Can't adjust paths dynamically
Design Flaws:
- Over-inclusive: Adds ALL plugin directories to workspace, which can cause:
- Slow lua_ls startup
- Excessive memory usage
- Conflicting completions from unrelated plugins
- No project filtering: Doesn't respect project boundaries
- No performance optimization: No memoization or lazy loading
Recommended Improvements:
- Enable the module - Uncomment in
lua/lsp/completions.lua
- Add caching - Memoize plugin directory scanning
- Add project awareness - Only include plugins relevant to current project
- Add incremental updates - Support dynamic path addition/removal
- Add user commands - Similar to TypeScript workspace management
- Add auto-initialization - Trigger on LspAttach for lua_ls
Comparison with TypeScript Workspace Pattern
The typescript_workspace.lua module provides a better pattern:
- Event-driven: Auto-initializes on
LspAttach
- Dynamic management: Add/remove workspace folders
- Project-aware: Reads
package.json workspaces
- User commands: Provides
Tsw* commands
The workspace_enhancer should follow a similar pattern for Lua projects.
Recommendation
The workspace_enhancer module has a solid design foundation but needs:
- Activation - Uncomment and integrate
- Caching - Add memoization
- Project awareness - Filter plugins by project
- Dynamic management - Add/remove paths
- User commands - Provide
Lsw* commands
Would you like me to create an improved version that addresses these issues?