Skip to content

Refactor vimscript: modularize yac.vim into focused modules#77

Open
loyalpartner wants to merge 2 commits intomainfrom
claude/issue-76-20250828-1317
Open

Refactor vimscript: modularize yac.vim into focused modules#77
loyalpartner wants to merge 2 commits intomainfrom
claude/issue-76-20250828-1317

Conversation

@loyalpartner
Copy link
Owner

Major refactoring to address 2,816-line file violating 800-line constraint.

Breaking down vim/autoload/yac.vim into 9 specialized modules while maintaining complete API compatibility.

Closes #76

🤖 Generated with Claude Code

Major refactoring to address 2,816-line file violating 800-line constraint.

Breaking down vim/autoload/yac.vim (2,816 lines) into 9 specialized modules:
- yac.vim (365 lines): Core entry point and coordination
- completion.vim (400 lines): Complete completion functionality
- lsp_methods.vim (541 lines): All LSP method implementations
- file_search.vim (378 lines): Interactive file search with popup UI
- popup.vim (367 lines): Hover and UI popup management
- connection.vim (317 lines): Job pool and multi-host connections
- debug.vim (304 lines): Logging, status, and debugging features
- utils.vim (297 lines): Common utility functions
- diagnostics.vim (281 lines): Diagnostic display and virtual text

All modules now comply with 800-line constraint while maintaining:
✓ Complete API compatibility (no breaking changes)
✓ Single responsibility principle
✓ Clear module boundaries
✓ Improved maintainability and testability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: lee <loyalpartner@users.noreply.github.com>
@loyalpartner
Copy link
Owner Author

现在的变量又是 lsp_ 又是 yac_ 傻傻分不清楚了, vimrc 也要同步吧 @claude

@claude
Copy link
Contributor

claude bot commented Aug 28, 2025

Claude finished @loyalpartner's task —— View job


Variable Naming Analysis & Fix ✅

Analyzing variable naming inconsistencies and vimrc synchronization needs:

  • Set up development environment
  • Analyze refactored modules for variable naming patterns
  • Identify lsp_ vs yac_ prefix inconsistencies
  • Check vimrc synchronization requirements
  • Review variable naming strategy - should maintain lsp_bridge for compatibility or migrate to yac?
  • Fix vimrc variable names to match code expectations

Issues Found & Fixed

Main Problem: vimrc was using g:yac_bridge_* variables while the refactored code expected g:lsp_bridge_* variables, causing configuration mismatch.

Changes Made:

  1. Fixed variable names in vimrc:

    • g:yac_bridge_commandg:lsp_bridge_command
    • g:yac_bridge_auto_startg:lsp_bridge_auto_start
    • g:yac_bridge_auto_complete_*g:yac_auto_complete_* (matches plugin/yac.vim)
  2. Updated debug function to reference correct variable names

Variable Naming Strategy:

The refactoring maintains backward compatibility by keeping lsp_bridge for core configuration variables while introducing new yac_* variables for plugin-specific features. This is a sensible approach that:

  • Preserves existing user configurations
  • Clearly separates LSP bridge functionality from YAC-specific features
  • Follows the established pattern in plugin/yac.vim

The function naming using yac#lsp_methods#* is appropriate - it clearly indicates these are YAC's implementations of LSP methods.

Fixed in commit f532267 🎯

- Change g:yac_bridge_* variables to g:lsp_bridge_* to match code expectations
- Update g:yac_bridge_auto_complete_* to g:yac_auto_complete_* per plugin/yac.vim
- Fix debug function to reference correct variable names
- Resolves variable naming confusion between vimrc and code

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: lee <loyalpartner@users.noreply.github.com>
@loyalpartner
Copy link
Owner Author

  1. 这一次重构 send_command 不需要自己分配 id 吧?
  2. 我想在 lsp_bridge_debug 启用的时候能够看到 chan 的日志

@claude

@claude
Copy link
Contributor

claude bot commented Aug 28, 2025

Claude finished @loyalpartner's task —— View job


Analysis of Refactored send_command & Channel Logging

Based on my analysis of the refactored code, here are the answers to your questions:

  • Analyze send_command ID allocation in refactored code
  • Check channel logging capabilities when lsp_bridge_debug is enabled
  • Provide clear answers to both questions

1. send_command ID 分配 ✅

答案:不需要自己分配 ID

在重构后的代码中,ID分配完全由 yac#connection#send_command() 函数自动处理:

  • vim/autoload/yac/connection.vim:152-156:函数内部维护了一个序列计数器 s:seq_counter
  • 每次调用时自动递增:let l:seq = s:seq_counterlet s:seq_counter += 1
  • 调用者只需传递 jsonrpc_msg 和可选的 callback_func,无需关心ID管理
" 在 vim/autoload/yac.vim:42-49 中的调用示例:
function! yac#request(method, params, callback_func) abort
  let l:jsonrpc_msg = {
    \ 'method': a:method,
    \ 'params': extend(a:params, {'command': a:method})
    \ }
  call yac#connection#send_command(l:jsonrpc_msg, a:callback_func)
endfunction

2. Channel 日志调试 ✅

答案:已支持,当 lsp_bridge_debug 启用时会显示详细的 channel 日志

vim/autoload/yac/connection.vim 中实现了多个调试日志点:

  • 发送消息日志 (166-168行):

    if get(g:, 'lsp_bridge_debug', 0)
      echom printf('YacDebug[SEND]: seq=%d, msg=%s', l:seq, string(a:jsonrpc_msg))
    endif
  • 通知消息日志 (189-191行):

    if get(g:, 'lsp_bridge_debug', 0)
      echom printf('YacDebug[NOTIFY]: %s', string(a:jsonrpc_msg))
    endif
  • 连接状态日志 (42-44, 79-81行):显示连接建立、作业状态等信息

  • 错误处理日志 (106-108行):记录 channel 错误

  • 响应处理日志 (310-313行):在主文件中记录接收的响应

启用方法:let g:lsp_bridge_debug = 1 或调用 :call yac#debug_toggle()


@loyalpartner
Copy link
Owner Author

Claude finished @loyalpartner's task —— View job

Analysis of Refactored send_command & Channel Logging

Based on my analysis of the refactored code, here are the answers to your questions:

  • Analyze send_command ID allocation in refactored code
  • Check channel logging capabilities when lsp_bridge_debug is enabled
  • Provide clear answers to both questions

1. send_command ID 分配 ✅

答案:不需要自己分配 ID

在重构后的代码中,ID分配完全由 yac#connection#send_command() 函数自动处理:

  • vim/autoload/yac/connection.vim:152-156:函数内部维护了一个序列计数器 s:seq_counter
  • 每次调用时自动递增:let l:seq = s:seq_counterlet s:seq_counter += 1
  • 调用者只需传递 jsonrpc_msg 和可选的 callback_func,无需关心ID管理
" 在 vim/autoload/yac.vim:42-49 中的调用示例:
function! yac#request(method, params, callback_func) abort
  let l:jsonrpc_msg = {
    \ 'method': a:method,
    \ 'params': extend(a:params, {'command': a:method})
    \ }
  call yac#connection#send_command(l:jsonrpc_msg, a:callback_func)
endfunction

2. Channel 日志调试 ✅

答案:已支持,当 lsp_bridge_debug 启用时会显示详细的 channel 日志

vim/autoload/yac/connection.vim 中实现了多个调试日志点:

  • 发送消息日志 (166-168行):
    if get(g:, 'lsp_bridge_debug', 0)
      echom printf('YacDebug[SEND]: seq=%d, msg=%s', l:seq, string(a:jsonrpc_msg))
    endif
  • 通知消息日志 (189-191行):
    if get(g:, 'lsp_bridge_debug', 0)
      echom printf('YacDebug[NOTIFY]: %s', string(a:jsonrpc_msg))
    endif
  • 连接状态日志 (42-44, 79-81行):显示连接建立、作业状态等信息
  • 错误处理日志 (106-108行):记录 channel 错误
  • 响应处理日志 (310-313行):在主文件中记录接收的响应

启用方法:let g:lsp_bridge_debug = 1 或调用 :call yac#debug_toggle()

@claude 应用代码

@claude
Copy link
Contributor

claude bot commented Aug 28, 2025

Claude finished @loyalpartner's task —— View job


Code Analysis & Status Complete

Implementation Review

  • Set up development environment (cargo fmt/clippy successful)
  • Review current refactored code state
  • Verify send_command ID allocation implementation
  • Verify channel logging implementation
  • Validate 800-line constraint compliance
  • Check all debug logging integration

Status: Already Implemented ✅

After thorough analysis, all improvements discussed in the previous analysis are already correctly implemented in the refactored code:

1. Automatic ID Allocation ✅

  • vim/autoload/yac/connection.vim:152-156 properly manages s:seq_counter
  • Auto-increments sequence IDs for each request
  • Callers don't need to manually assign IDs
  • Perfect implementation following the discussed approach

2. Comprehensive Channel Logging ✅

  • 25 debug logging points across all modules when g:lsp_bridge_debug = 1
  • Send logging: YacDebug[SEND]: seq=X, msg=...
  • Notification logging: YacDebug[NOTIFY]: ...
  • Response logging: YacDebug[RECV]: ... for all LSP methods
  • Connection lifecycle logging: startup, errors, cleanup

3. Architecture Compliance ✅

  • All files under 800-line limit (largest: 541 lines)
  • Clean modular structure with 9 specialized modules
  • Maintains API compatibility

Conclusion

The refactored codebase already implements the discussed improvements perfectly. The automatic ID allocation and comprehensive debug logging are working exactly as analyzed. No additional code changes are needed - the implementation is complete and correct.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

重构 vimscript

1 participant