Skip to content

Commit

Permalink
Drop unfinished integration to Debug API
Browse files Browse the repository at this point in the history
Unfortunally, vscode has ugly and useless Debug API.

Related #11, #13.
  • Loading branch information
reklatsmasters committed Oct 1, 2018
1 parent 284894f commit 77b86ea
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 237 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
"onLanguage:wasm",
"onCommand:wasm.wasm2wat",
"onCommand:wasm.save2wat",
"onCommand:wasm.save2wasm",
"onCommand:wasm.pickFunction",
"onDebug"
"onCommand:wasm.save2wasm"
],
"main": "./out/extension",
"contributes": {
Expand Down Expand Up @@ -82,11 +80,6 @@
"command": "wasm.save2wasm",
"title": "Save as WebAssembly binary file",
"category": "wasm"
},
{
"command": "wasm.pickFunction",
"title": "Select a WebAssembly function",
"category": "wasm"
}
],
"menus": {
Expand Down Expand Up @@ -154,7 +147,6 @@
"vscode": "^1.1.18"
},
"dependencies": {
"vscode-debugprotocol": "^1.29.0",
"wabt": "^1.0.5"
}
}
65 changes: 1 addition & 64 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
import * as vscode from 'vscode'

import WebAssemblyContentProvider from './webassembly-content-provider'
import WebAssemblyDebugContentProvider from './webassembly-debug-content-provider';
import { Uri } from 'vscode'
import { wasm2wat, wat2wasm, writeFile, readFile, SubscribeComplete } from './utils'
import WebAssemblyFunctionQuickPickItem from './webassembly-quick-pick-item';
import WebAssemblyDebugSession from './webassembly-debug-session';

const wasmNamespace = '<node_internals>/wasm:'
const WasmFuncPickItem = WebAssemblyFunctionQuickPickItem;

let activeDebugSession : WebAssemblyDebugSession | null = null
import { wasm2wat, wat2wasm, writeFile, readFile } from './utils'

export function activate(context: vscode.ExtensionContext) {
const provider = new WebAssemblyContentProvider()
const debugProvider = new WebAssemblyDebugContentProvider()

const registration = vscode.workspace.registerTextDocumentContentProvider('wasm-preview', provider)
const registerDebug = vscode.workspace.registerTextDocumentContentProvider('wasm-debug', debugProvider)

const openEvent = vscode.workspace.onDidOpenTextDocument((document: vscode.TextDocument) => {
showDocument(document);
Expand Down Expand Up @@ -63,57 +53,20 @@ export function activate(context: vscode.ExtensionContext) {
.then(maybeSaveWasm(from), vscode.window.showErrorMessage)
})

const pickFunction = vscode.commands.registerCommand('wasm.pickFunction', () => {
const sources = activeDebugSession ? activeDebugSession.sources : []

async function select(file: WebAssemblyFunctionQuickPickItem | undefined) {
if (!file || !activeDebugSession) {
return
}

return activeDebugSession.openFile(file.source)
}

const options = { placeHolder: "Pick a function..." };

vscode.window.showQuickPick(sources.map(source => new WasmFuncPickItem(source)), options)
.then(select, vscode.window.showErrorMessage)
});

if (vscode.window.activeTextEditor) {
showDocument(vscode.window.activeTextEditor.document);
}

const startDebugEvent = vscode.debug.onDidStartDebugSession((session: vscode.DebugSession) => {
if (!isNodeDebugSession(session)) {
return
}

activeDebugSession = new WebAssemblyDebugSession(session);

activeDebugSession.once('wasm:sources', (sources) => {
console.log('Complete loadind sources, length=%s', sources.length);
})

activeDebugSession.on('error', (error) => console.error(error))

context.subscriptions.push(activeDebugSession);
})

context.subscriptions.push(
registration,
registerDebug,
openEvent,
previewCommand,
save2watCommand,
save2wasmCommand,
startDebugEvent,
pickFunction
)
}

export function deactivate() {
activeDebugSession = null
}

function showDocument(document: vscode.TextDocument): void {
Expand Down Expand Up @@ -166,19 +119,3 @@ async function saveWasm(from: vscode.Uri, to: vscode.Uri) {

await writeFile(to, wasmContent)
}

function isNodeDebugSession(session: vscode.DebugSession | undefined) {
if (session === undefined) {
return false
}

if (!session.type.startsWith('node')) {
return false
}

return true
}

function isWebAssemblyDocument(document: vscode.TextDocument) {
return document.fileName.startsWith(wasmNamespace)
}
47 changes: 1 addition & 46 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TextDocumentContentProvider, Uri, window } from 'vscode'
import { Uri, window } from 'vscode'
import * as fs from 'fs'
import { EventEmitter } from 'events'
import * as WabtModule from 'wabt'

// @ts-ignore
Expand Down Expand Up @@ -93,47 +92,3 @@ export function wat2wasm(content: Buffer): Buffer {
wasmModule.destroy()
}
}

export class SubscribeComplete extends EventEmitter {
private _events: Array<any>;
private _handle : NodeJS.Timer;
private _time: number;
private _complete: boolean;

constructor(time: number) {
super();

this._events = [];
this._time = time;
this._complete = false;

this.resetTimer();
}

private resetTimer() {
if (this._handle !== undefined) {
clearTimeout(this._handle);
}

this._handle = setTimeout(() => {
this._complete = true;
this.emit('complete', this._events);
}, this._time);
}

process(event): boolean {
if (this._complete) {
return false
}

this._events.push(event);
this.resetTimer();

return true;
}

dispose() {
this._events.length = 0;
this._handle = undefined;
}
}
19 changes: 0 additions & 19 deletions src/webassembly-debug-content-provider.ts

This file was deleted.

80 changes: 0 additions & 80 deletions src/webassembly-debug-session.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/webassembly-quick-pick-item.ts

This file was deleted.

0 comments on commit 77b86ea

Please sign in to comment.