Skip to content

Commit

Permalink
Add support for --internal-build-dir option with juvix-mode.internalB…
Browse files Browse the repository at this point in the history
…uildDir option
  • Loading branch information
jonaprieto committed Jan 10, 2023
1 parent e524a85 commit d2e96af
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "juvix-mode",
"version": "0.1.17",
"version": "0.1.18",
"license": "GPL-3.0",
"description": "Juvix Mode for VSCode",
"displayName": "Juvix",
Expand Down Expand Up @@ -486,6 +486,11 @@
"noStdlib": {
"type": "boolean",
"description": "Do not use the standard library"
},
"internalBuildDir": {
"type": "string",
"default": ".juvix-build",
"description": "Directory for compiler internal output. Empty string will make the compiler use a temporary directory."
}
},
"additionalProperties": false,
Expand Down
23 changes: 22 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
'use strict';

import { serializerWithDefault, VsCodeSetting } from './utils/VsCodeSetting';
import * as fs from 'fs';
import * as path from 'path';
import { tmpdir } from 'os';
import { debugChannel } from './utils/debug';

export class JuvixConfig {
readonly binaryName = new VsCodeSetting('juvix-mode.bin.name', {
Expand All @@ -16,6 +19,7 @@ export class JuvixConfig {
serializer: serializerWithDefault(''),
});


public getJuvixExec(): string {
return path.join(this.binaryPath.get(), this.binaryName.get());
}
Expand All @@ -29,7 +33,21 @@ export class JuvixConfig {
readonly noTermination = new VsCodeSetting('juvix-mode.opts.noTermination');
readonly noPositivity = new VsCodeSetting('juvix-mode.opts.noPositivity');
readonly noStdlib = new VsCodeSetting('juvix-mode.opts.noStdlib');

readonly internalBuildDir = new VsCodeSetting('juvix-mode.opts.internalBuildDir');

public getInternalBuildDir(): string {
const buildDir = this.internalBuildDir.get();
if (buildDir) return buildDir.toString();
const tmp = path.join(tmpdir(),fs.mkdtempSync('juvix'));
try {
fs.mkdirSync(tmp);
return tmp.toString();
} catch (e) {
debugChannel.error('Error creating temporary directory: ' + e);
}
return '.juvix-build';
}

// Dev
readonly enableDevTasks = new VsCodeSetting('juvix-mode.enableDevTasks', {
serializer: serializerWithDefault(false),
Expand All @@ -38,6 +56,7 @@ export class JuvixConfig {
serializer: serializerWithDefault<TaggedList>({}),
});


public getGlobalFlags(): string {
const flags = [];
if (this.noColors.get()) flags.push('--no-colors');
Expand All @@ -46,6 +65,8 @@ export class JuvixConfig {
if (this.noTermination.get()) flags.push('--no-termination');
if (this.noPositivity.get()) flags.push('--no-positivity');
if (this.noStdlib.get()) flags.push('--no-stdlib');
flags.push('--internal-build-dir');
flags.push(this.getInternalBuildDir());
return flags.join(' ').trim();
}

Expand Down
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as vscode from 'vscode';
import { debugChannel } from './utils/debug';
import * as tasks from './tasks';
import * as user from './config';
import * as statusBar from './statusbar';
import * as syntaxHighlighter from './highlighting';
import * as goToDefinition from './definitions';
Expand Down
29 changes: 12 additions & 17 deletions src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import * as vscode from 'vscode';
import * as user from './config';
import { debugChannel } from './utils/debug';
import * as fs from 'fs';
import * as path from 'path';
import { tmpdir } from 'os';

export const TASK_TYPE = 'Juvix';

Expand Down Expand Up @@ -84,14 +81,13 @@ export class JuvixTaskProvider implements vscode.TaskProvider {
},
{
command: 'typecheck',
args: ['${file}', config.getGlobalFlags()],
args: ['${file}'],
group: vscode.TaskGroup.Build,
reveal: setupPanel(),
},
{
command: 'compile',
args: [
config.getGlobalFlags(),
config.getCompilationFlags(),
'${file}',
],
Expand All @@ -100,7 +96,7 @@ export class JuvixTaskProvider implements vscode.TaskProvider {
},
{
command: 'run',
args: ['${file}', config.getGlobalFlags()],
args: ['${file}'],
group: vscode.TaskGroup.Build,
reveal: vscode.TaskRevealKind.Always,
},
Expand All @@ -112,13 +108,13 @@ export class JuvixTaskProvider implements vscode.TaskProvider {
},
{
command: 'dev parse',
args: ['${file}', config.getGlobalFlags()],
args: ['${file}'],
group: vscode.TaskGroup.Build,
reveal: vscode.TaskRevealKind.Always,
},
{
command: 'dev scope',
args: ['${file}', config.getGlobalFlags()],
args: ['${file}'],
group: vscode.TaskGroup.Build,
reveal: vscode.TaskRevealKind.Always,
},
Expand Down Expand Up @@ -167,23 +163,22 @@ export async function JuvixTask(
args: string[]
): Promise<vscode.Task> {
let input = args.join(' ').trim();

let exec: vscode.ProcessExecution | vscode.ShellExecution | undefined;
const config = new user.JuvixConfig();
const JuvixExec = [config.getJuvixExec(), config.getGlobalFlags()].join(' ');
let exec: vscode.ProcessExecution | vscode.ShellExecution | undefined;
switch (name) {
case 'run':
input = args.slice(1).join(' ').trim();
const tmp = path.join(tmpdir(),fs.mkdtempSync('juvix'));
fs.mkdirSync(tmp);
const buildDir = config.getInternalBuildDir();

exec = new vscode.ShellExecution(
config.getJuvixExec() +
` compile --output ${tmp}\${pathSeparator}out ${input} && ${tmp}\${pathSeparator}out && rm -rf \${fileDirname}\${pathSeparator}.juvix-build`
, { cwd: tmp}
JuvixExec +
` compile --output ${buildDir}\${pathSeparator}out ${input} && ${buildDir}\${pathSeparator}out`
, { cwd: buildDir}
);
break;
default:
const call = config.getJuvixExec() + ` ${input}`;
exec = new vscode.ShellExecution(call);
exec = new vscode.ShellExecution(JuvixExec+ ` ${input}`);
break;
}
return new vscode.Task(
Expand Down
4 changes: 3 additions & 1 deletion src/utils/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import * as vscode from 'vscode';

export function isJuvixFile(document: vscode.TextDocument): boolean {
Expand Down
Binary file added test/HelloWorld
Binary file not shown.
2 changes: 1 addition & 1 deletion test/HelloWorld.juvix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module HelloWorld;
open import Stdlib.Prelude;
main : IO;
main := putStrLn "helloasdf world!";
main := putStrLn "hello world!";

end;

0 comments on commit d2e96af

Please sign in to comment.