Skip to content

Commit

Permalink
set up envirnoment with one command
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Sep 30, 2022
1 parent 7f0c506 commit 60e0289
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v2.0.2

Execute the command `Install the last version of the language server` and get directly your environment set up.

## v2.0.1

- Add icon for Pharo files and Moosebook file
Expand Down
15 changes: 13 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 24 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Highlighting, Auto-completion, Execution, ...",
"author": "Benoît Verhaeghe",
"license": "MIT",
"version": "2.0.1",
"version": "2.0.2",
"icon": "icon.png",
"repository": {
"type": "git",
Expand All @@ -30,11 +30,15 @@
"onCommand:pharo.extensionVersion",
"onCommand:pharo.printIt",
"onCommand:pharo.showIt",
"onCommand:pharo.installIt",
"onCommand:extension.pharo-debug.debugEditorContents",
"onView:pharoImage",
"onFileSystem:pharoImage",
"onNotebook:moosebook"
],
"extensionDependencies": [
"mindaro-dev.file-downloader"
],
"main": "./dist/extension",
"contributes": {
"configuration": {
Expand Down Expand Up @@ -133,32 +137,44 @@
"commands": [
{
"command": "pharo.extensionVersion",
"title": "Show Pharo Language Server Version"
"title": "Show Pharo Language Server Version",
"category": "Pharo"
},
{
"command": "pharo.save",
"title": "Save the Pharo image"
"title": "Save the Pharo image",
"category": "Pharo"
},
{
"command": "pharo.printIt",
"title": "Print the result of selected lines"
"title": "Print the result of selected lines",
"category": "Pharo"
},
{
"command": "pharo.showIt",
"title": "Show the result of selected lines"
"title": "Show the result of selected lines",
"category": "Pharo"
},
{
"command": "pharo.doIt",
"title": "Execute the result of selected lines"
"title": "Execute the result of selected lines",
"category": "Pharo"
},
{
"command": "pharo.installIt",
"title": "Install the last version of the language server",
"category": "Pharo"
},
{
"command": "pharo.executeTest",
"title": "Execute the test",
"category": "Pharo",
"when": false
},
{
"command": "pharo.executeClassTests",
"title": "Execute all class tests",
"category": "Pharo",
"when": false
},
{
Expand Down Expand Up @@ -300,7 +316,8 @@
"dependencies": {
"@vscode/debugprotocol": "^1.51.0",
"vscode-languageclient": "^8.0.2",
"vscode-languageserver-protocol": "3.17.2"
"vscode-languageserver-protocol": "3.17.2",
"@microsoft/vscode-file-downloader-api": "^1.0.1"
},
"devDependencies": {
"@types/mocha": "^8.0.3",
Expand Down
81 changes: 76 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* ------------------------------------------------------------------------------------------ */

import * as vscode from 'vscode';
import { workspace, ExtensionContext, commands, window, Selection } from 'vscode';
import { workspace, ExtensionContext, commands, window, Uri, Selection } from 'vscode';
import {
LanguageClient,
LanguageClientOptions,
Expand All @@ -23,11 +23,23 @@ import { PharoDocumentExplorer } from './treeProvider/documentBinding';
import { sign } from 'crypto';
import { MoosebookSerializer } from './moosebook/MoosebookSerializer'
import { MoosebookController } from './moosebook/MoosebookController';
const os = require('os');

import { getApi, FileDownloader } from "@microsoft/vscode-file-downloader-api";


export let client: LanguageClient;
let documentExplorer: PharoDocumentExplorer;
let dls: child_process.ChildProcess;
export let extensionContext: ExtensionContext;


export async function activate(context: ExtensionContext) {

extensionContext = context;
// Create new command
createCommands(context);

// Testing Pharo can be used
return requirements.resolveRequirements().catch(error => {
window.showErrorMessage(error.message, error.label).then((selection) => {
Expand All @@ -46,9 +58,6 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(client);
window.showInformationMessage('Client started');

// Create new command
createCommands(context);

new PharoImageExplorer(context);
documentExplorer = new PharoDocumentExplorer(context);

Expand All @@ -69,6 +78,8 @@ function createCommands(context: ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand('pharo.save', commandPharoSave));
context.subscriptions.push(vscode.commands.registerCommand('pharo.executeTest', commandPharoExecuteTest));
context.subscriptions.push(vscode.commands.registerCommand('pharo.executeClassTests', commandPharoExecuteClassTests));
context.subscriptions.push(vscode.commands.registerCommand('pharo.installIt', commandPharoInstallLastVersion));

}


Expand Down Expand Up @@ -133,6 +144,67 @@ function commandPharoExecuteClassTests(aClass: string) {
}).catch((error) => window.showErrorMessage(error));
}

export async function commandPharoInstallLastVersion() {

if(dls !== undefined){
dls.kill(9);
}

// Download pharo VM

let vmPath = ''
if (os.platform() == 'linux') {
vmPath = 'https://files.pharo.org/get-files/100/pharo64-linux-stable.zip'
} else if (os.platform() == 'darwin') {
vmPath = 'https://files.pharo.org/get-files/100/pharo64-mac-stable.zip'
} else {
vmPath = 'https://files.pharo.org/get-files/100/pharo-vm-Windows-x86_64-stable.zip'
}

let vmDirectory = await download(Uri.parse(vmPath), true, 'pharoVM');
vscode.workspace.getConfiguration('pharo').update('pathToVM', vmDirectory.fsPath + "\\Pharo.exe", true);
window.showInformationMessage('VM updated. Please wait')

// Download image
let imageName = 'Moose64-10-PLS'
let pharoDirectory = await download(Uri.parse("https://github.com/badetitou/Pharo-LanguageServer/releases/download/v3.0.2/" + imageName + ".zip"), true, imageName);
vscode.workspace.getConfiguration('pharo').update('pathToImage', pharoDirectory.fsPath + "\\" + imageName + ".image", true);
window.showInformationMessage('Pharo updated. Please restart', 'Restart VSCode').then(() => {
commands.executeCommand('workbench.action.reloadWindow');
})
}


async function download(uri: Uri, unzip: boolean, location: string): Promise<vscode.Uri> {

// let mooseImageUri = Uri.parse("", true);
const fileDownloader: FileDownloader = await getApi();
console.log('Download ', uri)
console.log('Download ', uri.toString())
// update to string
uri.toString = (skipEncoding?: boolean): string => {
return uri.scheme + "://" + uri.authority + uri.path + "?" + uri.query
}
console.log('Download ', uri.toString())


const cancellationTokenSource = new vscode.CancellationTokenSource();
const cancellationToken = cancellationTokenSource.token;

const progressCallback = (downloadedBytes: number, totalBytes: number | undefined) => {
console.log(`Downloaded ${downloadedBytes}/${totalBytes} bytes`);
};
const vmDirectory: Uri = await fileDownloader.downloadFile(
uri,
location,
extensionContext,
cancellationToken,
progressCallback,
{ shouldUnzip: unzip }
);
return vmDirectory;
}

/*
* Section with function for Pharo Language Server
*/
Expand Down Expand Up @@ -163,7 +235,6 @@ function createPharoLanguageServer(requirements: requirements.RequirementsData,
}

async function createServerWithSocket(pharoPath: string, pathToImage: string, context: ExtensionContext): Promise<StreamInfo> {
let dls: child_process.ChildProcess;

let options = [ pathToImage, 'st', context.asAbsolutePath('/res/run-server.st') ];
if (vscode.workspace.getConfiguration('pharo').get('headless') && !vscode.workspace.getConfiguration('pharo').get('debugMode')) {
Expand Down

0 comments on commit 60e0289

Please sign in to comment.