@@ -58,7 +58,19 @@ interface SearchResult {
58
58
afterContext : string [ ]
59
59
}
60
60
61
+ // Constants
61
62
const MAX_RESULTS = 300
63
+ const MAX_LINE_LENGTH = 500
64
+
65
+ /**
66
+ * Truncates a line if it exceeds the maximum length
67
+ * @param line The line to truncate
68
+ * @param maxLength The maximum allowed length (defaults to MAX_LINE_LENGTH)
69
+ * @returns The truncated line, or the original line if it's shorter than maxLength
70
+ */
71
+ export function truncateLine ( line : string , maxLength : number = MAX_LINE_LENGTH ) : string {
72
+ return line . length > maxLength ? line . substring ( 0 , maxLength ) + " [truncated...]" : line
73
+ }
62
74
63
75
async function getBinPath ( vscodeAppRoot : string ) : Promise < string | undefined > {
64
76
const checkPath = async ( pkgFolder : string ) => {
@@ -140,7 +152,8 @@ export async function regexSearchFiles(
140
152
let output : string
141
153
try {
142
154
output = await execRipgrep ( rgPath , args )
143
- } catch {
155
+ } catch ( error ) {
156
+ console . error ( "Error executing ripgrep:" , error )
144
157
return "No results found"
145
158
}
146
159
const results : SearchResult [ ] = [ ]
@@ -154,19 +167,28 @@ export async function regexSearchFiles(
154
167
if ( currentResult ) {
155
168
results . push ( currentResult as SearchResult )
156
169
}
170
+
171
+ // Safety check: truncate extremely long lines to prevent excessive output
172
+ const matchText = parsed . data . lines . text
173
+ const truncatedMatch = truncateLine ( matchText )
174
+
157
175
currentResult = {
158
176
file : parsed . data . path . text ,
159
177
line : parsed . data . line_number ,
160
178
column : parsed . data . submatches [ 0 ] . start ,
161
- match : parsed . data . lines . text ,
179
+ match : truncatedMatch ,
162
180
beforeContext : [ ] ,
163
181
afterContext : [ ] ,
164
182
}
165
183
} else if ( parsed . type === "context" && currentResult ) {
184
+ // Apply the same truncation logic to context lines
185
+ const contextText = parsed . data . lines . text
186
+ const truncatedContext = truncateLine ( contextText )
187
+
166
188
if ( parsed . data . line_number < currentResult . line ! ) {
167
- currentResult . beforeContext ! . push ( parsed . data . lines . text )
189
+ currentResult . beforeContext ! . push ( truncatedContext )
168
190
} else {
169
- currentResult . afterContext ! . push ( parsed . data . lines . text )
191
+ currentResult . afterContext ! . push ( truncatedContext )
170
192
}
171
193
}
172
194
} catch ( error ) {
0 commit comments