Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add quickjs debugger support #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2
61 changes: 58 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,66 @@
"Other"
],
"activationEvents": [
"onCommand:vscode-webf.helloWorld"
"*",
"onCommand:webf.runDebug",
"onDebug"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "vscode-webf.helloWorld",
"title": "Hello World"
"command": "webf.runDebug",
"title": "Debug WebF Apps"
}
],
"debuggers": [
{
"type": "webf",
"label": "WebF",
"languages": ["javascript", "html", "vue"],
"initialConfigurations": [
{
"type": "webf",
"request": "launch",
"name": "Launch Program",
"url": "http://localhost:3000"
},
{
"type": "webf",
"request": "attach",
"name": "Attach to WebF App",
"port": 9222,
"host": "localhost"
}
],
"configurationAttributes": {
"launch": {
"required": ["url"],
"properties": {
"url": {
"type": "string",
"description": "The page url which webf opens."
},
"program": {
"type": "string",
"description": "The main page entry"
}
}
},
"attach": {
"required": [],
"properties": {
"port": {
"type": "number",
"description": "the port which WebF debugger server listen to. default to 9222"
},
"host": {
"type": "string",
"description": "the host which WebF debugger server listen to. default to localhost"
}
}
}
}
}
]
},
Expand Down Expand Up @@ -49,6 +101,9 @@
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@types/websocket": "^1.0.5",
"source-map": "^0.7.4",
"vscode-debugadapter": "^1.51.0",
"websocket": "^1.0.34"
}
}
27 changes: 27 additions & 0 deletions src/activateWebFDebug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'ust strict';

import * as vscode from 'vscode';
import { QuickJSDebugSession } from './quickjsDebug';

class WebFConfigurationProvider implements vscode.DebugConfigurationProvider {
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken | undefined): vscode.ProviderResult<vscode.DebugConfiguration> {
return config;
}
}

class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory {
createDebugAdapterDescriptor(_session: vscode.DebugSession): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
return new vscode.DebugAdapterInlineImplementation(new QuickJSDebugSession());
}
}

export function activateWebFDebug(context: vscode.ExtensionContext, factory?: vscode.DebugAdapterDescriptorFactory) {
// register a configuration provider for 'webf' debug type
const provider = new WebFConfigurationProvider();
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('webf', provider));

if (!factory) {
factory = new InlineDebugAdapterFactory();
}
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory('webf', factory));
}
7 changes: 7 additions & 0 deletions src/debugAdaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import { QuickJSDebugSession } from './quickjsDebug';

QuickJSDebugSession.run(QuickJSDebugSession);
57 changes: 43 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { CancellationToken, DebugConfiguration, ProviderResult, WorkspaceFolder } from 'vscode';

class WebFConfigurationProvider implements vscode.DebugConfigurationProvider {
/**
* Massage a debug configuration just before a debug session is being launched,
* e.g. add all missing attributes to the debug configuration.
*/
resolveDebugConfiguration(folder: WorkspaceFolder | undefined, config: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {
return config;
}
}

import { spawn, spawnSync } from 'child_process';
import { activateWebFDebug } from './activateWebFDebug';

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("WebF", new WebFConfigurationProvider()));
activateWebFDebug(context);

checkWebFCommand();
}

async function checkWebFCommand() {
let result = spawnSync('type', ['webf'], { encoding: 'utf-8'});
if (result.status !== 0) {
const selection = await vscode.window.showWarningMessage('The `webf` command not found on PATH.', 'Install it for me', 'Ignore');
if (selection === 'Install it for me') {
vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: "Installing..",
cancellable: true
}, (progress, token) => {
const installer = spawn('npm', ['install', '-g', '@openwebf/cli'], { stdio: 'inherit' });
token.onCancellationRequested(() => {
installer.kill();
});

progress.report({ increment: 0 });

setTimeout(() => {
progress.report({ increment: 10});
}, 1000);

setTimeout(() => {
progress.report({ increment: 40});
}, 2000);

const p = new Promise<void>(resolve => {
installer.on('exit', () => {
resolve();
});
});
return p;
});
}
}
}


// This method is called when your extension is deactivated
export function deactivate() {}
export function deactivate() { }
Loading