@@ -26,7 +26,6 @@ function getNonce(): string {
2626}
2727
2828export class UtbotWizardPanel {
29-
3029 public static currentPanel : UtbotWizardPanel | undefined ;
3130 private disposables : vs . Disposable [ ] = [ ] ;
3231 private static PING_TIMEOUT_MS = 5000 ;
@@ -124,6 +123,7 @@ export class UtbotWizardPanel {
124123 } ) ;
125124 }
126125
126+ private static GENERATED = "This file is automatically generated by UnitTestBot." ;
127127 private async setupSFTP (
128128 activate : boolean ,
129129 host : string ,
@@ -142,9 +142,21 @@ export class UtbotWizardPanel {
142142 const workspaceFolder = workspaceFolderUrl . fsPath ;
143143 const sftpConfigPath = pathUtils . fsJoin ( workspaceFolder , '.vscode' , 'sftp.json' ) ;
144144 try {
145+ // backup config: sftp.json -> sftp.json.old if we have user's version
146+ if ( fs . existsSync ( sftpConfigPath ) ) {
147+ const configContentOld = fs . readFileSync ( sftpConfigPath , { encoding :'utf8' , flag :'r' } ) ;
148+ // checks, that the configuration was not created by UTBot
149+ if ( ! configContentOld . includes ( UtbotWizardPanel . GENERATED ) ) {
150+ const oldConfigPath = sftpConfigPath + ".old" ;
151+ console . log ( `Back up ".vscode/${ sftpConfigPath } " to ".vscode/${ oldConfigPath } "` ) ;
152+ fs . writeFileSync ( oldConfigPath , configContentOld ) ;
153+ }
154+ }
155+
145156 if ( activate ) {
146- const configContent =
157+ const configContent =
147158`{
159+ "//comment": "${ UtbotWizardPanel . GENERATED } ",
148160 "name": "UTBot Server",
149161 "host": "${ host } ",
150162 "protocol": "sftp",
@@ -159,23 +171,24 @@ export class UtbotWizardPanel {
159171 if ( ! fs . existsSync ( sftpConfigPath ) ) {
160172 fs . writeFileSync ( sftpConfigPath , ' ' ) ;
161173 }
174+
162175 const doc = await vs . workspace . openTextDocument ( sftpConfigPath ) ;
163176 const editor = await vs . window . showTextDocument ( doc , { preview : true , preserveFocus : false } ) ;
164177 // we need to generate the `onDidSaveTextDocument` event
165- // it is the only event that is processed by SFTP pluging to change the preload configuration
178+ // it is the only event that is processed by SFTP plugin to change the preload configuration
166179 void editor . edit ( builder => {
167180 builder . delete ( new vs . Range ( 0 , 0 , 10000 , 10000 ) ) ;
168181 builder . insert ( new vs . Position ( 0 , 0 ) , configContent ) ;
169182 } )
170183 . then ( ( ) => {
171184 void editor . document . save ( ) . then ( saved => {
172185 if ( saved ) {
173- messages . showWarningMessage ( `New configuration ".vscode/sftp.json" was saved!` ) ;
186+ messages . showInfoMessage ( `New configuration ".vscode/sftp.json" was saved!` ) ;
174187 }
175188 void vs . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
176189 const postponedSync = ( ) : void => {
177190 void vs . commands . executeCommand ( "sftp.sync.localToRemote" , workspaceFolderUrl ) . then (
178- ( ) => messages . showWarningMessage ( `Project copy was created on UTBot Server at "${ remotePath } "` ) ,
191+ ( ) => messages . showInfoMessage ( `Project copy was created on UTBot Server at "${ remotePath } "` ) ,
179192 ( err ) => messages . showWarningMessage ( `Project copy was not created on UTBot Server at "${ remotePath } " with error ` + err )
180193 ) ;
181194 } ;
0 commit comments