You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this is a way to improve. I'll try to join the Continue Discord for questions
I'm not able to find an open issue that requests the same enhancement
Problem
Issue: Improve Code Folding Strategy for Large String Literals and Variable Declarations
Problem Statement
The current code folding implementation in code.ts doesn't properly handle large string literals or array declarations, especially when they appear at the beginning of a file or function. The collapseChildren method lacks a strategy for handling these edge cases, causing entire blocks to be unnecessarily folded.
Description
The current implementation focuses on folding function bodies and class definitions, but doesn't have dedicated handling for large string literals or variable declarations. This is particularly problematic in languages like Go where large global string declarations or constant arrays are common:
// Example in Go: This large string declaration at file level causes issuesvarlongTemplateString=`This is a very long template string that might span several hundred characters and contain a lot of content...... many more lines ...and finally ends here.`// Or a large array/slice declarationvarlargeDataArray= []string{
"very long string 1 that exceeds reasonable line length and causes folding issues",
"very long string 2 that exceeds reasonable line length and causes folding issues",
"very long string 3 that exceeds reasonable line length and causes folding issues",
// Many more entries...
}
funcmain() {
// Function body starts here
}
In such cases, the entire file gets considered for folding rather than just the problematic declaration.
Suggested Improvement
Enhance the collapseChildren method to include a line-based approach for handling very long lines:
Add a character threshold for individual lines (e.g., 500 characters)
When processing code content, check if any individual line exceeds this threshold
For lines that exceed the threshold, apply targeted folding just to those lines
Implementation Approach
// Add a function to handle long lines in addition to existing folding strategiesfunctionhandleLongLines(code: string,maxLineLength: number=500): string{constlines=code.split('\n');returnlines.map(line=>{if(line.length>maxLineLength){// Preserve the first 200 and last 100 charactersreturnline.substring(0,200)+'...'+line.substring(line.length-100);}returnline;}).join('\n');}// Update collapseChildren to use this functionasyncfunctioncollapseChildren(node: SyntaxNode,code: string,blockTypes: string[],collapseTypes: string[],collapseBlockTypes: string[],maxChunkSize: number,): Promise<string>{// Existing code...// Add line length handling before other folding logiccode=handleLongLines(code);// Rest of the existing implementation...}
This enhancement would allow for more granular folding, targeting only the problematic long lines rather than folding entire blocks or files.
Benefits
More precise folding for large literals and declarations
Improved readability of indexed code
Better handling of edge cases in languages like Go, Java, and Python
Reduced overall size of indexed content without losing important context
Related Components
code.ts - Main file for implementation
Tree-sitter parsing integration
Languages with common long string patterns (Go, Java, Python, etc.)
Solution
No response
The text was updated successfully, but these errors were encountered:
Validations
Problem
Issue: Improve Code Folding Strategy for Large String Literals and Variable Declarations
Problem Statement
The current code folding implementation in code.ts doesn't properly handle large string literals or array declarations, especially when they appear at the beginning of a file or function. The
collapseChildren
method lacks a strategy for handling these edge cases, causing entire blocks to be unnecessarily folded.Description
The current implementation focuses on folding function bodies and class definitions, but doesn't have dedicated handling for large string literals or variable declarations. This is particularly problematic in languages like Go where large global string declarations or constant arrays are common:
In such cases, the entire file gets considered for folding rather than just the problematic declaration.
Suggested Improvement
Enhance the
collapseChildren
method to include a line-based approach for handling very long lines:Implementation Approach
This enhancement would allow for more granular folding, targeting only the problematic long lines rather than folding entire blocks or files.
Benefits
Related Components
Solution
No response
The text was updated successfully, but these errors were encountered: