Skip to content

Commit

Permalink
Set Juvix binary path in user settings and some other revisions (#110)
Browse files Browse the repository at this point in the history
- Fix #109
  • Loading branch information
jonaprieto authored Jun 9, 2023
1 parent d5e5f9f commit 567d0f3
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 69 deletions.
50 changes: 30 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"onLanguage:JuvixAsm",
"onLanguage:JuvixCore",
"onLanguage:JuvixGeb",
"onLanguage:VampIR"
"onLanguage:VampIR",
"onCommand:juvix-mode.installJuvixBinary"
],
"main": "./out/extension.js",
"scripts": {
Expand Down Expand Up @@ -486,6 +487,11 @@
}
],
"commands": [
{
"command": "juvix-mode.installJuvixBinary",
"title": "Install Juvix Binary",
"category": "Juvix"
},
{
"command": "juvix-mode.getBinaryVersion",
"title": "about",
Expand Down Expand Up @@ -705,77 +711,77 @@
"menus": {
"editor/title": [
{
"when": "editorLangId == Juvix || editorLangId == JuvixCore || editorLangId == JuvixGeb",
"when": "juvix-mode:ready && (editorLangId == Juvix || editorLangId == JuvixCore || editorLangId == JuvixGeb)",
"command": "juvix-mode.loadFileRepl",
"group": "navigation@0"
},
{
"when": "editorLangId == Juvix",
"when": "juvix-mode:ready && editorLangId == Juvix",
"command": "juvix-mode.typecheck",
"group": "navigation@1"
},
{
"when": "editorLangId == Juvix",
"when": "juvix-mode:ready && editorLangId == Juvix",
"command": "juvix-mode.compile",
"group": "navigation@2"
},
{
"when": "editorLangId == Juvix",
"when": "juvix-mode:ready && editorLangId == Juvix",
"command": "juvix-mode.run",
"group": "navigation@3"
},
{
"when": "editorLangId == JuvixCore",
"when": "juvix-mode:ready && editorLangId == JuvixCore",
"command": "juvix-mode.core-compile",
"group": "navigation@2"
},
{
"when": "editorLangId == JuvixCore",
"when": "juvix-mode:ready && editorLangId == JuvixCore",
"command": "juvix-mode.core-eval",
"group": "navigation@3"
},
{
"when": "editorLangId == JuvixGeb",
"when": "juvix-mode:ready && editorLangId == JuvixGeb",
"command": "juvix-mode.geb-check",
"group": "navigation@1"
},
{
"when": "editorLangId == JuvixGeb",
"when": "juvix-mode:ready && editorLangId == JuvixGeb",
"command": "juvix-mode.geb-compile",
"group": "navigation@2"
},
{
"when": "editorLangId == JuvixGeb",
"when": "juvix-mode:ready && editorLangId == JuvixGeb",
"command": "juvix-mode.geb-eval",
"group": "navigation@3"
},
{
"when": "editorLangId == VampIR",
"when": "juvix-mode:ready && editorLangId == VampIR",
"command": "juvix-mode.vampir-setup",
"group": "navigation@0"
},
{
"when": "editorLangId == VampIR",
"when": "juvix-mode:ready && editorLangId == VampIR",
"command": "juvix-mode.vampir-compile",
"group": "navigation@1"
},
{
"when": "editorLangId == VampIR",
"when": "juvix-mode:ready && editorLangId == VampIR",
"command": "juvix-mode.vampir-prove",
"group": "navigation@2"
},
{
"when": "editorLangId == VampIR",
"when": "juvix-mode:ready && editorLangId == VampIR",
"command": "juvix-mode.vampir-verify",
"group": "navigation@3"
},
{
"when": "editorLangId == Juvix",
"when": "juvix-mode:ready && editorLangId == Juvix",
"command": "juvix-mode.createOrShowJudoc",
"group": "navigation@4"
},
{
"when": "editorLangId == Juvix",
"when": "juvix-mode:ready && editorLangId == Juvix",
"command": "juvix-mode.createOrShowJudocOnlySource",
"group": "navigation@5"
}
Expand All @@ -784,7 +790,7 @@
{
"submenu": "juvix-submenu",
"group": "navigation",
"when": "editorLangId == Juvix"
"when": "juvix-mode:ready && editorLangId == Juvix"
}
],
"juvix-submenu": [
Expand All @@ -803,23 +809,27 @@
{
"command": "juvix-mode.doctor",
"group": "[email protected]"
},
{
"command": "juvix-mode.createOrShowJudoc",
"group": "[email protected]"
}
]
},
"configuration": {
"title": "Juvix Mode",
"properties": {
"juvix-mode.bin.name": {
"juvix-mode.juvixBinName": {
"type": "string",
"default": "juvix",
"scope": "machine-overridable",
"description": "Name of the executable of Juvix. (e.g. juvix-v0.3.0)"
},
"juvix-mode.bin.path": {
"juvix-mode.juvixBinPath": {
"type": "string",
"default": "",
"scope": "machine-overridable",
"description": "Absolute path to the executable of Juvix. (e.g. /usr/local/bin/)"
"description": "Absolute path where the Juvix binary is located (e.g. /usr/local/bin/)"
},
"juvix-mode.vampirBinName": {
"type": "string",
Expand Down
61 changes: 45 additions & 16 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ import * as fs from 'fs';
import * as path from 'path';
import { tmpdir } from 'os';
import { logger } from './utils/debug';
import { ConfigurationTarget } from 'vscode';

export class JuvixConfig {
readonly binaryName = new VsCodeSetting('juvix-mode.bin.name', {
serializer: serializerWithDefault('Juvix'),
readonly binaryName = new VsCodeSetting('juvix-mode.juvixBinName', {
serializer: serializerWithDefault('juvix')
});

readonly binaryPath = new VsCodeSetting('juvix-mode.bin.path', {
serializer: serializerWithDefault(''),
readonly binaryPath = new VsCodeSetting('juvix-mode.juvixBinPath', {
serializer: serializerWithDefault('')
});

public getJuvixExec(): string {
return path.join(this.binaryPath.get(), this.binaryName.get());
let binPath = this.binaryPath.get();
let binName = this.binaryName.get();
logger.debug(`binPath: ${binPath}`);
logger.debug(`binName: ${binName}`);
return path.join(binPath, binName);
}

public setJuvixExec(juvixExec: string): void {
Expand All @@ -31,9 +36,11 @@ export class JuvixConfig {
// geb settings
readonly vampirBinaryName = new VsCodeSetting('juvix-mode.vampirBinName', {
serializer: serializerWithDefault('vamp-ir'),
target: ConfigurationTarget.Global,
});
readonly vampirBinaryPath = new VsCodeSetting('juvix-mode.vampirBinPath', {
serializer: serializerWithDefault(''),
target: ConfigurationTarget.Global,
});

public getVampirExec(): string {
Expand All @@ -43,30 +50,52 @@ export class JuvixConfig {
// Geb settings
readonly gebBinaryName = new VsCodeSetting('juvix-mode.gebName', {
serializer: serializerWithDefault('geb.image'),
target: ConfigurationTarget.Global,
});
readonly gebBinaryPath = new VsCodeSetting('juvix-mode.gebBinPath', {
serializer: serializerWithDefault(''),
target: ConfigurationTarget.Global,
});

public getGebExec(): string {
return path.join(this.gebBinaryPath.get(), this.gebBinaryName.get());
}

readonly revealPanel = new VsCodeSetting('juvix-mode.revealPanel');
readonly typecheckOn = new VsCodeSetting('juvix-mode.typecheckOn');
readonly revealPanel = new VsCodeSetting('juvix-mode.revealPanel', {
target: ConfigurationTarget.Global,
});
readonly typecheckOn = new VsCodeSetting('juvix-mode.typecheckOn', {
target: ConfigurationTarget.Global,
});

readonly noColors = new VsCodeSetting('juvix-mode.opts.noColors');
readonly noColors = new VsCodeSetting('juvix-mode.opts.noColors', {
target: ConfigurationTarget.Global,
});

readonly showNameIds = new VsCodeSetting('juvix-mode.opts.showNameIds');
readonly onlyErrors = new VsCodeSetting('juvix-mode.opts.onlyErrors');
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 showNameIds = new VsCodeSetting('juvix-mode.opts.showNameIds', {
target: ConfigurationTarget.Global,
});
readonly onlyErrors = new VsCodeSetting('juvix-mode.opts.onlyErrors', {
target: ConfigurationTarget.Global,
});
readonly noTermination = new VsCodeSetting('juvix-mode.opts.noTermination', {
target: ConfigurationTarget.Global,
});
readonly noPositivity = new VsCodeSetting('juvix-mode.opts.noPositivity', {
target: ConfigurationTarget.Global,
});
readonly noStdlib = new VsCodeSetting('juvix-mode.opts.noStdlib', {
target: ConfigurationTarget.Global,
});
readonly internalBuildDir = new VsCodeSetting(
'juvix-mode.opts.internalBuildDir'
'juvix-mode.opts.internalBuildDir',
{
target: ConfigurationTarget.Global,
}
);

readonly judocDir = new VsCodeSetting('juvix-mode.opts.judocDir');
readonly judocDir = new VsCodeSetting('juvix-mode.opts.judocDir', {
target: ConfigurationTarget.Global,
});

public getInternalBuildDir(): string | undefined {
const useTmpDir = () => {
Expand Down
53 changes: 36 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
'use strict';

import * as vscode from 'vscode';
import * as check from './check';
import * as codelens from './codelens';
Expand All @@ -18,24 +17,44 @@ import * as statusBar from './statusbar';
import * as tasks from './tasks';
import * as vampir from './vampir/tasks';
import * as installer from './installer';
import { checkForUpgrade, checkJuvixBinary } from './juvixVersion';
import { checkForUpgrade, checkJuvixBinary, juvixIsNotInstalled } from './juvixVersion';
import { logger } from './utils/debug'
import { config } from './config';

export async function activate(context: vscode.ExtensionContext) {
logger.debug("Activating Juvix Mode");
logger.debug("Initial config: " + config.getJuvixExec());
installer.activate(context);
checkJuvixBinary().then(version => {
statusBar.activate(context, version);

let version = checkJuvixBinary();
vscode.commands.executeCommand('setContext', "juvix-mode:ready", false);

if (!version) {
logger.debug("Juvix binary not found, installing...");
juvixIsNotInstalled().then(() => {
version = checkJuvixBinary();
});
}
if (version !== undefined) {
logger.debug("Juvix version detected: " + version);
checkForUpgrade(version);
codelens.activate(context);
syntaxHighlighter.activate(context);
goToDefinition.activate(context);
hoverInfo.activate(context);
tasks.activate(context);
inputMethod.activate(context);
repl.activate(context);
judoc.activate(context);
check.activate(context);
formatter.activate(context);
vampir.activate(context);
dev.activate(context);
});
statusBar.activate(context, version);

const modules = [
codelens,
syntaxHighlighter,
goToDefinition,
hoverInfo,
tasks,
inputMethod,
repl,
judoc,
check,
formatter,
vampir,
dev
];
modules.forEach(module => module.activate(context));
vscode.commands.executeCommand('setContext', "juvix-mode:ready", true);
}
}
14 changes: 10 additions & 4 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import { exit } from 'process';
import * as vscode from 'vscode';
import { logger } from './utils/debug';
import { config } from './config';
import { env } from 'process';
import * as path from 'path';

const userHome = env['XDG_BIN_HOME'] || env.HOME || '~';
const INSTALLBIN_PATH = path.join(userHome, '.local', 'bin');

export class Installer {
private terminal: vscode.Terminal;
Expand Down Expand Up @@ -35,16 +41,16 @@ export class Installer {
disposeToken.dispose();
if (this.terminal.exitStatus !== undefined) {
resolve(this.terminal.exitStatus);
config.binaryPath.set(INSTALLBIN_PATH);
vscode.window
.showInformationMessage(
'Juvix binary installation complete.',
'Reload window'
)
.then(selection => {
if (selection === 'Reload window') {
vscode.commands.executeCommand(
'workbench.action.reloadWindow'
);
vscode.window.terminals.forEach(t => t.dispose());
vscode.commands.executeCommand( 'workbench.action.reloadWindow' );
}
});
} else reject('Terminal exited with undefined status');
Expand Down Expand Up @@ -101,7 +107,7 @@ export async function installJuvix() {

export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('juvix-mode.installBinary', () => {
vscode.commands.registerCommand('juvix-mode.installJuvixBinary', () => {
installJuvix();
})
);
Expand Down
Loading

0 comments on commit 567d0f3

Please sign in to comment.