Skip to content

Commit

Permalink
feat: build commands added to document header (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dotneteer committed Apr 21, 2024
1 parent ef66dc8 commit 97e3c00
Show file tree
Hide file tree
Showing 21 changed files with 1,487 additions and 214 deletions.
69 changes: 7 additions & 62 deletions src/common/ksx/eval-tree-async.ts

Large diffs are not rendered by default.

23 changes: 3 additions & 20 deletions src/common/ksx/process-statement-async.ts
Expand Up @@ -60,8 +60,7 @@ export type OnStatementCompletedCallback =
export async function processStatementQueueAsync (
statements: Statement[],
evalContext: EvaluationContext,
thread?: LogicalThread,
onStatementCompleted?: OnStatementCompletedCallback
thread?: LogicalThread
): Promise<QueueInfo> {
if (!thread) {
// --- Create the main thread for the queue
Expand Down Expand Up @@ -103,8 +102,7 @@ export async function processStatementQueueAsync (
outcome = await processStatementAsync(
queueItem!.statement,
evalContext,
thread,
onStatementCompleted
thread
);
} catch (err) {
if (thread.tryBlocks && thread.tryBlocks.length > 0) {
Expand Down Expand Up @@ -150,8 +148,6 @@ export async function processStatementQueueAsync (
}
}

await onStatementCompleted?.(evalContext, queueItem!.statement);

// --- Provide diagnostics
if (queue.length > diagInfo.maxQueueLength) {
diagInfo.maxQueueLength = queue.length;
Expand Down Expand Up @@ -180,8 +176,7 @@ export async function processStatementQueueAsync (
async function processStatementAsync (
statement: Statement,
evalContext: EvaluationContext,
thread: LogicalThread,
onStatementCompleted: OnStatementCompletedCallback
thread: LogicalThread
): Promise<ProcessOutcome> {
// --- These items should be put in the statement queue after return
let toUnshift: StatementQueueItem[] = [];
Expand Down Expand Up @@ -259,7 +254,6 @@ async function processStatementAsync (
statement.expression,
evalContext,
thread,
onStatementCompleted
);
if (thread.blocks && thread.blocks.length !== 0) {
thread.blocks[thread.blocks.length - 1].returnValue = statementValue;
Expand All @@ -271,7 +265,6 @@ async function processStatementAsync (
const arrowFuncValue = await executeArrowExpression(
statement.expression,
evalContext,
onStatementCompleted,
thread,
...(evalContext.eventArgs ?? [])
);
Expand All @@ -290,7 +283,6 @@ async function processStatementAsync (
block,
evalContext,
thread,
onStatementCompleted,
statement.declarations
);
break;
Expand All @@ -306,7 +298,6 @@ async function processStatementAsync (
block,
evalContext,
thread,
onStatementCompleted,
statement.declarations,
true
);
Expand All @@ -319,7 +310,6 @@ async function processStatementAsync (
statement.condition,
evalContext,
thread,
onStatementCompleted
));
if (condition) {
toUnshift = mapToItem(statement.thenBranch);
Expand All @@ -341,7 +331,6 @@ async function processStatementAsync (
statement.expression,
evalContext,
thread,
onStatementCompleted
)
: undefined;

Expand Down Expand Up @@ -377,7 +366,6 @@ async function processStatementAsync (
statement.condition,
evalContext,
thread,
onStatementCompleted
));
if (condition) {
toUnshift = provideLoopBody(
Expand Down Expand Up @@ -408,7 +396,6 @@ async function processStatementAsync (
statement.condition,
evalContext,
thread,
onStatementCompleted
));
if (condition) {
toUnshift = provideLoopBody(
Expand Down Expand Up @@ -531,7 +518,6 @@ async function processStatementAsync (
statement.condition,
evalContext,
thread,
onStatementCompleted
))
) {
// --- Stay in the loop, inject the body, the update expression, and the loop guard
Expand Down Expand Up @@ -749,7 +735,6 @@ async function processStatementAsync (
statement.expression,
evalContext,
thread,
onStatementCompleted
)
);
}
Expand Down Expand Up @@ -941,7 +926,6 @@ export async function processDeclarationsAsync (
block: BlockScope,
evalContext: EvaluationContext,
thread: LogicalThread,
onStatementCompleted: OnStatementCompletedCallback,
declarations: VarDeclaration[],
addConst = false,
useValue = false,
Expand All @@ -957,7 +941,6 @@ export async function processDeclarationsAsync (
decl.expression,
evalContext,
thread,
onStatementCompleted
);
}
visitDeclaration(block, decl, value, addConst);
Expand Down
1 change: 1 addition & 0 deletions src/common/messaging/MainToIdeMessenger.ts
Expand Up @@ -12,6 +12,7 @@ class MainToIdeMessenger extends MessengerBase {
*/
constructor (public readonly window: BrowserWindow) {
super();
this._requestSeqNo = 1000;
ipcMain?.on(
this.responseChannel,
(_ev: IpcMainEvent, response: ResponseMessage) =>
Expand Down
4 changes: 2 additions & 2 deletions src/common/messaging/MessengerBase.ts
Expand Up @@ -11,7 +11,7 @@ import { Channel, RequestMessage, ResponseMessage } from "./messages-core";
*/
export abstract class MessengerBase {
// Sequential number of the next request
private _requestSeqNo = 0;
protected _requestSeqNo = 1;

/**
* Stores resolvers to correlate incoming messages with outcoming ones
Expand Down Expand Up @@ -44,7 +44,7 @@ export abstract class MessengerBase {
// --- Create a promise and store the resolver function with the message ID.
const promise = new Promise<TResp>((resolve, reject) => {
this._messageResolvers.set(
message.correlationId ?? 0,
message.correlationId,
resolve as (
value: ResponseMessage | PromiseLike<ResponseMessage>
) => void
Expand Down
1 change: 1 addition & 0 deletions src/common/messaging/any-to-ide.ts
Expand Up @@ -54,6 +54,7 @@ export interface IdeShowDialogRequest extends MessageBase {
export interface IdeExecuteCommandRequest extends MessageBase {
type: "IdeExecuteCommand";
commandText: string;
scriptId?: number;
}

// --- Ask the IDE to save all files before quitting
Expand Down
97 changes: 16 additions & 81 deletions src/main/app-menu.ts
Expand Up @@ -243,6 +243,21 @@ export function setupMenu (
await saveKliveProject();
}
},
...(!kliveProject
? []
: ([
{ type: "separator" },
{
id: EXCLUDED_PROJECT_ITEMS,
label: "\nManage Excluded Items",
enabled: true,
click: () => {
mainStore.dispatch(
displayDialogAction(EXCLUDED_PROJECT_ITEMS_DIALOG)
);
}
}
] as MenuItemConstructorOptions[])),
...(__DARWIN__
? []
: ([
Expand Down Expand Up @@ -757,86 +772,6 @@ export function setupMenu (
// Project Menu

if (kliveProject) {
// --- Machine-specific view menu items
let specificProjectMenus: MenuItemConstructorOptions[] = [];
if (machineMenus && machineMenus.projectItems) {
specificProjectMenus = machineMenus.projectItems(
{
emuWindow,
ideWindow
},
currentMachine,
currentModel
);
}

template.push({
label: "Project",
submenu: [
{
id: COMPILE_CODE,
label: "Compile code",
enabled: !!buildRoot,
click: async () => {
await executeIdeCommand(ideWindow, "outp build", undefined, true);
await executeIdeCommand(ideWindow, "compile", "Compile Code");
}
},
{
id: INJECT_CODE,
label: "Inject code",
enabled: !!buildRoot && execState === MachineControllerState.Paused,
click: async () => {
await executeIdeCommand(ideWindow, "outp build", undefined, true);
await executeIdeCommand(ideWindow, "inject", "Inject Code", true);
}
},
{ type: "separator" },
{
id: RUN_CODE,
label: "Run",
enabled: !!buildRoot,
click: async () => {
mainStore.dispatch(setRestartTarget("project"));
await executeIdeCommand(ideWindow, "outp build", undefined, true);
await executeIdeCommand(ideWindow, "run", "Run Code", true);
}
},
{
id: DEBUG_CODE,
label: "Debug",
enabled: !!buildRoot,
click: async () => {
mainStore.dispatch(setRestartTarget("project"));
await executeIdeCommand(ideWindow, "outp build", undefined, true);
await executeIdeCommand(ideWindow, "debug", "Debug Code", true);
}
},
{ type: "separator" },
{
id: EXPORT_CODE,
label: "Export code...",
enabled: !!buildRoot,
click: () => {
mainStore.dispatch(displayDialogAction(EXPORT_CODE_DIALOG));
}
},
{ type: "separator" },
{
id: EXCLUDED_PROJECT_ITEMS,
label: "\nManage Excluded Items",
enabled: true,
click: () => {
mainStore.dispatch(
displayDialogAction(EXCLUDED_PROJECT_ITEMS_DIALOG)
);
}
},
{ type: "separator" },
...specificProjectMenus
]
});

if (hasBuildFile) {
let buildTasks: MenuItemConstructorOptions[] = [];
for (const task of collectedBuildTasks) {
Expand Down Expand Up @@ -1134,7 +1069,7 @@ function visitMenu (
}
}

async function executeIdeCommand (
export async function executeIdeCommand (
window: BrowserWindow,
commandText: string,
title?: string,
Expand Down
2 changes: 1 addition & 1 deletion src/main/build.ts
Expand Up @@ -119,7 +119,7 @@ const predefinedTasks: Record<string, PredefinedBuildTaskDescriptor> = {
ideCommand: "debug"
},
exportCode: {
displayName: "Export artifacts",
displayName: "Export code...",
separatorBefore: true,
ideCommand: "export"
}
Expand Down

0 comments on commit 97e3c00

Please sign in to comment.