@@ -147,42 +147,39 @@ export class GrepSearch {
147147 const result = await rg . run ( )
148148 this . logger . info ( `Executing ripgrep with exitCode: ${ result . exitCode } ` )
149149 // Process the output to format with file URLs and remove matched content
150- const processedOutput = this . processRipgrepOutput ( result . stdout )
150+ const { sanitizedOutput , totalMatchCount } = this . processRipgrepOutput ( result . stdout )
151151
152152 // If updates is provided, write the processed output
153153 if ( updates ) {
154- updates . write ( ' \n\nGreped Results :\n\n' )
155- updates . write ( processedOutput )
154+ updates . write ( ` \n\n( ${ totalMatchCount } matches found) :\n\n` )
155+ updates . write ( sanitizedOutput )
156156 }
157157
158- this . logger . info ( `Processed ripgrep result: ${ processedOutput } ` )
159- resolve ( processedOutput )
158+ this . logger . info ( `Processed ripgrep result: ${ totalMatchCount } matches found ` )
159+ resolve ( sanitizedOutput )
160160 } catch ( err ) {
161161 reject ( err )
162162 }
163163 } )
164164 }
165165
166- /**
167- * Process ripgrep output to:
168- * 1. Remove matched content (keep only file:line)
169- * 2. Add file URLs for clickable links
170- */
171166 /**
172167 * Process ripgrep output to:
173168 * 1. Group results by file
174169 * 2. Format as collapsible sections
175170 * 3. Add file URLs for clickable links
171+ * @returns An object containing the processed output and total match count
176172 */
177- private processRipgrepOutput ( output : string ) : string {
173+ private processRipgrepOutput ( output : string ) : { sanitizedOutput : string ; totalMatchCount : number } {
178174 if ( ! output || output . trim ( ) === '' ) {
179- return 'No matches found.'
175+ return { sanitizedOutput : 'No matches found.' , totalMatchCount : 0 }
180176 }
181177
182178 const lines = output . split ( '\n' )
183179
184180 // Group by file path
185181 const fileGroups : Record < string , string [ ] > = { }
182+ let totalMatchCount = 0
186183
187184 for ( const line of lines ) {
188185 if ( ! line || line . trim ( ) === '' ) {
@@ -203,28 +200,32 @@ export class GrepSearch {
203200 fileGroups [ filePath ] = [ ]
204201 }
205202
206- // Create a clickable link with line number only
207- fileGroups [ filePath ] . push ( `- [Line ${ lineNumber } ](${ vscode . Uri . file ( filePath ) . toString ( ) } :${ lineNumber } )` )
203+ // Create a clickable link with line number using VS Code's Uri.with() method
204+ const uri = vscode . Uri . file ( filePath )
205+ // Use the with() method to add the line number as a fragment
206+ const uriWithLine = uri . with ( { fragment : `L${ lineNumber } ` } )
207+ fileGroups [ filePath ] . push ( `- [Line ${ lineNumber } ](${ uriWithLine . toString ( true ) } )` )
208+ totalMatchCount ++
208209 }
209210
210211 // Sort files by match count (most matches first)
211212 const sortedFiles = Object . entries ( fileGroups ) . sort ( ( a , b ) => b [ 1 ] . length - a [ 1 ] . length )
212213
213214 // Format as collapsible sections
214- const processedOutput = sortedFiles
215+ const sanitizedOutput = sortedFiles
215216 . map ( ( [ filePath , matches ] ) => {
216217 const fileName = path . basename ( filePath )
217218 const matchCount = matches . length
218219
219220 return `<details>
220- <summary><strong>${ fileName } (${ matchCount } )</strong></summary>
221+ <summary><strong>${ fileName } - match count: (${ matchCount } )</strong></summary>
221222
222223${ matches . join ( '\n' ) }
223224</details>`
224225 } )
225226 . join ( '\n\n' )
226227
227- return processedOutput
228+ return { sanitizedOutput , totalMatchCount }
228229 }
229230
230231 private createOutput ( content : string ) : InvokeOutput {
0 commit comments