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

Commit

Permalink
Improve command validation (#130)
Browse files Browse the repository at this point in the history
* use find vs. filter to find command id (#123)
* provide number of  commands validated (#124)
* open output log when validating (#125)
* simplifying check for undefined and removing unnecessary check
* adjusting changelog message slightly

Signed-off-by: bfitzpat@redhat.com <bfitzpat@redhat.com>
  • Loading branch information
bfitzpat authored Jun 18, 2020
1 parent 226365c commit bd110dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to the "vscode-didact" extension will be documented in this
- Adding title-level context menu item to Markdown and AsciiDoc editors to call validation
- Adding awareness so Didact view column is persisted if moved
- Adding new 'vscode.didact.copyToClipboardCommand' command that can put text on the clipboard
- Improving validation to show number of commands validated and open Didact output channel to see results
- Improving command validation performance

## 0.1.14

Expand Down
14 changes: 11 additions & 3 deletions src/extensionFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,13 @@ export namespace extensionFunctions {
}
}

async function openDidactOutputChannel() : Promise<void> {
if (!didactOutputChannel) {
didactOutputChannel = vscode.window.createOutputChannel(DIDACT_OUTPUT_CHANNEL);
}
didactOutputChannel.show();
}

// exported for testing
export async function validateDidactCommands(commands : any[]) : Promise<boolean> {
let allOk = true;
Expand Down Expand Up @@ -634,10 +641,10 @@ export namespace extensionFunctions {
// exported for testing
export function validateCommand(commandId:string, vsCommands:string[]) : boolean {
if (commandId) {
var filteredList : string[] = vsCommands.filter( function (command) {
var foundCommand : string | undefined = vsCommands.find( function (command) {
return command === commandId;
});
if (filteredList.length >= 1) {
if (foundCommand) {
return true;
}
}
Expand All @@ -651,11 +658,12 @@ export namespace extensionFunctions {
if (DidactWebviewPanel.currentPanel) {
const commands : any[] = extensionFunctions.gatherAllCommandsLinks();
let allOk = false;
await openDidactOutputChannel();
if (commands && commands.length > 0) {
allOk = await validateDidactCommands(commands);
if (allOk) {
sendTextToOutputChannel(`--Command IDs: OK`);
sendTextToOutputChannel(`Validation Result: SUCCESS`);
sendTextToOutputChannel(`Validation Result: SUCCESS (${commands.length} Commands Validated)`);
} else {
sendTextToOutputChannel(`Validation Result: FAILURE`);
sendTextToOutputChannel(`-- Note that command IDs not found may be due to a missing extension or simply an invalid ID.`);
Expand Down

0 comments on commit bd110dd

Please sign in to comment.