Skip to content

Commit

Permalink
add install / uninstall commands
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWhiting committed Oct 23, 2023
1 parent 4ada32e commit 1852cb2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
10 changes: 9 additions & 1 deletion support/vscode/koka.language-koka/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
],
"configuration": {
"type": "object",
"title": "Koka configuration",
"title": "Koka",
"properties": {
"koka.indentationRules.enabled": {
"type": "boolean",
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion support/vscode/koka.language-koka/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand Down
41 changes: 41 additions & 0 deletions support/vscode/koka.language-koka/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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, 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
Expand Down
2 changes: 1 addition & 1 deletion util/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion util/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down

0 comments on commit 1852cb2

Please sign in to comment.