@@ -26,7 +26,6 @@ function getNonce(): string {
26
26
}
27
27
28
28
export class UtbotWizardPanel {
29
-
30
29
public static currentPanel : UtbotWizardPanel | undefined ;
31
30
private disposables : vs . Disposable [ ] = [ ] ;
32
31
private static PING_TIMEOUT_MS = 5000 ;
@@ -124,6 +123,7 @@ export class UtbotWizardPanel {
124
123
} ) ;
125
124
}
126
125
126
+ private static GENERATED = "This file is automatically generated by UnitTestBot." ;
127
127
private async setupSFTP (
128
128
activate : boolean ,
129
129
host : string ,
@@ -142,9 +142,21 @@ export class UtbotWizardPanel {
142
142
const workspaceFolder = workspaceFolderUrl . fsPath ;
143
143
const sftpConfigPath = pathUtils . fsJoin ( workspaceFolder , '.vscode' , 'sftp.json' ) ;
144
144
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
+
145
156
if ( activate ) {
146
- const configContent =
157
+ const configContent =
147
158
`{
159
+ "//comment": "${ UtbotWizardPanel . GENERATED } ",
148
160
"name": "UTBot Server",
149
161
"host": "${ host } ",
150
162
"protocol": "sftp",
@@ -159,23 +171,24 @@ export class UtbotWizardPanel {
159
171
if ( ! fs . existsSync ( sftpConfigPath ) ) {
160
172
fs . writeFileSync ( sftpConfigPath , ' ' ) ;
161
173
}
174
+
162
175
const doc = await vs . workspace . openTextDocument ( sftpConfigPath ) ;
163
176
const editor = await vs . window . showTextDocument ( doc , { preview : true , preserveFocus : false } ) ;
164
177
// 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
166
179
void editor . edit ( builder => {
167
180
builder . delete ( new vs . Range ( 0 , 0 , 10000 , 10000 ) ) ;
168
181
builder . insert ( new vs . Position ( 0 , 0 ) , configContent ) ;
169
182
} )
170
183
. then ( ( ) => {
171
184
void editor . document . save ( ) . then ( saved => {
172
185
if ( saved ) {
173
- messages . showWarningMessage ( `New configuration ".vscode/sftp.json" was saved!` ) ;
186
+ messages . showInfoMessage ( `New configuration ".vscode/sftp.json" was saved!` ) ;
174
187
}
175
188
void vs . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
176
189
const postponedSync = ( ) : void => {
177
190
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 } "` ) ,
179
192
( err ) => messages . showWarningMessage ( `Project copy was not created on UTBot Server at "${ remotePath } " with error ` + err )
180
193
) ;
181
194
} ;
0 commit comments