Skip to content
Draft
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
42 changes: 38 additions & 4 deletions src/iproject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* (c) Copyright IBM Corp. 2023
*/

import { Action, CommandResult, DeploymentMethod, DeploymentParameters, IBMiObject } from "@halcyontech/vscode-ibmi-types";
import { Action, ActionResult, CommandResult, DeploymentMethod, DeploymentParameters, IBMiObject } from "@halcyontech/vscode-ibmi-types";
import * as dotenv from 'dotenv';
import { ValidatorResult } from "jsonschema";
import * as path from "path";
Expand Down Expand Up @@ -61,6 +61,15 @@ export type Direction = 'up' | 'down';
*/
export type Position = 'first' | 'last' | 'middle';

/**
* Represents a build or compile result.
*/
export type BuildOrCompileResult = {
success: boolean,
output: string[],
message: string
};

/**
* Represents an IBM i Project.
*/
Expand Down Expand Up @@ -468,7 +477,13 @@ export class IProject {
* @param fileUri The file uri to compile or `undefined` for builds.
* @param object The specific object to build.
*/
public async runBuildOrCompileCommand(isBuild: boolean, fileUri?: Uri, object?: string) {
public async runBuildOrCompileCommand(isBuild: boolean, fileUri?: Uri, object?: string): Promise<BuildOrCompileResult> {
let buildOrCompileResult: BuildOrCompileResult = {
success: false,
output: [],
message: ''
};

const unresolvedState = await this.getUnresolvedState();

if (unresolvedState) {
Expand All @@ -488,8 +503,9 @@ export class IProject {
}

if (rawCommand) {
let actionResult: ActionResult | undefined;
if (rawCommand.startsWith('ext:')) {
await commands.executeCommand(rawCommand.substring(4), { fileUri, object });
actionResult = await commands.executeCommand(rawCommand.substring(4), { fileUri, object });
} else {
const directoryUris = ['.logs', '.evfevent'].map(dir => Uri.file(path.join(this.workspaceFolder.uri.fsPath, dir)));
for await (const uri of directoryUris) {
Expand Down Expand Up @@ -520,12 +536,29 @@ export class IProject {
".evfevent"
]
};
await commands.executeCommand(`code-for-ibmi.runAction`, { resourceUri: fileUri ? fileUri : this.workspaceFolder.uri }, undefined, action, this.deploymentMethod);
actionResult = await commands.executeCommand(`code-for-ibmi.runAction`, { resourceUri: fileUri ? fileUri : this.workspaceFolder.uri }, undefined, action, this.deploymentMethod);
}

ProjectManager.fire({ type: isBuild ? 'build' : 'compile', iProject: this });

if (actionResult) {
buildOrCompileResult.success = actionResult.success;
buildOrCompileResult.message = actionResult.message;
if (actionResult.output.length > 0 && actionResult.output[0].output.length > 0) {
buildOrCompileResult.output = actionResult.output[0].output;
}
}
} else {
const commandField = isBuild ?
(object ? 'buildObjectCommand' : 'buildCommand') :
'compileCommand';
buildOrCompileResult.message = l10n.t('{0} not set', commandField);
}
} else {
buildOrCompileResult.message = l10n.t('No iproj.json found');
}

return buildOrCompileResult;
}
/**
* Run the project's build, build object, or compile command. If no command
Expand Down Expand Up @@ -1436,6 +1469,7 @@ export class IProject {
this.liblVarsUpdated = false; // toggle off after it is cheched
return returnValue;
}

/**
* Get the validation result of the project against the `iproj.json` schema.
*
Expand Down