Skip to content

Maintenance: LenFunctionHandler - Fix VimBlob handling and improve test coverage#1412

Closed
claude[bot] wants to merge 2 commits intomasterfrom
maintenance/len-function-vimblob-fix
Closed

Maintenance: LenFunctionHandler - Fix VimBlob handling and improve test coverage#1412
claude[bot] wants to merge 2 commits intomasterfrom
maintenance/len-function-vimblob-fix

Conversation

@claude
Copy link

@claude claude bot commented Dec 23, 2025

Summary

This maintenance PR improves the len() function implementation by addressing a TODO and enhancing test coverage:

  • Fixed VimBlob handling: Replaced TODO() placeholder with a proper exception message
  • Added test coverage: New tests for VimBlob error case and multibyte string behavior
  • Documented behavior: Added comments explaining current multibyte character handling

What area was inspected

Randomly selected LenFunctionTest.kt for inspection, which led to investigating:

  • vim-engine/src/main/kotlin/com/maddyhome/idea/vim/vimscript/model/functions/handlers/LenFunctionHandler.kt
  • Related test file and function handlers for comparison

Issues found

  1. Unimplemented VimBlob support: The len() function had a TODO() for VimBlob handling, which would cause crashes if encountered
  2. Missing test coverage: No tests for VimBlob error case
  3. Undocumented behavior: Multibyte character handling differs from Vim (returns character count vs byte count)

Changes made

Implementation (LenFunctionHandler.kt)

  • Added import for ExException
  • Replaced is VimBlob -> TODO() with meaningful exception message directing users to YouTrack
  • Follows the same pattern as GetFunctionHandler and EmptyFunctionHandler

Tests (LenFunctionTest.kt)

  • Added test for VimBlob error case: verifies proper error handling
  • Added test for multibyte strings: documents current behavior with comment explaining the difference from Vim's byte-level counting

Why these changes improve the code

  1. Better error handling: Users get a clear message instead of a crash, with guidance to request support
  2. Consistency: Follows established patterns in the codebase for unsupported features
  3. Test coverage: Prevents regressions and documents expected behavior
  4. Documentation: Comment in test clarifies known limitation for future maintainers

Testing

The changes have been verified for correctness. Two focused commits keep the fix and tests logically separated for easier review.

🤖 Generated with Claude Code

github-actions bot and others added 2 commits December 23, 2025 06:15
…() function

The len() function had a TODO() placeholder for VimBlob handling. Since VimBlob
is not yet fully implemented in IdeaVim, this commit replaces the TODO with a
meaningful exception message that directs users to request support in YouTrack,
consistent with the pattern used in other function handlers (e.g., GetFunctionHandler).

This prevents unexpected crashes when users encounter blobs in their VimScript code
and provides clear guidance on the current limitation.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…len()

Added two new test cases:
1. Test that len() with VimBlob throws an appropriate error
2. Test multibyte character handling to document current behavior

The multibyte test includes a comment explaining that IdeaVim currently returns
character count rather than byte count (as Vim does). This documents the known
limitation and provides a baseline for future improvements if byte-level
compatibility is implemented.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@Test
fun `test len with blob causes error`() {
enterCommand("echo len(0z)")
assertPluginError(true)
Copy link
Author

Choose a reason for hiding this comment

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

The test assertion could be more specific. Instead of using assertPluginError(true), consider using assertPluginErrorMessage() to verify the exact error message, similar to line 81's test for float errors. This would:

  1. Make the test more robust (it currently passes for ANY error, not just the blob-related one)
  2. Document the expected error message for future maintainers
  3. Follow the pattern established by other error tests in this file

Suggested change:

Suggested change
assertPluginError(true)
fun `test len with blob causes error`() {
enterCommand("echo len(0z)")
assertPluginError(true)
assertPluginErrorMessage("Blobs are not supported as an argument for len(). If you need it, request support in YouTrack")
}

}

@Test
fun `test len with multibyte characters`() {
Copy link
Author

Choose a reason for hiding this comment

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

Consider adding the @TestWithoutNeovim annotation here since this test documents behavior that differs from real Vim. Looking at other test files in the codebase (e.g., FunctionTest.kt:40-46), tests that exhibit different behavior from Vim/Neovim are typically annotated with:

@TestWithoutNeovim(SkipNeovimReason.DIFFERENT)
@Test
fun `test len with multibyte characters`() {

This makes it clear to maintainers that this is a known difference and helps with test infrastructure that compares against Neovim.

@claude
Copy link
Author

claude bot commented Dec 23, 2025

Code Review Summary

Thank you for this maintenance PR! The changes are well-structured and improve code quality by addressing technical debt. Here's my detailed review:

✅ Strengths

  1. Excellent Error Handling Pattern: The ExException implementation (line 43 in LenFunctionHandler.kt) follows the established pattern from GetFunctionHandler.kt:54, providing users with actionable guidance to request feature support.

  2. Good Test Coverage Additions: The new tests cover important edge cases that were previously untested.

  3. Clear Documentation: The comment in the multibyte test (lines 92-93) appropriately documents the known behavioral difference from Vim.

  4. Proper Code Consistency: The change replaces a crash-inducing TODO() with a proper exception, preventing runtime failures.

🔍 Suggestions for Improvement

I've left two inline comments with specific suggestions:

  1. Test Assertion Specificity (line 85-88): The blob error test uses assertPluginError(true) which passes for ANY error. Consider verifying the exact error message like line 81 does for float errors. This makes the test more robust and documents expected behavior.

  2. Test Annotation (line 91): The multibyte character test should likely include @TestWithoutNeovim(SkipNeovimReason.DIFFERENT) annotation since it documents behavior that differs from real Vim. This follows the pattern seen in other test files (e.g., FunctionTest.kt).

📋 Code Quality Assessment

  • Bug Risk: ✅ Low - The changes are defensive and improve error handling
  • Performance: ✅ No impact - Exception path is only hit on error conditions
  • Security: ✅ No concerns
  • Test Coverage: ⚠️ Good, but could be strengthened per inline comments
  • Best Practices: ✅ Follows established codebase patterns

🎯 Overall Assessment

This is a solid maintenance PR that improves code quality. The core changes are good - the suggestions above are minor improvements that would make the tests more robust and maintainable. The ExException message is user-friendly and follows the codebase convention.

Recommendation: Approve with minor suggested improvements.

@AlexPl292 AlexPl292 closed this Jan 16, 2026
@AlexPl292 AlexPl292 deleted the maintenance/len-function-vimblob-fix branch January 16, 2026 11:48
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.

1 participant