Skip to content
Snippets Groups Projects
Commit f42fd98c authored by Stekelenburg, A.V. (Alexander, Student )'s avatar Stekelenburg, A.V. (Alexander, Student )
Browse files

Send the tool names to the webview even if the webview loads after the server is ready

parent 70accc23
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,8 @@
*/
const toolDropDown = document.getElementById("tools");
toolDropDown.addEventListener('change', event => {
vscode.postMessage({ type: "toolSelected", toolName: toolDropDown.options[toolDropDown.selectedIndex].value })
})
vscode.postMessage({ type: "toolSelected", toolName: toolDropDown.options[toolDropDown.selectedIndex].value });
});
// Handle messages sent from the extension to the webview
window.addEventListener('message', event => {
......@@ -93,4 +93,6 @@
vscode.setState({ definedConstants: definedConstants, undefinedConstants: undefinedConstants, options: options });
}
vscode.postMessage({ type: "init" });
}());
......@@ -22,6 +22,7 @@ import { fstat, existsSync } from 'fs';
export let client: LanguageClient | undefined;
export let provider: ModestSidebarProvider;
let toolNames: Array<string> | undefined;
interface ModestTools {
availableTools: Array<ModestTool>
......@@ -121,7 +122,7 @@ function createClient(): LanguageClient | undefined {
client.trace = Trace.Verbose;
client.onReady().then(() =>
initializeTools()
)
);
return client;
}
......@@ -160,21 +161,21 @@ export function activate(context: ExtensionContext) {
export function initializeTools() {
client?.sendRequest<any>("modest/getTools").then(data => {
const toolNames: Array<string> = data.availableTools;
toolNames = data.availableTools;
provider.sendMessage({
type: "fillTools",
tools: toolNames
})
})
});
});
}
export function getParameters(toolName: string) {
let uri = vscode.window.activeTextEditor?.document.uri;
if (uri) {
let JSONObject = { "TextDocument": TextDocumentIdentifier.create(uri.toString()), "ToolName": toolName }
let JSONObject = { "TextDocument": TextDocumentIdentifier.create(uri.toString()), "ToolName": toolName };
client?.sendRequest<any>("modest/getParameters", JSONObject).then(data => {
console.log(data);
})
});
}
}
......@@ -210,13 +211,20 @@ class ModestSidebarProvider implements vscode.WebviewViewProvider {
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
webviewView.webview.onDidReceiveMessage(data => {
console.log(data)
console.log(data);
switch (data.type) {
case 'toolSelected':
{
getParameters(data.toolName);
break;
case 'init': {
if (toolNames) {
provider.sendMessage({
type: "fillTools",
tools: toolNames
});
}
}
case 'toolSelected': {
getParameters(data.toolName);
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