Skip to content

Commit 67ea9fb

Browse files
committed
Some Refactoring 1)
1 parent e1ef6a2 commit 67ea9fb

5 files changed

Lines changed: 82 additions & 103 deletions

File tree

src/callbacks.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import * as vscode from "vscode";
22

33
// some functions that are used across functional areas of the extensions
4-
5-
import { updateDisplayedCoverage } from "./coverage";
6-
import { updateTestDecorator } from "./editorDecorator";
7-
8-
import { updateExploreDecorations } from "./fileDecorator";
94
import {
105
errorLevel,
116
indentString,

src/extension.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import {
6363
globalProjectWebviewComboboxItems,
6464
setGlobalProjectIsOpenedChecker,
6565
setGlobalCompilerAndTestsuites,
66+
loadTestScriptButton,
6667
} from "./testPane";
6768

6869
import {
@@ -442,8 +443,8 @@ function configureExtension(context: vscode.ExtensionContext) {
442443
// Command: vectorcastTestExplorer.loadTestScript////////////////////////////////////////////////////////
443444
let loadTestScriptCommand = vscode.commands.registerCommand(
444445
"vectorcastTestExplorer.loadTestScript",
445-
() => {
446-
loadTestScript();
446+
async () => {
447+
await loadTestScriptButton();
447448
}
448449
);
449450
context.subscriptions.push(loadTestScriptCommand);
@@ -829,7 +830,7 @@ function configureExtension(context: vscode.ExtensionContext) {
829830
<div class="modal">
830831
<h2>Add Testsuite to Compiler</h2>
831832
<label for="testsuiteInput">Testsuite Name:</label>
832-
<input type="text" id="testsuiteInput" placeholder="Enter Testsuite Name" />
833+
<input aria-label="testSuiteInput" type="text" id="testsuiteInput" placeholder="Enter Testsuite Name" />
833834
<div>
834835
<button class="primary-button" onclick="submitForm()">OK</button>
835836
<button class="cancel-button" onclick="cancel()">Cancel</button>
@@ -1071,7 +1072,7 @@ function configureExtension(context: vscode.ExtensionContext) {
10711072
// We want to load the test script automatically when the user saves
10721073
const filePath = editor.uri.fsPath;
10731074
if (filePath.endsWith(".tst") && alreadyConfigured) {
1074-
loadTestScript();
1075+
await loadTestScript();
10751076
}
10761077
await updateCodedTestCases(editor);
10771078
await updateCOVdecorations();
@@ -1515,7 +1516,7 @@ async function installPreActivationEventHandlers(
15151516
so the text "Select" is truly centered. -->
15161517
<label>Env File:</label>
15171518
<div class="single-input-container">
1518-
<input type="text" id="envFileInput" placeholder="Select Env File" readonly />
1519+
<input aria-label="envFileInput" type="text" id="envFileInput" placeholder="Select Env File" />
15191520
<button class="select-button" onclick="importEnvFile()">Select</button>
15201521
</div>
15211522
@@ -1874,7 +1875,7 @@ async function installPreActivationEventHandlers(
18741875
<label>Source Files:</label>
18751876
<div id="sourceFilesContainer">
18761877
<div class="single-input-container">
1877-
<input type="text" placeholder="Enter Source File" />
1878+
<input aria-label="sourceFileInput" type="text" placeholder="Enter Source File" />
18781879
<button class="remove-button" onclick="this.parentElement.remove()">✖</button>
18791880
</div>
18801881
</div>
@@ -1900,7 +1901,7 @@ async function installPreActivationEventHandlers(
19001901
<!-- OK/Cancel Buttons -->
19011902
<div class="button-container">
19021903
<button class="primary-button" onclick="cancel()">Cancel</button>
1903-
<button class="primary-button" onclick="submitForm()">OK</button>
1904+
<button aria-label="importOk" class="primary-button" onclick="submitForm()">OK</button>
19041905
</div>
19051906
</div>
19061907

src/testPane.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,20 +1426,9 @@ export async function insertATGTests(testNode: testNodeType) {
14261426
generateAndLoadATGTests(testNode);
14271427
}
14281428

1429-
const url = require("url");
14301429
export async function loadTestScript() {
1431-
// This gets called from the right-click editor context menu
1432-
// The convention is that the .tst file must be in the same directory
1433-
// as the environment, so we get the enviroName from parsing the
1434-
// .tst and get the working directory from its location
1435-
14361430
const activeEditor = vscode.window.activeTextEditor;
14371431
if (activeEditor) {
1438-
if (activeEditor.document.isDirty) {
1439-
// need to wait, otherwise we have a race condition with clicast
1440-
await activeEditor.document.save();
1441-
}
1442-
14431432
let scriptPath = url.fileURLToPath(activeEditor.document.uri.toString());
14441433

14451434
// we use the test script contents to determine the environment name
@@ -1480,12 +1469,35 @@ export async function loadTestScript() {
14801469
}
14811470
}
14821471

1472+
const url = require("url");
1473+
export async function loadTestScriptButton() {
1474+
// This gets called from the right-click editor context menu
1475+
// The convention is that the .tst file must be in the same directory
1476+
// as the environment, so we get the enviroName from parsing the
1477+
// .tst and get the working directory from its location
1478+
1479+
const activeEditor = vscode.window.activeTextEditor;
1480+
if (activeEditor) {
1481+
if (activeEditor.document.isDirty) {
1482+
// need to wait, otherwise we have a race condition with clicast
1483+
// This also triggers the onDidTextdocumentSave which triggers the loadTestScript function
1484+
// If we don't do it that way, we will load the same script twice.
1485+
await activeEditor.document.save();
1486+
}
1487+
}
1488+
}
1489+
14831490
async function checkIfTestExists(
14841491
enviroPath: string,
14851492
scriptPath: string
14861493
): Promise<boolean> {
14871494
const scriptContent = fs.readFileSync(scriptPath, "utf8");
14881495

1496+
// Short-circuit if this is a COMPOUND or INIT test
1497+
if (/^TEST\.SUBPROGRAM:\s*<<(?:COMPOUND|INIT)>>$/m.test(scriptContent)) {
1498+
return true;
1499+
}
1500+
14891501
const testNameMatch = scriptContent.match(/^TEST\.NAME:(.*)$/m);
14901502
const unitNameMatch = scriptContent.match(/^TEST\.UNIT:(.*)$/m);
14911503
const subprogramNameMatch = scriptContent.match(/^TEST\.SUBPROGRAM:(.*)$/m);

src/vcastAdapter.ts

Lines changed: 49 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { openMessagePane, vectorMessage } from "./messagePane";
1616

1717
import {
1818
environmentDataCache,
19-
environmentNodeDataType,
2019
getClicastArgsFromTestNode,
2120
getClicastArgsFromTestNodeAsList,
2221
getEnviroNameFromID,
@@ -237,7 +236,7 @@ export async function cleanProjectEnvironment(
237236
// if we are in server mode, close any existing connection to the environment
238237
if (globalEnviroDataServerActive) await closeConnection(enviroPath);
239238

240-
executeWithRealTimeEchoWithProgress(
239+
await executeWithRealTimeEchoWithProgress(
241240
manageCommandToUse,
242241
manageArgs,
243242
projectLocation,
@@ -608,87 +607,66 @@ export async function updateAllOpenedProjects() {
608607
/**
609608
* Updates the project data for the given environment
610609
* @param enviroPath Path to the environment
611-
* @param enviroName Name of the environment
610+
* @param forceUpdate Whether to force update even if auto-update is disabled
612611
*/
613612
export async function updateProjectData(
614613
enviroPath: string,
615614
forceUpdate = false
616615
) {
617-
// Only update if the current env is embedded in a project and the setting is enabled
618-
// or we force the update by actively clicking on the Update Project Button
619-
const normalizedEnviroPath = normalizePath(enviroPath);
616+
const normalizedPath = normalizePath(enviroPath);
620617
const config = vscode.workspace.getConfiguration("vectorcastTestExplorer");
621-
const autoUpdateEnabled = config.get<boolean>(
618+
const autoUpdate = config.get<boolean>(
622619
"automaticallyUpdateManageProject",
623620
true
624621
);
625622

626-
const envIsInProject: boolean = envIsEmbeddedInProject(normalizedEnviroPath);
627-
628-
if (envIsInProject && (autoUpdateEnabled || forceUpdate)) {
629-
const enviroName = path.basename(normalizedEnviroPath);
630-
const blockUpdate =
631-
await checkIfEnvironmentIsBuildMultipleTimes(enviroName);
632-
if (blockUpdate) {
633-
// Show an information message with two options.
634-
const selection = await vscode.window.showInformationMessage(
635-
`Updating the project data is currently blocked because ${enviroName} is built in multiple testsuites. You can clean the other Environments now and the project will be updated.`,
636-
"Cancel",
637-
"Clean other Environments"
638-
);
639-
640-
if (selection === "Clean other Environments") {
641-
// Delete the build folders of the other builds.
642-
await deleteOtherBuildFolders(normalizedEnviroPath);
643-
644-
// Update Project after cleaning the other environments
645-
const enviroData: environmentNodeDataType =
646-
getEnviroNodeData(normalizedEnviroPath);
647-
const projectFilePath: string = enviroData.projectPath;
648-
const projectName: string = path.basename(projectFilePath);
649-
const projectLocation: string = path.dirname(projectFilePath);
650-
const manageArgs: string[] = [
651-
`-p${projectName}`,
652-
`--level=${enviroData.displayName}`,
653-
"--apply-changes",
654-
"--force",
655-
];
623+
// Only update if the current env is embedded in a project and the setting is enabled
624+
// or we force the update by actively clicking on the Update Project Button
625+
if (
626+
!envIsEmbeddedInProject(normalizedPath) ||
627+
(!autoUpdate && !forceUpdate)
628+
) {
629+
return;
630+
}
656631

657-
openMessagePane();
658-
const progressMessage = "Updating project data ...";
659-
await executeWithRealTimeEchoWithProgress(
660-
manageCommandToUse,
661-
manageArgs,
662-
projectLocation,
663-
progressMessage
664-
);
665-
} else {
666-
// User chose Cancel; do nothing.
667-
return;
668-
}
669-
} else {
670-
const enviroData: environmentNodeDataType =
671-
getEnviroNodeData(normalizedEnviroPath);
672-
const projectFilePath: string = enviroData.projectPath;
673-
const projectName: string = path.basename(projectFilePath);
674-
const projectLocation: string = path.dirname(projectFilePath);
675-
const manageArgs: string[] = [
676-
`-p${projectName}`,
677-
`--level=${enviroData.displayName}`,
678-
"--apply-changes",
679-
"--force",
680-
];
681-
682-
openMessagePane();
683-
const progressMessage = "Updating project data ...";
684-
await executeWithRealTimeEchoWithProgress(
685-
manageCommandToUse,
686-
manageArgs,
687-
projectLocation,
688-
progressMessage
689-
);
690-
}
632+
const enviroName = path.basename(normalizedPath);
633+
634+
// Check if the environment is built in multiple test suites
635+
const shouldBlock = await checkIfEnvironmentIsBuildMultipleTimes(enviroName);
636+
637+
if (shouldBlock) {
638+
// Show an information message with two options.
639+
const choice = await vscode.window.showInformationMessage(
640+
`Updating the project data is currently blocked because ${enviroName} is built in multiple testsuites. You can clean the other Environments now and the project will be updated.`,
641+
"Cancel",
642+
"Clean other Environments"
643+
);
644+
645+
if (choice !== "Clean other Environments") return;
646+
647+
// Delete the build folders of the other builds.
648+
await deleteOtherBuildFolders(normalizedPath);
691649
}
650+
651+
// Update Project after cleaning the other environments OR if update is not blocked
652+
const { projectPath, displayName } = getEnviroNodeData(normalizedPath);
653+
const projectName = path.basename(projectPath);
654+
const projectLocation = path.dirname(projectPath);
655+
const manageArgs = [
656+
`-p${projectName}`,
657+
`--level=${displayName}`,
658+
"--apply-changes",
659+
"--force",
660+
];
661+
662+
openMessagePane();
663+
const progressMessage = "Updating project data ...";
664+
await executeWithRealTimeEchoWithProgress(
665+
manageCommandToUse,
666+
manageArgs,
667+
projectLocation,
668+
progressMessage
669+
);
692670
}
693671

694672
// Load Test Script - server logic included -----------------------------------------

src/vcastUtilities.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as vscode from "vscode";
33
// needed for parsing json files with comments
44
import * as jsonc from "jsonc-parser";
55

6-
import { deleteEnvironmentCallback, loadScriptCallBack } from "./callbacks";
6+
import { loadScriptCallBack } from "./callbacks";
77

88
import { vectorMessage } from "./messagePane";
99

@@ -40,23 +40,16 @@ import {
4040
vUnitIncludeSuffix,
4141
} from "./vcastInstallation";
4242

43-
import {
44-
clientRequestType,
45-
closeConnection,
46-
globalEnviroDataServerActive,
47-
vcastCommandType,
48-
} from "../src-common/vcastServer";
43+
import { clientRequestType, vcastCommandType } from "../src-common/vcastServer";
4944
import {
5045
globalController,
5146
globalProjectDataCache,
5247
globalProjectMap,
5348
globalUnusedCompilerList,
5449
globalUnusedTestsuiteList,
5550
nodeKind,
56-
refreshAllExtensionData,
5751
vcastTestItem,
5852
} from "./testPane";
59-
import { executeWithRealTimeEchoWithProgress } from "./vcastCommandRunner";
6053

6154
const fs = require("fs");
6255
const os = require("os");

0 commit comments

Comments
 (0)