Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Vscode injection #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions client/src/session/SessionRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { QuickDiffProvider, Uri, CancellationToken, ProviderResult, WorkspaceFolder, workspace } from "vscode";
import { QuickDiffProvider, window, Uri, CancellationToken, ProviderResult, WorkspaceFolder, workspace } from "vscode";
import * as vscode from 'vscode';
import * as path from 'path';
import { compareMaps } from "../utils";
import { SessionConfiguration, strMapToObj, SessionMode } from "./SessionConfiguration";
Expand Down Expand Up @@ -165,7 +166,6 @@ export async function duplicateSession(session: SessionContent): Promise<string>
}

const SAVE_TABS_PLUGIN_NAME = "save-tabs";
const SOLVER_PLUGIN_NAME = "solver";

/**
* Fetches session from the planning.domains server.
Expand Down Expand Up @@ -207,11 +207,26 @@ async function getRawSession(sessionConfiguration: SessionConfiguration): Promis
if(pluginsMatch = SESSION_PLUGINS_PATTERN.exec(sessionContent)) {
let rawPlugins = JSON.parse(pluginsMatch[1]);

[SAVE_TABS_PLUGIN_NAME, SOLVER_PLUGIN_NAME].forEach(pluginName => {
if (rawPlugins.hasOwnProperty(pluginName)) {
plugins.set(pluginName, toRawSessionPlugin(pluginName, rawPlugins[pluginName]));
// Save all of the plugins found (even if we don't use them all)
for (let pluginName in rawPlugins) {
plugins.set(pluginName, toRawSessionPlugin(pluginName, rawPlugins[pluginName]));

// Process vscode injection components
if (rawPlugins[pluginName]['settings'].hasOwnProperty('vscode-injection')) {
// Confirm with user (since we're using eval)
let answer = await window.showQuickPick(["Yes", "No"],
{ placeHolder: `Allow code injection from ${pluginName} extension?` });
if (answer === "Yes") {
try {
var vscode_settings = {vscode: vscode};
var cb = eval(rawPlugins[pluginName]['settings']['vscode-injection']);
cb(rawPlugins[pluginName]['settings'], vscode_settings);
} catch (ex) {
throw new Error("Failed to run plugin's vscode injection code: " + ex);
}
}
}
});
}
}
else {
console.log("Malformed saved session plugins. Could not extract session plugins. Session content:" + sessionContent);
Expand Down
17 changes: 0 additions & 17 deletions client/src/session/SessionSourceControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { toFuzzyRelativeTime } from '../utils';
import * as afs from '../../../common/src/asyncfs';
import * as fs from 'fs';
import { SessionConfiguration, saveConfiguration, SessionMode, toSessionConfiguration, CONFIGURATION_FILE } from './SessionConfiguration';
import { PDDL_PLANNER, EXECUTABLE_OR_SERVICE } from '../configuration';

/**
* Command for cloning a session to the local storage.
Expand Down Expand Up @@ -226,8 +225,6 @@ export class SessionSourceControl implements vscode.Disposable {
if (overwrite) { this.resetFilesToCheckedOutVersion(); } // overwrite local file content
this._onRepositoryChange.fire(this.session);
await this.updateChangedGroup();
await this.saveWorkspaceSettings();

await this.saveCurrentConfiguration();
}

Expand All @@ -252,20 +249,6 @@ export class SessionSourceControl implements vscode.Disposable {
return await saveConfiguration(this.workspaceFolder.uri, this.session);
}

private static readonly SOLVER_PLUGIN = "solver";

/** Saves setting of eligible session plugins to workspace configuration. */
async saveWorkspaceSettings(): Promise<void> {
if (this.session.plugins.has(SessionSourceControl.SOLVER_PLUGIN)) {
let solver = this.session.plugins.get(SessionSourceControl.SOLVER_PLUGIN);
if (solver.url !== "/plugins/solver.js") { return; }

let solverUrl = solver.settings["url"];

await vscode.workspace.getConfiguration(PDDL_PLANNER, this.workspaceFolder.uri).update(EXECUTABLE_OR_SERVICE, solverUrl + "/solve", vscode.ConfigurationTarget.WorkspaceFolder);
}
}

/**
* Refresh is used when the information on the server may have changed.
* For example another user updates the session files online.
Expand Down