Moved "extension/ui" to "webview", removed "shared".

This commit is contained in:
Henning Dieterichs
2020-02-29 21:31:22 +01:00
parent f55bef23c2
commit 5318b5e4ae
56 changed files with 144 additions and 116 deletions

View File

@@ -1,5 +1,5 @@
import { Disposable } from "@hediet/std/disposable";
import { debugVisualizerUIContract } from "@hediet/debug-visualizer-vscode-shared";
import { debugVisualizerUIContract } from "./contract";
import { ConsoleRpcLogger, RequestHandlingError } from "@hediet/typed-json-rpc";
import { EvaluationWatcher, DataSource } from "./DataSource/DataSource";
import { WebSocketStream } from "@hediet/typed-json-rpc-websocket";

View File

@@ -1,8 +1,5 @@
import { DataExtractorId } from "@hediet/debug-visualizer-data-extraction";
import {
DataExtractionState,
CompletionItem,
} from "@hediet/debug-visualizer-vscode-shared";
import { DataExtractionState, CompletionItem } from "../contract";
export interface DataSource {
createEvaluationWatcher(

View File

@@ -6,10 +6,7 @@ import {
import { observable, autorun, action } from "mobx";
import { Disposable } from "@hediet/std/disposable";
import { DataExtractorId } from "@hediet/debug-visualizer-data-extraction";
import {
DataExtractionState,
CompletionItem,
} from "@hediet/debug-visualizer-vscode-shared";
import { DataExtractionState, CompletionItem } from "../contract";
import { hotClass } from "@hediet/node-reload";
import { VsCodeDebuggerView } from "../VsCodeDebugger";
import { DataExtractionProviderFactory } from "./DataExtractionProvider/DataExtractionProvider";

View File

@@ -1,7 +1,6 @@
import { WebSocketStream } from "@hediet/typed-json-rpc-websocket";
import { AddressInfo } from "net";
import WebSocket = require("ws");
import { join } from "path";
import { ConnectionHandler } from "./ConnectionHandler";
import { Sources } from "./DataSource";
import * as express from "express";
@@ -9,6 +8,7 @@ import * as http from "http";
import * as serveStatic from "serve-static";
import { Config } from "./Config";
import cryptoRandomString = require("crypto-random-string");
import { distPath } from "debug-visualizer-webview";
export class Server {
private server: http.Server;
@@ -16,11 +16,17 @@ export class Server {
constructor(sources: Sources, config: Config) {
const app = express();
const distPath = join(__dirname, "../ui/dist");
app.use(serveStatic(distPath));
this.server = app.listen();
console.log(
`Serving "${distPath}" on port ${
(this.server.address() as AddressInfo).port
}`
);
const wss = new WebSocket.Server({ server: this.server });
wss.on("connection", ws => {
const stream = new WebSocketStream(ws);

View File

@@ -1,7 +1,7 @@
import { Disposable } from "@hediet/std/disposable";
import { debug, DebugSession } from "vscode";
import { EventEmitter } from "@hediet/std/events";
import { CompletionItem } from "@hediet/debug-visualizer-vscode-shared";
import { CompletionItem } from "./contract";
import { observable, runInAction } from "mobx";
export class VsCodeDebugger {

118
extension/src/contract.ts Normal file
View File

@@ -0,0 +1,118 @@
import {
contract,
notificationContract,
types,
requestContract,
} from "@hediet/typed-json-rpc";
import {
DataExtractionResult,
DataExtractorId,
} from "@hediet/debug-visualizer-data-extraction";
function unchecked<T>(): types.Type<T, any, unknown> {
return new types.Type<T, T, unknown>(
"unchecked",
(u): u is T => true,
value => types.success(value as T),
value => value
);
}
export type DataExtractionState =
| { kind: "loading" }
| { kind: "error"; message: string }
| { kind: "noDebugSession" }
| {
kind: "data";
result: DataExtractionResult;
};
// https://microsoft.github.io/debug-adapter-protocol/specification#CompletionItem
type CompletionItemType =
| "method"
| "function"
| "constructor"
| "field"
| "variable"
| "class"
| "interface"
| "module"
| "property"
| "unit"
| "value"
| "enum"
| "keyword"
| "snippet"
| "text"
| "color"
| "file"
| "reference"
| "customcolor";
export interface CompletionItem {
/**
* The label of this completion item. By default this is also the text that is inserted when selecting this completion.
*/
label: string;
/**
* If text is not falsy then it is inserted instead of the label.
*/
text?: string;
/**
* The item's type. Typically the client uses this information to render the item in the UI with an icon.
*/
type?: CompletionItemType;
/**
* This value determines the location (in the CompletionsRequest's 'text' attribute) where the completion text is added.
* If missing the text is added at the location specified by the CompletionsRequest's 'column' attribute.
*/
start?: number;
/**
* This value determines how many characters are overwritten by the completion text.
* If missing the value 0 is assumed which results in the completion text being inserted.
*/
length?: number;
}
export const debugVisualizerUIContract = contract({
client: {
updateState: notificationContract({
params: types.type({
newState: unchecked<DataExtractionState>(),
}),
}),
},
server: {
authenticate: requestContract({
params: types.type({
secret: types.string,
}),
}),
setPreferredDataExtractor: notificationContract({
params: types.type({
dataExtractorId: unchecked<DataExtractorId>(),
}),
}),
setExpression: notificationContract({
params: types.type({
newExpression: types.string,
}),
}),
refresh: notificationContract({}),
openInBrowser: notificationContract({}),
getCompletions: requestContract({
params: types.type({
text: types.string,
column: types.number,
}),
result: types.type({
completions: types.array(unchecked<CompletionItem>()),
}),
}),
},
});

View File

@@ -4,3 +4,7 @@ declare namespace NodeJS {
USE_DEV_UI?: "true";
}
}
declare module "debug-visualizer-webview" {
export const distPath: string;
}