Skip to content

Commit

Permalink
Fixed warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelMayer committed Aug 14, 2023
1 parent 0738dc8 commit 9e483dd
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/ui/compileCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ import { Messages } from './messages';

const OutputPathArg = '--output';

enum CommandType {
Build,
Run,
Test
}

export default class CompileCommands {
public static createAndRegister(installer: DafnyInstaller): CompileCommands {
installer.context.subscriptions.push(
commands.registerCommand(DafnyCommands.Build, () =>
buildRunOrTest(installer, false, false, false)),
buildRunOrTest(installer, CommandType.Build, false)),
commands.registerCommand(DafnyCommands.BuildCustomArgs, () =>
buildRunOrTest(installer, true, false, false)),
buildRunOrTest(installer, CommandType.Build, true)),
commands.registerCommand(DafnyCommands.Run, () =>
buildRunOrTest(installer, false, true, false)),
buildRunOrTest(installer, CommandType.Run, false)),
commands.registerCommand(DafnyCommands.Test, () =>
buildRunOrTest(installer, false, false, true)),
buildRunOrTest(installer, CommandType.Test, false))
);
return new CompileCommands();
}
Expand All @@ -30,7 +36,7 @@ export default class CompileCommands {
// Build: run == false && test == false
// Run: run == true
// Test: run == false && test == true
async function buildRunOrTest(installer: DafnyInstaller, useCustomArgs: boolean, run: boolean, test: boolean): Promise<boolean> {
async function buildRunOrTest(installer: DafnyInstaller, commandType: CommandType, useCustomArgs: boolean): Promise<boolean> {
const document = window.activeTextEditor?.document;
if(document == null) {
return false;
Expand All @@ -42,7 +48,7 @@ async function buildRunOrTest(installer: DafnyInstaller, useCustomArgs: boolean,
if(!await document.save()) {
return false;
}
const compilerCommand = await new CommandFactory(installer, document.fileName, useCustomArgs, run, test).createCompilerCommand();
const compilerCommand = await new CommandFactory(installer, document.fileName, commandType, useCustomArgs).createCompilerCommand();
if(compilerCommand == null) {
return false;
}
Expand All @@ -60,9 +66,8 @@ class CommandFactory {
public constructor(
private readonly installer: DafnyInstaller,
private readonly fileName: string,
private readonly useCustomArgs: boolean,
private readonly run: boolean,
private readonly test: boolean
private readonly commandType: CommandType,
private readonly useCustomArgs: boolean
) {}

public async createCompilerCommand(): Promise<string | undefined> {
Expand Down Expand Up @@ -110,17 +115,21 @@ class CommandFactory {
}

private withCompileAndRun(args: string[]): string[] {
if(this.run) {
if(this.commandType === CommandType.Run) {
return [ 'run', '--no-verify', ...args ];
}
if(this.test) {
return [ 'test', '--no-verify', ...args];
if(this.commandType === CommandType.Test) {
return [ 'test', '--no-verify', ...args ];
}
if(this.commandType === CommandType.Build) {
return [ 'build', ...args ];
}
return [ 'build', ...args ];
throw new Error(`Unknown command type: ${this.commandType}`);
}

private withOutputPath(args: string[]): string[] {
if(this.run || this.test) {
//if(this.run || this.test) {
if(this.commandType === CommandType.Run || this.commandType === CommandType.Test) {
return args;
}
if(args.some(arg => arg.includes(OutputPathArg))) {
Expand Down

0 comments on commit 9e483dd

Please sign in to comment.