Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit a94b3f5

Browse files
authored
issue 415 adding retry and refresh (#416)
* issue 415 adding retry and refresh * fixing command list test and updating changelog Signed-off-by: Brian Fitzpatrick <[email protected]>
1 parent f4a710c commit a94b3f5

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ All notable changes to the "vscode-didact" extension will be documented in this
44

55
## 0.3.2
66

7-
- TBD
7+
- adding *vscode.didact.refresh* command to refresh the currently active Didact window
8+
- adding retry in case the uri for a tutorial isn't quite available yet
89

910
## 0.3.1
1011

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
"command": "vscode.didact.verifyCommands",
110110
"title": "Validate Didact File",
111111
"when": "resourceFilename =~ /[.](didact)[.](md|adoc)$/"
112+
},
113+
{
114+
"command": "vscode.didact.refresh",
115+
"title": "Didact: Refresh Current Didact Window"
112116
}
113117
],
114118
"keybindings": [

src/didactPanel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ export class DidactPanel {
159159
this._panel.webview.postMessage(jsonMsg);
160160
}
161161

162+
public async refreshPanel() : Promise<void> {
163+
this.configure(true);
164+
}
165+
162166
async configure(flag = false): Promise<void> {
163167
this._update(flag);
164168
await this.sendSetStateMessage();

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
6262
context.subscriptions.push(vscode.commands.registerCommand(extensionFunctions.PASTE_TO_ACTIVE_EDITOR_COMMAND, extensionFunctions.pasteClipboardToActiveEditorOrPreviouslyUsedOne));
6363
context.subscriptions.push(vscode.commands.registerCommand(extensionFunctions.PASTE_TO_EDITOR_FOR_FILE_COMMAND, extensionFunctions.pasteClipboardToEditorForFile));
6464
context.subscriptions.push(vscode.commands.registerCommand(extensionFunctions.PASTE_TO_NEW_FILE_COMMAND, extensionFunctions.pasteClipboardToNewTextFile));
65+
context.subscriptions.push(vscode.commands.registerCommand(extensionFunctions.REFRESH_DIDACT, extensionFunctions.refreshDidactWindow));
6566

6667
// set up the vscode URI handler
6768
vscode.window.registerUriHandler({

src/extensionFunctions.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const FILE_TO_CLIPBOARD_COMMAND = 'vscode.didact.copyFileTextToClipboardC
6868
export const PASTE_TO_ACTIVE_EDITOR_COMMAND = 'vscode.didact.copyClipboardToActiveTextEditor';
6969
export const PASTE_TO_EDITOR_FOR_FILE_COMMAND = 'vscode.didact.copyClipboardToEditorForFile';
7070
export const PASTE_TO_NEW_FILE_COMMAND = 'vscode.didact.copyClipboardToNewFile';
71+
export const REFRESH_DIDACT = 'vscode.didact.refresh';
7172

7273
export const EXTENSION_ID = "redhat.vscode-didact";
7374

@@ -433,6 +434,11 @@ export async function reloadDidact(): Promise<void>{
433434
await vscode.commands.executeCommand(START_DIDACT_COMMAND, _didactFileUri);
434435
}
435436

437+
export async function refreshDidactWindow(): Promise<void>{
438+
sendTextToOutputChannel(`Refreshing Didact window`);
439+
await didactManager.active()?.refreshPanel();
440+
}
441+
436442
// send a message back to the webview - used for requirements testing mostly
437443
function postRequirementsResponseMessage(requirement: string, booleanResponse: boolean): void {
438444
if (requirement) {
@@ -457,19 +463,33 @@ export async function getWebviewContent() : Promise<string|void> {
457463
}
458464
if (_didactFileUri) {
459465
if (_didactFileUri.scheme === 'file') {
460-
return await getDataFromFile(_didactFileUri).catch( (error) => {
461-
showFileUnavailable(error);
462-
});
466+
return await loadFileWithRetry(_didactFileUri);
463467
} else if (_didactFileUri.scheme === 'http' || _didactFileUri.scheme === 'https'){
464-
const urlToFetch = _didactFileUri.toString();
465-
return await getDataFromUrl(urlToFetch).catch( (error) => {
466-
showFileUnavailable(error);
467-
});
468+
return await loadFileFromHTTPWithRetry(_didactFileUri);
468469
}
469470
}
470471
return undefined;
471472
}
472473

474+
async function loadFileWithRetry ( uri:vscode.Uri ) : Promise<string | void | undefined> {
475+
return await getDataFromFile(uri).catch( async (error) => {
476+
await utils.delay(3000);
477+
return await getDataFromFile(uri).catch( async (error) => {
478+
showFileUnavailable(error);
479+
});
480+
});
481+
}
482+
483+
async function loadFileFromHTTPWithRetry ( uri:vscode.Uri ) : Promise<string | void | undefined> {
484+
const urlToFetch = uri.toString();
485+
return await getDataFromUrl(urlToFetch).catch( async (error) => {
486+
await utils.delay(3000);
487+
return await getDataFromUrl(urlToFetch).catch( async (error) => {
488+
showFileUnavailable(error);
489+
});
490+
});
491+
}
492+
473493
export function isAsciiDoc() : boolean {
474494
let uriToTest : vscode.Uri | undefined;
475495
if (!_didactFileUri) {

src/test/suite/didactUriCompletionItemProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ suite("Didact URI completion provider tests", function () {
110110
test("that the command processing for a command prefix returns expected results", async () => {
111111
const match = provider.findMatchForCommandVariable('didact://?commandId=vscode.didact.');
112112
const completionList = await provider.processCommands(match);
113-
expect(completionList.items).to.have.lengthOf(26)
113+
expect(completionList.items).to.have.lengthOf(27)
114114
});
115115

116116
test("that the command processing for one command returns one expected result", async () => {

0 commit comments

Comments
 (0)