continuedev / continuedev/continue
Enhance CodeSnippets Content Processing for Large Arrays and Long Lines
@Patrick-Erichsen is already working on this.
Since Mar 12, 2025.
- Dominant language
- TypeScript
- Stars
- 36k
- Forks
- 5.4k
- PR merge metrics
- No merged PRs in 30d
Description
Validations
- 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
Type
Enhancement
Description
The current CodeSnippets indexing system faces efficiency challenges when processing code snippets containing extremely long lines or large arrays/objects. These snippets are stored in the database's content field and later provided to large language models (LLMs) as context using the @code directive.
When code snippets contain excessively long lines (thousands of characters) or large array/object declarations, several issues arise:
- Context length becomes unnecessarily large, consuming excessive tokens
- Information density is reduced, with valuable token space wasted on low-value content
- LLM processing efficiency decreases due to the noise-to-signal ratio
Current Implementation
In the CodeSnippetsCodebaseIndex class, specifically in the getSnippetsFromMatch method, node text is directly stored as content without any optimization:
if (bodyCaptureGroupPrefixes.includes(trimmedCaptureName)) {
if (bodyTypesToTreatAsSignatures.includes(nodeType)) {
signature = nodeText;
hasSeenBody = true;
}
content = nodeText;
startLine = node.startPosition.row;
endLine = node.endPosition.row;
}
Later, in the getForId method, this content is wrapped in a Markdown code block and returned:
content: `\`\`\`${relativePathOrBasename}\n${row.content}\n\`\`\``,
This approach lacks any content optimization strategy for handling large data structures or extremely long lines.
Proposed Enhancement
Implement intelligent content optimization strategies to improve information density and reduce token usage:
-
Smart Line Truncation:
- Detect lines exceeding a configurable threshold (e.g., 200-300 characters)
- Intelligently truncate these lines, preserving important parts at the beginning and end
- Replace middle sections with ellipses (
...)
-
Structured Data Summarization:
- Identify large array/object declarations
- Replace with structured summaries (e.g.,
const largeArray = [/* 500 elements */];) - Preserve the first few and last few elements for context
-
Metadata Annotations:
- Add comments indicating original content size/length
- Example:
// Note: Original array contained 500 elements, showing first/last 3
-
Configurable Optimization Strategies:
- Allow customization of maximum line length
- Configure number of elements to preserve in arrays/objects
- Enable/disable specific optimization techniques
Expected Benefits
- Reduced context length, saving token usage
- Improved information density for more efficient LLM processing
- Enhanced user experience with more relevant context
- Better performance when working with codebases containing large data structures
Technical Implementation
Add content optimization logic either within the getSnippetsFromMatch method or as a separate processing function before storing content in the database:
// Example implementation approach
function optimizeContent(content: string): string {
const lines = content.split('\n');
const optimizedLines = lines.map(line => {
if (line.length > MAX_LINE_LENGTH) {
return optimizeLongLine(line);
}
if (isLargeArrayOrObject(line)) {
return summarizeDataStructure(line);
}
return line;
});
return optimizedLines.join('\n');
}
Related Components
core/indexing/CodeSnippetsIndex.ts- Specifically the
getSnippetsFromMatchandgetForIdmethods
Additional Considerations
- Optimization should be lossless for critical code elements (function signatures, control structures)
- Consider adding a flag to retrieve the original unoptimized content when needed
- Ensure backward compatibility with existing indexed snippets
This enhancement would significantly improve the efficiency of code snippets when used as context for LLMs, particularly in codebases with data-heavy files.
Solution
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.