Skip to content

Fixes for #533, #530, #529 (partially), #528 #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions vscode-plugin/media/wizard.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2>🖥️ Server Setup</h2>
<td>
<label
class="utbot-form__tab_label"
style="width: auto; display: inline;"
style="width: 10ex; display: inline;"
for="portGRPCInput">GRPC port</label>
<input class="utbot-form__tab_input"
style="width: auto; display: inline;"
Expand All @@ -126,15 +126,15 @@ <h2>🖥️ Server Setup</h2>
</td>
<td>
<span id="GRPC_connection_loader">⏳ Connecting...</span>
<span id="GRPC_connection_success">✔️ Successfully pinged GRPC server! </span>
<span id="GRPC_connection_success">✔️ Successfully pinged GRPC server!</span>
<span id="GRPC_connection_warning" format="⚠️ Warning! Versions are different: "></span>
<span id="GRPC_connection_failure">❌ Failed to establish GRPC connection! </span>
<span id="GRPC_connection_failure">❌ Failed to establish GRPC connection!</span>
</td>
</tr>
<tr style="display: grid; grid-template-columns: auto 1fr">
<td>
<label class="utbot-form__tab_label"
style="width: auto; display: inline;"
style="width: 10ex; display: inline;"
for="portSFTPInput">SFTP port</label>
<input class="utbot-form__tab_input"
style="width: auto; display: inline;"
Expand All @@ -149,9 +149,9 @@ <h2>🖥️ Server Setup</h2>
</td>
<td>
<span id="SFTP_connection_loader">⏳ Connecting SFTP...</span>
<span id="SFTP_connection_success">✔️ Successfully pinged SFTP server! </span>
<span id="SFTP_connection_warning">SFTP synchronization is not used.</span>
<span id="SFTP_connection_failure">❌ Failed to establish SFTP connection! </span>
<span id="SFTP_connection_success">✔️ Successfully pinged SFTP server!</span>
<span id="SFTP_connection_warning">SFTP synchronization is not used.</span>
<span id="SFTP_connection_failure">❌ Failed to establish SFTP connection!</span>
</td>
</tr>
</table>
Expand All @@ -168,7 +168,7 @@ <h2>🖥️ Server Setup</h2>
<input class="utbot-form__tab_input"
id="serverPath"
value="{{predictedRemotePath}}"
placeholder="/tmp/XXXX">
placeholder="Ex. /tmp/XXXX">
Project path on server specifies the path to the project's copy on the server host.
May point to a directory shared by the client and server. In this case, SFTP synchronization
must be disabled by leaving the <b>SFTP port field empty</b>.
Expand Down
2 changes: 1 addition & 1 deletion vscode-plugin/media/wizardHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function showTab(tabIndex) {

showElement(currentTabElement, true);
// Show previous button if necessary
showElement(prevButton, tabIndex === 0);
showElement(prevButton, tabIndex !== 0);

// Set nextButton title according to tab number
if (tabIndex === tabElements.length - 1) {
Expand Down
23 changes: 18 additions & 5 deletions vscode-plugin/src/wizard/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function getNonce(): string {
}

export class UtbotWizardPanel {

public static currentPanel: UtbotWizardPanel | undefined;
private disposables: vs.Disposable[] = [];
private static PING_TIMEOUT_MS = 5000;
Expand Down Expand Up @@ -124,6 +123,7 @@ export class UtbotWizardPanel {
});
}

private static GENERATED = "This file is automatically generated by UnitTestBot.";
private async setupSFTP(
activate: boolean,
host: string,
Expand All @@ -142,9 +142,21 @@ export class UtbotWizardPanel {
const workspaceFolder = workspaceFolderUrl.fsPath;
const sftpConfigPath = pathUtils.fsJoin(workspaceFolder, '.vscode', 'sftp.json');
try {
// backup config: sftp.json -> sftp.json.old if we have user's version
if (fs.existsSync(sftpConfigPath)) {
const configContentOld = fs.readFileSync(sftpConfigPath, {encoding:'utf8', flag:'r'});
// checks, that the configuration was not created by UTBot
if (!configContentOld.includes(UtbotWizardPanel.GENERATED)) {
const oldConfigPath = sftpConfigPath + ".old";
console.log(`Back up ".vscode/${sftpConfigPath}" to ".vscode/${oldConfigPath}"`);
fs.writeFileSync(oldConfigPath, configContentOld);
}
}

if (activate) {
const configContent =
const configContent =
`{
"//comment": "${UtbotWizardPanel.GENERATED}",
"name": "UTBot Server",
"host": "${host}",
"protocol": "sftp",
Expand All @@ -159,23 +171,24 @@ export class UtbotWizardPanel {
if (!fs.existsSync(sftpConfigPath)) {
fs.writeFileSync(sftpConfigPath, ' ');
}

const doc = await vs.workspace.openTextDocument(sftpConfigPath);
const editor = await vs.window.showTextDocument(doc, {preview: true, preserveFocus: false});
// we need to generate the `onDidSaveTextDocument` event
// it is the only event that is processed by SFTP pluging to change the preload configuration
// it is the only event that is processed by SFTP plugin to change the preload configuration
void editor.edit( builder => {
builder.delete(new vs.Range(0, 0, 10000, 10000));
builder.insert(new vs.Position(0, 0), configContent);
})
.then( () => {
void editor.document.save().then( saved => {
if (saved) {
messages.showWarningMessage(`New configuration ".vscode/sftp.json" was saved!`);
messages.showInfoMessage(`New configuration ".vscode/sftp.json" was saved!`);
}
void vs.commands.executeCommand('workbench.action.closeActiveEditor');
const postponedSync = (): void => {
void vs.commands.executeCommand("sftp.sync.localToRemote", workspaceFolderUrl).then(
() => messages.showWarningMessage(`Project copy was created on UTBot Server at "${remotePath}"`),
() => messages.showInfoMessage(`Project copy was created on UTBot Server at "${remotePath}"`),
(err) => messages.showWarningMessage(`Project copy was not created on UTBot Server at "${remotePath}" with error ` + err)
);
};
Expand Down