diff --git a/support/vscode/koka.language-koka/package.json b/support/vscode/koka.language-koka/package.json index 8c55a4c9e..2d9d9eada 100644 --- a/support/vscode/koka.language-koka/package.json +++ b/support/vscode/koka.language-koka/package.json @@ -69,7 +69,7 @@ ], "configuration": { "type": "object", - "title": "Koka configuration", + "title": "Koka", "properties": { "koka.indentationRules.enabled": { "type": "boolean", @@ -125,6 +125,14 @@ "command": "koka.restartLanguageServer", "title": "Koka: Restart Language Server" }, + { + "command": "koka.downloadLatest", + "title": "Koka: Download and Install Latest Version" + }, + { + "command": "koka.uninstall", + "title": "Koka: Uninstall System SDK" + }, { "command": "koka.startWithoutDebugging", "title": "Koka: Run current file" diff --git a/support/vscode/koka.language-koka/src/extension.ts b/support/vscode/koka.language-koka/src/extension.ts index 6516cfedb..9a12e5c87 100644 --- a/support/vscode/koka.language-koka/src/extension.ts +++ b/support/vscode/koka.language-koka/src/extension.ts @@ -9,7 +9,7 @@ import { StreamInfo, } from 'vscode-languageclient/node' -import { KokaConfig, scanForSDK } from './workspace' +import { KokaConfig, downloadSDK, scanForSDK, uninstallSDK } from './workspace' import { CancellationToken, CodeLens, DebugConfiguration, DebugConfigurationProvider, EventEmitter, ProviderResult, TextDocument, WorkspaceFolder } from 'vscode' import { KokaDebugSession } from './debugger' import { AddressInfo, Server, createServer } from 'net' @@ -201,6 +201,12 @@ function createCommands( console.log(`Launch config ${launchConfig}`) vscode.debug.startDebugging(vscode.workspace.getWorkspaceFolder(resource), launchConfig as vscode.DebugConfiguration) }), + vscode.commands.registerCommand('koka.downloadLatest', (resource: vscode.Uri) => { + downloadSDK() + }), + vscode.commands.registerCommand('koka.uninstall', (resource: vscode.Uri) => { + uninstallSDK() + }), vscode.commands.registerCommand('koka.restartLanguageServer', () => { if (!config.get('languageServer.enabled')) return vscode.window.showErrorMessage('Language server is not enabled') diff --git a/support/vscode/koka.language-koka/src/workspace.ts b/support/vscode/koka.language-koka/src/workspace.ts index 8171a053a..ee8690b7a 100644 --- a/support/vscode/koka.language-koka/src/workspace.ts +++ b/support/vscode/koka.language-koka/src/workspace.ts @@ -55,11 +55,52 @@ export function scanForSDK(): SDKs | undefined { if (defaultSDK === "") { console.log('Koka: No Koka SDK found') vs.window.showWarningMessage("Koka SDK not found on path or in ~/.local/bin") + downloadSDK() } else { return { sdkPath: defaultSDK, allSDKs: allSDKs } } } +export async function downloadSDK() { + const decision = await vscode.window.showInformationMessage( + `Download and Install the lastest Koka, continue?`, + { modal: true }, + 'Yes', + 'No' + ) + if (decision == 'No'){ + return + } + let command = "curl -sSL https://github.com/koka-lang/koka/releases/latest/download/install.sh | sh" + if (os.platform() === "win32") { + command = "curl -sSL -o %tmp%\install-koka.bat https://github.com/koka-lang/koka/releases/latest/download/install.bat && %tmp%\install-koka.bat" + } + const term = vscode.window.createTerminal({name: "Install Koka", cwd: process.env.HOME, shellPath: DefaultShellPath, isTransient: true, message: "Installing Koka, restart your editor when finished"}) + term.sendText(command) + term.show() +} + +export async function uninstallSDK() { + const decision = await vscode.window.showInformationMessage( + `Uninstall the system Koka installation, continue?`, + { modal: true }, + 'Yes', + 'No' + ) + if (decision == 'No'){ + return + } + let command = "curl -sSL https://github.com/koka-lang/koka/releases/latest/download/install.sh | sh -s -- -u -f" + if (os.platform() === "win32") { + command = "curl -sSL -o %tmp%\install-koka.bat https://github.com/koka-lang/koka/releases/latest/download/install.bat && %tmp%\install-koka.bat -u -f" + } + const term = vscode.window.createTerminal({name: "Uninstall Koka", cwd: process.env.HOME, shellPath: DefaultShellPath, isTransient: true, message: "Uninstalling Koka, you can close the terminal when done"}) + term.sendText(command) + term.show() +} + +const DefaultShellPath = os.platform() === "win32" ? "C:\Windows\System32\cmd.exe" : null + export class KokaConfig { constructor(config: vscode.WorkspaceConfiguration, sdkPath: string, allSDKs: string[]) { this.config = config diff --git a/util/install.bat b/util/install.bat index d337f5331..7f52eb483 100644 --- a/util/install.bat +++ b/util/install.bat @@ -4,7 +4,7 @@ rem Installation script for Koka; use -h to see command line options. rem ------------------------------------------------------------------ setlocal -set KOKA_VERSION=v2.4.2 +set KOKA_VERSION=v2.4.3 set KOKA_PREFIX=%LOCALAPPDATA%\koka set KOKA_UNINSTALL=N set KOKA_HELP=N diff --git a/util/install.sh b/util/install.sh index 0e3e5ddfc..80e9de862 100755 --- a/util/install.sh +++ b/util/install.sh @@ -4,7 +4,7 @@ # Installation script for Koka; use -h to see command line options. #----------------------------------------------------------------------------- -VERSION="v2.4.2" +VERSION="v2.4.3" MODE="install" # or uninstall PREFIX="/usr/local" QUIET=""