Skip to content

Commit 566d633

Browse files
committed
Fixes for #533, #530, #529 (partially), #528
- SFTP notifications have wrong icons #533 - Fields on 'Server Setup' page of wizard are misaligned #530 - Wizard has no 'Previous' buttons #528 - Don't delete existing sftp.json configuration file #529 (partially - for user config we make a backup) Signed-off-by: Alexey Utkin <[email protected]>
1 parent 7af7938 commit 566d633

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

vscode-plugin/media/wizard.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ <h2>🖥️ Server Setup</h2>
111111
<td>
112112
<label
113113
class="utbot-form__tab_label"
114-
style="width: auto; display: inline;"
114+
style="width: 10ex; display: inline;"
115115
for="portGRPCInput">GRPC port</label>
116116
<input class="utbot-form__tab_input"
117117
style="width: auto; display: inline;"
@@ -126,15 +126,15 @@ <h2>🖥️ Server Setup</h2>
126126
</td>
127127
<td>
128128
<span id="GRPC_connection_loader">⏳ Connecting...</span>
129-
<span id="GRPC_connection_success">✔️ Successfully pinged GRPC server! </span>
129+
<span id="GRPC_connection_success">✔️ Successfully pinged GRPC server!</span>
130130
<span id="GRPC_connection_warning" format="⚠️ Warning! Versions are different: "></span>
131-
<span id="GRPC_connection_failure">❌ Failed to establish GRPC connection! </span>
131+
<span id="GRPC_connection_failure">❌ Failed to establish GRPC connection!</span>
132132
</td>
133133
</tr>
134134
<tr style="display: grid; grid-template-columns: auto 1fr">
135135
<td>
136136
<label class="utbot-form__tab_label"
137-
style="width: auto; display: inline;"
137+
style="width: 10ex; display: inline;"
138138
for="portSFTPInput">SFTP port</label>
139139
<input class="utbot-form__tab_input"
140140
style="width: auto; display: inline;"
@@ -149,9 +149,9 @@ <h2>🖥️ Server Setup</h2>
149149
</td>
150150
<td>
151151
<span id="SFTP_connection_loader">⏳ Connecting SFTP...</span>
152-
<span id="SFTP_connection_success">✔️ Successfully pinged SFTP server! </span>
153-
<span id="SFTP_connection_warning">SFTP synchronization is not used.</span>
154-
<span id="SFTP_connection_failure">❌ Failed to establish SFTP connection! </span>
152+
<span id="SFTP_connection_success">✔️ Successfully pinged SFTP server!</span>
153+
<span id="SFTP_connection_warning">SFTP synchronization is not used.</span>
154+
<span id="SFTP_connection_failure">❌ Failed to establish SFTP connection!</span>
155155
</td>
156156
</tr>
157157
</table>
@@ -168,7 +168,7 @@ <h2>🖥️ Server Setup</h2>
168168
<input class="utbot-form__tab_input"
169169
id="serverPath"
170170
value="{{predictedRemotePath}}"
171-
placeholder="/tmp/XXXX">
171+
placeholder="Ex. /tmp/XXXX">
172172
Project path on server specifies the path to the project's copy on the server host.
173173
May point to a directory shared by the client and server. In this case, SFTP synchronization
174174
must be disabled by leaving the <b>SFTP port field empty</b>.

vscode-plugin/media/wizardHTML.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function showTab(tabIndex) {
171171

172172
showElement(currentTabElement, true);
173173
// Show previous button if necessary
174-
showElement(prevButton, tabIndex === 0);
174+
showElement(prevButton, tabIndex !== 0);
175175

176176
// Set nextButton title according to tab number
177177
if (tabIndex === tabElements.length - 1) {

vscode-plugin/src/wizard/wizard.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ function getNonce(): string {
2626
}
2727

2828
export 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

Comments
 (0)