Skip to content
Snippets Groups Projects
Commit b50484fb authored by s1995588's avatar s1995588
Browse files

changed some variable names and added distributions

parent bd0a80b3
No related branches found
No related tags found
No related merge requests found
......@@ -12,7 +12,7 @@
toolDropDown.addEventListener('change', event => {
var oldState = vscode.getState();
var currentTool = toolDropDown.options[toolDropDown.selectedIndex].value;
vscode.setState({ tools: oldState.tools, constants: oldState.constants, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: currentTool });
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: currentTool });
vscode.postMessage({ type: "toolSelected", toolName: currentTool });
});
......@@ -21,9 +21,9 @@
const message = event.data; // The json data that the extension sent
console.log("Received message");
switch (message.type) {
case 'updateConstants':
case 'updateDocumentVars':
{
updateConstants(message.constants, message.uri);
updateDocumentVars(message.documentVars, message.uri);
break;
}
case 'updateParameters':
......@@ -42,7 +42,7 @@
const runButton = document.getElementById("run-button");
runButton.addEventListener("click", event => {
const state = vscode.getState();
for (const file of state.constants) {
for (const file of state.documentVars) {
if (file.uri === state.currentUri) {
for (const tool of state.parameters) {
if (tool.toolName === state.currentTool) {
......@@ -71,7 +71,7 @@
vscode.postMessage({ type: "toolSelected", toolName: oldState.currentTool });
vscode.setState({ tools: tools, constants: oldState.constants, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
vscode.setState({ tools: tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
}
function addConstantItem(ul, name, value) {
......@@ -91,7 +91,7 @@
valueBox.classList.add("value");
valueBox.addEventListener("input", event => {
let oldState = vscode.getState();
for (const file of oldState.constants) {
for (const file of oldState.documentVars) {
if (file.uri === oldState.currentUri) {
for (const constant of file.constants) {
if (constant.name === name) {
......@@ -102,7 +102,7 @@
break;
}
}
vscode.setState({ tools: oldState.tools, constants: oldState.constants, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
......@@ -138,7 +138,7 @@
break;
}
}
vscode.setState({ tools: oldState.tools, constants: oldState.constants, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: oldState.parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
});
li.appendChild(valueBox);
......@@ -148,36 +148,36 @@
/**
*
* @param {Array<{ uri: string, constants: Array<{ name: string, value: string }> }>} constants
* @param {Array<{ uri: string, constants: Array<{ name: string, value: string }>, distributions: Array<{ name: string, value: string }> }>} documentVars
* @param {string} uri
*/
function updateConstants(constants, uri) {
function updateDocumentVars(documentVars, uri) {
const constantsUl = document.querySelector("#constants");
const oldState = vscode.getState();
// combines the oldstate constants with the "new" constants.
for (const file of constants) {
const index = oldState.constants.findIndex(x => x.uri === file.uri);
for (const file of documentVars) {
const index = oldState.documentVars.findIndex(x => x.uri === file.uri);
if (index !== -1) {
for (const constant of file.constants) {
const oldConstantIndex = oldState.constants[index].constants.findIndex(x => x.name === constant.name);
const oldConstantIndex = oldState.documentVars[index].constants.findIndex(x => x.name === constant.name);
if (oldConstantIndex !== -1) {
constant.value = oldState.constants[index].constants[oldConstantIndex].value;
constant.value = oldState.documentVars[index].constants[oldConstantIndex].value;
}
}
}
}
for (const file of oldState.constants) {
const index = constants.findIndex(x => x.uri === file.uri);
for (const file of oldState.documentVars) {
const index = documentVars.findIndex(x => x.uri === file.uri);
if (index === -1) {
constants.push(file);
documentVars.push(file);
}
}
constantsUl.innerHTML = "";
// adds the constants to the sidebar.
for (const file of constants) {
for (const file of documentVars) {
if (file.uri === uri) {
for (const constant of file.constants) {
addConstantItem(constantsUl, constant.name, constant.value);
......@@ -190,7 +190,7 @@
constantsUl.innerHTML = "There are no undefined constants.";
}
vscode.setState({ tools: oldState.tools, constants: constants, parameters: oldState.parameters, currentUri: uri, currentTool: oldState.currentTool });
vscode.setState({ tools: oldState.tools, documentVars: documentVars, parameters: oldState.parameters, currentUri: uri, currentTool: oldState.currentTool });
}
/**
......@@ -232,13 +232,13 @@
}
}
vscode.setState({ tools: oldState.tools, constants: oldState.constants, parameters: parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
vscode.setState({ tools: oldState.tools, documentVars: oldState.documentVars, parameters: parameters, currentUri: oldState.currentUri, currentTool: oldState.currentTool });
}
const oldState = vscode.getState() || { tools: [], constants: [], parameters: [], currentUri: "", currentTool: "" };
const oldState = vscode.getState() || { tools: [], documentVars: [], parameters: [], currentUri: "", currentTool: "" };
const tools = oldState.tools;
const constants = oldState.constants;
const documentVars = oldState.documentVars;
const parameters = oldState.parameters;
const currentUri = oldState.currentUri;
const currentTool = oldState.currentTool;
......@@ -248,6 +248,6 @@
} else {
fillTools(tools);
updateParameters(parameters, currentTool);
updateConstants(constants, currentUri);
updateDocumentVars(documentVars, currentUri);
}
}());
......@@ -13,7 +13,7 @@ import {
} from "vscode-languageclient/node";
import { AnalysisResultsProvider, Result } from "./analysisResults";
import { ModestCommands } from "./commands";
import { getConstants, initializeTools, ModestSidebarProvider } from "./sidebar";
import { getDocumentVars, initializeTools, ModestSidebarProvider } from "./sidebar";
export let client: LanguageClient | undefined;
export let provider: ModestSidebarProvider;
......@@ -151,12 +151,12 @@ export function activate(context: ExtensionContext) {
vscode.window.onDidChangeActiveTextEditor(textEditor => {
if (textEditor) {
getConstants(textEditor.document);
getDocumentVars(textEditor.document);
}
});
vscode.workspace.onDidSaveTextDocument(textEditor => {
getConstants(textEditor);
getDocumentVars(textEditor);
});
//#endregion
......
......@@ -10,9 +10,9 @@ import {
import { analysisResultsProvider, client, provider } from './extension';
export let toolNames: Array<string> | undefined;
export let constants: Array<{ uri: string, constants: Array<{ name: string, value: string }> }> = [];
export let parameters: Array<{ toolName: string, parameters: Array<{ id: string, value: string, type: ParameterType, category: string }> }> = [];
export let localToolNames: Array<string> | undefined;
export let localDocumentVars: Array<{ uri: string, constants: Array<{ name: string, value: string }>, distributions: Array<{ name: string, value: string }> }> = [];
export let localParameters: Array<{ toolName: string, parameters: Array<{ id: string, defaultValue: string, type: ParameterType, category: string }> }> = [];
//#region interfaces
interface ParameterDefinitions {
......@@ -47,32 +47,36 @@ interface ResultNotification {
export function initializeTools() {
client?.sendRequest<any>("modest/getTools").then(data => {
toolNames = data.availableTools;
localToolNames = data.availableTools;
provider.sendMessage({
type: "fillTools",
tools: toolNames
tools: localToolNames
});
});
}
export function getConstants(document: TextDocument) {
export function getDocumentVars(document: TextDocument) {
if (document.languageId === "modest") {
if (document.uri) {
let uri = document.uri.toString();
let jsonObject = { "textDocument": TextDocumentIdentifier.create(uri) };
client?.sendRequest<Array<string>>("modest/getConstants", jsonObject).then(data => {
const index = constants.findIndex(x => x.uri === uri);
const newConstants = data.map(constant => {
client?.sendRequest<{ constants: Array<string>, distributions: Array<string> }>("modest/getDocumentVars", jsonObject).then(data => {
const index = localDocumentVars.findIndex(x => x.uri === uri);
const newConstants = data.constants.map(constant => {
return { name: constant, value: "" };
});
const newDistributions = data.distributions.map(distribution => {
return { name: distribution, value: "" };
});
if (index === -1) {
constants.push({ "uri": uri, constants: newConstants });
localDocumentVars.push({ "uri": uri, constants: newConstants, distributions: newDistributions });
} else {
constants[index].constants = newConstants;
localDocumentVars[index].constants = newConstants;
localDocumentVars[index].distributions = newDistributions;
}
provider.sendMessage({
type: "updateConstants",
constants: constants,
type: "updateDocumentVars",
documentVars: localDocumentVars,
"uri": uri
});
});
......@@ -83,31 +87,31 @@ export function getConstants(document: TextDocument) {
function getParameters(toolName: string) {
let jsonObject = { "toolName": toolName };
client?.sendRequest<ParameterDefinitions>("modest/getParameters", jsonObject).then(data => {
const index = parameters.findIndex(x => x.toolName === toolName);
const index = localParameters.findIndex(x => x.toolName === toolName);
const newParameters = data.parameterDefinitions.map(parameter => {
return { id: parameter.id, value: parameter.defaultValue, type: parameter.type, category: parameter.category };
return { id: parameter.id, defaultValue: parameter.defaultValue, type: parameter.type, category: parameter.category };
});
if (index === -1) {
parameters.push({ toolName: toolName, parameters: newParameters });
localParameters.push({ toolName: toolName, parameters: newParameters });
} else {
parameters[index].parameters = newParameters;
localParameters[index].parameters = newParameters;
}
provider.sendMessage({
type: "updateParameters",
parameters: parameters,
parameters: localParameters,
toolName: toolName
});
});
}
function runTool(uri: string, toolName: string, constants: { name: string; value: string; }[], suppliedParameters: { id: string; value: string; }[]) {
const toolIndex = parameters.findIndex(x => x.toolName === toolName);
const toolIndex = localParameters.findIndex(x => x.toolName === toolName);
let serverParameters: Array<{ id: string, value: string }> = [];
if (toolIndex !== -1) {
for (const parameter of suppliedParameters) {
const parameterIndex = parameters[toolIndex].parameters.findIndex(x => x.id === parameter.id);
const parameterIndex = localParameters[toolIndex].parameters.findIndex(x => x.id === parameter.id);
if (parameterIndex !== -1) {
if (parameters[toolIndex].parameters[parameterIndex].value !== parameter.value) {
if (localParameters[toolIndex].parameters[parameterIndex].defaultValue !== parameter.value) {
serverParameters.push(parameter);
}
}
......@@ -132,7 +136,7 @@ function runTool(uri: string, toolName: string, constants: { name: string; value
if (data.data && data.data !== "") {
try {
analysisResultsProvider.setJsonString(data.data);
} catch(error) {
} catch (error) {
console.error(error);
}
}
......@@ -176,16 +180,16 @@ export class ModestSidebarProvider implements vscode.WebviewViewProvider {
console.log(data);
switch (data.type) {
case 'init': {
if (toolNames) {
if (localToolNames) {
provider.sendMessage({
type: "fillTools",
tools: toolNames
tools: localToolNames
});
}
if (constants) {
if (localDocumentVars) {
provider.sendMessage({
type: "updateConstants",
constants: constants
type: "updateDocumentVars",
documentVars: localDocumentVars
});
}
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment