Refactor autoIndent.ts: improve code organization and maintainability #252334
+339
−188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the
autoIndent.ts
file to make the code cleaner, more concise, and easier to understand while preserving all existing functionality.Key Improvements
1. Added consistent typing
IndentationResult
interface to standardize return types across indentation functions2. Extracted common validation logic
validateAutoIndentPrerequisites()
- eliminates duplicate validation code (used in 6 places)createIndentationResult()
- ensures consistent result objects (used in 13 places)3. Broke down complex functions into focused helpers
Before:
getInheritIndentForLine()
: ~142 lines of complex nested logicgetIndentActionForType()
: ~74 lines with multiple responsibilitiesAfter:
getInheritIndentForLine()
: 47 lines, clean and focusedgetIndentActionForType()
: 46 lines, clear logic flowgetIndentationForFirstNonBlankLine()
processIndentationFromPrecedingLine()
handleComplexIndentationCase()
searchForNonTemporaryIndent()
shouldTriggerDecreaseIndentation()
getDecreaseIndentation()
shouldIndentForAutoClosingPair()
4. Enhanced readability and maintainability
Code Quality Metrics
Backward Compatibility
✅ No breaking changes
The refactored code is now much easier to understand, maintain, and extend while following VS Code's coding guidelines.
Fixes #252333.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
electronjs.org
node-gyp
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.