* Implements languageId support

* Implements typing of helper functions
* Shift+F1 opens a new debug visualizer window if none is opened yet
This commit is contained in:
Henning Dieterichs
2020-03-29 15:16:46 +02:00
parent 213f4cda8f
commit 42e58ce9cf
14 changed files with 158 additions and 50 deletions

View File

@@ -4,8 +4,11 @@ import {
} from "debug-visualizer/src/contract";
import { WebSocketStream } from "@hediet/typed-json-rpc-websocket";
import { ConsoleRpcLogger } from "@hediet/typed-json-rpc";
import { observable, action, computed, when } from "mobx";
import { DataExtractorId } from "@hediet/debug-visualizer-data-extraction";
import { observable, action, computed, when, runInAction } from "mobx";
import {
DataExtractorId,
ExtractedData,
} from "@hediet/debug-visualizer-data-extraction";
import {
Visualization,
VisualizationId,
@@ -21,6 +24,7 @@ declare const window: Window & {
serverSecret: string;
serverPort: number;
publicPath: string;
expression: string | undefined;
};
};
@@ -38,10 +42,15 @@ export class Model {
private serverSecret: string;
@observable expression: string = "";
@observable state: DataExtractionState | { kind: "noExpression" } = {
@observable state:
| DataExtractionState
| { kind: "noExpression" }
| { kind: "visualizationError"; data: ExtractedData } = {
kind: "noExpression",
};
@observable languageId: string = "text";
@observable private preferredVisualizationId:
| VisualizationId
| undefined = undefined;
@@ -51,6 +60,11 @@ export class Model {
this.preferredVisualizationId = id;
}
@action
public setVisualizationError(data: ExtractedData) {
this.state = { kind: "visualizationError", data: data };
}
@computed get visualizations():
| {
visualization: Visualization | undefined;
@@ -99,6 +113,10 @@ export class Model {
};
updateTheme();
if (data.expression !== undefined) {
this.setExpression(data.expression);
}
this.dispose.track(
startInterval(1000, () => {
updateTheme();
@@ -191,14 +209,19 @@ export class Model {
new ConsoleRpcLogger(),
{
updateState: async ({ newState }) => {
this._loading = newState.kind === "loading";
if (!this._loading) {
this.state = newState;
}
runInAction(() => {
this._loading = newState.kind === "loading";
if (!this._loading) {
this.state = newState;
}
});
},
setExpression: async ({ expression }) => {
this.setExpression(expression);
},
updateLanguageId: async ({ languageId }) => {
this.languageId = languageId || "text";
},
}
);
try {