@@ -4,17 +4,19 @@ import { evaluateAndCreateCampaignSpec } from '@sourcegraph/campaigns-client'
44import slugify from 'slugify'
55import { getCurrentUser } from './util'
66
7- // TODO(sqs) SECURITY(sqs) : sanitize for real
7+ // TODO: sanitize this for real, it gets used in the description of the campaign
88const escapedMarkdownCode = ( text : string ) : string => '`' + text . replace ( / ` / g, '\\`' ) + '`'
99
10- // TODO: make this file filter configurable.
11- // The filter is applied on all files of each matching repo (confirm - is that correct?)
10+ // TODO: instead of using fileFilter, use the search results as the list of matching files
1211const fileFilter = ( path : string ) : boolean => path . endsWith ( '.yaml' ) || path . endsWith ( '.yml' ) || path . endsWith ( '.md' )
1312
1413export const registerFindReplaceAction = ( ) : Subscription => {
1514 const subscription = new Subscription ( )
1615 subscription . add (
17- sourcegraph . commands . registerCommand ( 'start-find-replace' , async ( ) => {
16+ sourcegraph . commands . registerCommand ( 'start-find-replace' , async ( searchQuery : string ) => {
17+ // TODO: in the future, use the search query to get the list of matching files.
18+ console . log ( 'context.searchQuery' , searchQuery )
19+
1820 // To create campaigns, a namespace is used, which can be the current user's username.
1921 const currentUser = await getCurrentUser ( )
2022 const namespaceName = currentUser ?. username
@@ -26,9 +28,11 @@ export const registerFindReplaceAction = (): Subscription => {
2628 if ( ! match ) {
2729 return
2830 }
31+
2932 const replacement = await sourcegraph . app . activeWindow ! . showInputBox ( {
3033 prompt : 'Replace with:' ,
3134 } )
35+ // Empty string is a valid replacement, so compare directly with undefined.
3236 if ( replacement === undefined ) {
3337 return
3438 }
@@ -55,11 +59,6 @@ export const registerFindReplaceAction = (): Subscription => {
5559 if ( ! text . includes ( match ) ) {
5660 return null
5761 }
58- try {
59- console . log ( 'editFile running on' , path )
60- } catch ( error ) {
61- console . error ( 'Caught' , error )
62- }
6362
6463 percentage += ( 100 - percentage ) / 100
6564 reporter . next ( { message : `Computing changes in ${ path } ` , percentage } )
@@ -81,13 +80,10 @@ export const registerFindReplaceAction = (): Subscription => {
8180 } ,
8281 } )
8382 )
84- await sourcegraph . app . activeWindow ! . showNotification (
85- `[**Find-replace changes**](${ applyURL } ) are ready to preview and apply.<br/><br/><small>${ diffStat . added } additions, ${ diffStat . changed } changes, ${ diffStat . deleted } deletions </small>` ,
83+ sourcegraph . app . activeWindow ! . showNotification (
84+ `[**Find-replace changes**](${ applyURL } ) are ready to preview and apply.<br/><br/><small>${ diffStat . changed } changes made. </small>` ,
8685 sourcegraph . NotificationType . Success
8786 )
88-
89- // const relativeURL = new URL(applyURL)
90- // await sourcegraph.commands.executeCommand('open', `${relativeURL.pathname}${relativeURL.search}`)
9187 } )
9288 )
9389 return subscription
0 commit comments