diff options
author | 2023-08-24 15:08:39 -0700 | |
---|---|---|
committer | 2023-08-24 20:11:20 -0700 | |
commit | 936f112b6aa2df6dc9ceb6b02675bbb48e6b52a9 (patch) | |
tree | 5f858282d26560b948d836e4d93a4da981b546ed | |
parent | 627de5b29d4ceba6615e53c996c0b03336f6404a (diff) | |
download | bun-936f112b6aa2df6dc9ceb6b02675bbb48e6b52a9.tar.gz bun-936f112b6aa2df6dc9ceb6b02675bbb48e6b52a9.tar.zst bun-936f112b6aa2df6dc9ceb6b02675bbb48e6b52a9.zip |
Prepare for extension
-rwxr-xr-x | packages/bun-debug-adapter-protocol/bun.lockb | bin | 2323 -> 2323 bytes | |||
-rw-r--r-- | packages/bun-debug-adapter-protocol/debugger/adapter.ts | 14 | ||||
-rwxr-xr-x | packages/bun-vscode/bun.lockb | bin | 12989 -> 12989 bytes | |||
-rw-r--r-- | packages/bun-vscode/package.json | 179 | ||||
-rw-r--r-- | packages/bun-vscode/src/adapter.ts | 38 | ||||
-rw-r--r-- | packages/bun-vscode/src/extension.ts | 16 | ||||
-rw-r--r-- | packages/bun-vscode/src/features/debug.ts (renamed from packages/bun-vscode/src/activate.ts) | 62 | ||||
-rw-r--r-- | packages/bun-vscode/src/features/lockfile.ts (renamed from packages/bun-vscode/src/lockfile.ts) | 0 | ||||
-rw-r--r-- | packages/bun-vscode/src/web-extension.ts | 5 |
9 files changed, 170 insertions, 144 deletions
diff --git a/packages/bun-debug-adapter-protocol/bun.lockb b/packages/bun-debug-adapter-protocol/bun.lockb Binary files differindex 350c33c61..68b641658 100755 --- a/packages/bun-debug-adapter-protocol/bun.lockb +++ b/packages/bun-debug-adapter-protocol/bun.lockb diff --git a/packages/bun-debug-adapter-protocol/debugger/adapter.ts b/packages/bun-debug-adapter-protocol/debugger/adapter.ts index ed40c86e4..251eac5d5 100644 --- a/packages/bun-debug-adapter-protocol/debugger/adapter.ts +++ b/packages/bun-debug-adapter-protocol/debugger/adapter.ts @@ -95,6 +95,7 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener { #functionBreakpoints: Map<string, FunctionBreakpoint>; #variables: (Variable | Variable[])[]; #process?: ChildProcess; + #launched?: LaunchRequest; #initialized?: InitializeRequest; #terminated?: boolean; @@ -121,6 +122,7 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener { this.#breakpoints.length = 0; this.#functionBreakpoints.clear(); this.#variables.length = 1; + this.#launched = undefined; this.#initialized = undefined; } @@ -236,12 +238,23 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener { } async configurationDone(request: DAP.ConfigurationDoneRequest): Promise<DAP.ConfigurationDoneResponse> { + if (this.#launched?.noDebug) { + this.#send("Debugger.setBreakpointsActive", { active: false }); + this.#send("Debugger.setPauseOnExceptions", { state: "none" }); + this.#send("Debugger.setPauseOnDebuggerStatements", { enabled: false }); + this.#send("Debugger.setPauseOnMicrotasks", { enabled: false }); + this.#send("Debugger.setPauseForInternalScripts", { shouldPause: false }); + this.#send("Debugger.setPauseOnAssertions", { enabled: false }); + } + this.#send("Inspector.initialized"); return {}; } async launch(request: DAP.LaunchRequest): Promise<DAP.LaunchResponse> { + this.#launched = request; + try { await this.#launch(request); } catch (error) { @@ -254,6 +267,7 @@ export class DebugAdapter implements IDebugAdapter, InspectorListener { }); this.#emit("terminated"); } + return {}; } diff --git a/packages/bun-vscode/bun.lockb b/packages/bun-vscode/bun.lockb Binary files differindex d5a37a3b2..dfa633f6a 100755 --- a/packages/bun-vscode/bun.lockb +++ b/packages/bun-vscode/bun.lockb diff --git a/packages/bun-vscode/package.json b/packages/bun-vscode/package.json index 10904db94..1029bdf23 100644 --- a/packages/bun-vscode/package.json +++ b/packages/bun-vscode/package.json @@ -1,66 +1,103 @@ { "name": "bun-vscode", + "displayName": "Bun", + "description": "The Visual Studio Code extension for Bun.", "version": "0.0.1", - "main": "dist/extension.js", - "devDependencies": { - "@types/vscode": "^1.81.0", - "@vscode/debugadapter": "^1.56.0", - "@vscode/debugadapter-testsupport": "^1.56.0", - "bun-types": "^0.7.3", - "typescript": "^5.0.0", - "esbuild": "^0.19.2" + "license": "MIT", + "author": "oven", + "publisher": "oven", + "keywords": [ + "bun", + "node.js", + "javascript", + "typescript", + "vscode" + ], + "icon": "src/assets/icon.png", + "galleryBanner": { + "color": "#C80000", + "theme": "dark" }, - "activationEvents": [ - "onDebugResolve:bun", - "onDebugDynamicConfigurations:bun", - "onCommand:extension.bun.getProgramName" + "homepage": "https://bun.sh/", + "repository": { + "type": "git", + "url": "https://github.com/oven-sh/bun" + }, + "bugs": { + "url": "https://github.com/oven-sh/bun/issues" + }, + "engines": { + "vscode": "^1.81.0" + }, + "extensionKind": [ + "workspace" ], - "browser": "dist/web-extension.js", "categories": [ "Programming Languages", - "Debuggers" + "Debuggers", + "Testing" + ], + "activationEvents": [ + "onLanguage:javascript", + "onLanguage:javascriptreact", + "onLanguage:typescript", + "onLanguage:typescriptreact", + "workspaceContains:**/.lockb", + "onDebugResolve:bun", + "onDebugDynamicConfigurations:bun" ], "contributes": { + "configuration": { + "title": "Bun", + "properties": { + "bun.path": { + "type": "string", + "description": "A path to the `bun` executable. By default, the extension looks for `bun` in the `PATH`, but if set, it will use the specified path instead.", + "scope": "window", + "default": null + } + } + }, + "commands": [ + { + "command": "extension.bun.runFile", + "title": "Run File", + "category": "Bun", + "enablement": "!inDebugMode", + "icon": "$(play)" + }, + { + "command": "extension.bun.debugFile", + "title": "Debug File", + "category": "Bun", + "enablement": "!inDebugMode", + "icon": "$(debug-alt)" + } + ], "menus": { "editor/title/run": [ { - "command": "extension.bun.runEditorContents", - "when": "resourceLangId == javascript", + "command": "extension.bun.runFile", + "when": "resourceLangId == javascript || resourceLangId == javascriptreact || resourceLangId == typescript || resourceLangId == typescriptreact", "group": "navigation@1" }, { - "command": "extension.bun.debugEditorContents", - "when": "resourceLangId == javascript", + "command": "extension.bun.debugFile", + "when": "resourceLangId == javascript || resourceLangId == javascriptreact || resourceLangId == typescript || resourceLangId == typescriptreact", "group": "navigation@2" } ], "commandPalette": [ { - "command": "extension.bun.debugEditorContents", - "when": "resourceLangId == javascript" + "command": "extension.bun.runFile", + "when": "resourceLangId == javascript || resourceLangId == javascriptreact || resourceLangId == typescript || resourceLangId == typescriptreact" }, { - "command": "extension.bun.runEditorContents", - "when": "resourceLangId == javascript" + "command": "extension.bun.debugFile", + "when": "resourceLangId == javascript || resourceLangId == javascriptreact || resourceLangId == typescript || resourceLangId == typescriptreact" } ] }, - "commands": [ - { - "command": "extension.bun.debugEditorContents", - "title": "Debug File", - "category": "Bun", - "enablement": "!inDebugMode", - "icon": "$(debug-alt)" - }, - { - "command": "extension.bun.runEditorContents", - "title": "Run File", - "category": "Bun", - "enablement": "!inDebugMode", - "icon": "$(play)" - } - ], "breakpoints": [ { "language": "javascript" @@ -101,7 +138,7 @@ "program": { "type": "string", "description": "The file to debug.", - "default": "${workspaceFolder}/${command:AskForProgramName}" + "default": "${file}" }, "cwd": { "type": "string", @@ -123,7 +160,7 @@ }, "inheritEnv": { "type": "boolean", - "description": "Whether environment variables should be inherited from the parent process.", + "description": "If environment variables should be inherited from the parent process.", "default": true } } @@ -143,12 +180,13 @@ "type": "bun", "request": "launch", "name": "Bun: Debug", - "program": "${workspaceFolder}/${command:AskForProgramName}" + "program": "${file}" }, { "type": "bun", "request": "attach", - "name": "Bun: Attach" + "name": "Bun: Attach", + "url": "ws://localhost:6499/" } ], "configurationSnippets": [ @@ -159,7 +197,7 @@ "type": "bun", "request": "launch", "name": "Ask for file name", - "program": "^\"\\${workspaceFolder}/\\${command:AskForProgramName}\"" + "program": "^\"\\${file}\"" } }, { @@ -169,14 +207,10 @@ "type": "bun", "request": "attach", "name": "Attach to Bun", - "port": 6499, - "hostname": "localhost" + "url": "ws://localhost:6499/" } } - ], - "variables": { - "AskForProgramName": "extension.bun.getProgramName" - } + ] } ], "languages": [ @@ -213,33 +247,34 @@ } ] }, - "description": "Visual Studio Code extension for Bun.", - "engines": { - "vscode": "^1.81.0" - }, - "galleryBanner": { - "color": "#C80000", - "theme": "dark" - }, - "icon": "src/assets/icon.png", - "license": "MIT", - "private": true, - "repository": { - "type": "git", - "url": "https://github.com/oven-sh/bun" - }, - "publisher": "oven", - "scripts": { - "bundle": "./node_modules/.bin/esbuild src/extension.ts src/web-extension.ts --bundle --external:vscode --outdir=dist --platform=node --format=cjs", - "prebuild": "bun run bundle && rm -rf extension && mkdir -p extension/src && cp -r dist extension/dist && cp -r src/assets extension/src/assets && cp package.json extension && cp README.md extension", - "build": "cd extension && vsce package", - "build:watch": "bunx esbuild --watch src/extension.ts src/web-extension.ts --bundle --external:vscode --outdir=dist --platform=node --format=cjs" - }, "workspaceTrust": { "request": "never" }, + "capabilities": { + "untrustedWorkspaces": { + "supported": false, + "description": "This extension needs to be able to run your code using Bun." + } + }, + "main": "dist/extension.js", + "browser": "dist/web-extension.js", "workspaces": [ "../bun-debug-adapter-protocol", "../bun-inspector-protocol" - ] + ], + "dependencies": {}, + "devDependencies": { + "@types/vscode": "^1.81.0", + "@vscode/debugadapter": "^1.56.0", + "@vscode/debugadapter-testsupport": "^1.56.0", + "bun-types": "^0.7.3", + "typescript": "^5.0.0", + "esbuild": "^0.19.2" + }, + "scripts": { + "bundle": "esbuild src/extension.ts src/web-extension.ts --bundle --external:vscode --outdir=dist --platform=node --format=cjs", + "prebuild": "bun run bundle && rm -rf extension && mkdir -p extension/src && cp -r dist extension/dist && cp -r src/assets extension/src/assets && cp package.json extension && cp README.md extension", + "build": "cd extension && vsce package", + "build:watch": "esbuild --watch src/extension.ts src/web-extension.ts --bundle --external:vscode --outdir=dist --platform=node --format=cjs" + } } diff --git a/packages/bun-vscode/src/adapter.ts b/packages/bun-vscode/src/adapter.ts deleted file mode 100644 index e3233d567..000000000 --- a/packages/bun-vscode/src/adapter.ts +++ /dev/null @@ -1,38 +0,0 @@ -import * as vscode from "vscode"; -import type { DAP } from "../../bun-debug-adapter-protocol"; -import { DebugAdapter } from "../../bun-debug-adapter-protocol"; -import { DebugSession } from "@vscode/debugadapter"; - -export class VSCodeAdapter extends DebugSession { - #adapter: DebugAdapter; - - constructor(session: vscode.DebugSession) { - super(); - console.log("[dap] --- start"); - this.#adapter = new DebugAdapter({ - sendToAdapter: this.sendMessage.bind(this), - }); - } - - sendMessage(message: DAP.Request | DAP.Response | DAP.Event): void { - console.log("[dap] -->", message); - const { type } = message; - if (type === "response") { - this.sendResponse(message); - } else if (type === "event") { - this.sendEvent(message); - } else { - throw new Error(`Not supported: ${type}`); - } - } - - handleMessage(message: DAP.Event | DAP.Request | DAP.Response): void { - console.log("[dap] <--", message); - this.#adapter.accept(message); - } - - dispose() { - console.log("[dap] --- close"); - this.#adapter.close(); - } -} diff --git a/packages/bun-vscode/src/extension.ts b/packages/bun-vscode/src/extension.ts index f840dd7a9..e333aedd7 100644 --- a/packages/bun-vscode/src/extension.ts +++ b/packages/bun-vscode/src/extension.ts @@ -1,16 +1,10 @@ import * as vscode from "vscode"; -import { activateBunDebug } from "./activate"; - -const runMode: "external" | "server" | "namedPipeServer" | "inline" = "inline"; +import activateLockfile from "./features/lockfile"; +import activateDebug from "./features/debug"; export function activate(context: vscode.ExtensionContext) { - if (runMode === "inline") { - activateBunDebug(context); - return; - } - throw new Error(`This extension does not support '${runMode}' mode.`); + activateLockfile(context); + activateDebug(context); } -export function deactivate() { - // No-op -} +export function deactivate() {} diff --git a/packages/bun-vscode/src/activate.ts b/packages/bun-vscode/src/features/debug.ts index 025515cc1..2a8ac587e 100644 --- a/packages/bun-vscode/src/activate.ts +++ b/packages/bun-vscode/src/features/debug.ts @@ -1,7 +1,8 @@ import * as vscode from "vscode"; -import { CancellationToken, DebugConfiguration, ProviderResult, WorkspaceFolder } from "vscode"; -import lockfile from "./lockfile"; -import { VSCodeAdapter } from "./adapter"; +import type { CancellationToken, DebugConfiguration, ProviderResult, WorkspaceFolder } from "vscode"; +import type { DAP } from "../../../bun-debug-adapter-protocol"; +import { DebugAdapter } from "../../../bun-debug-adapter-protocol"; +import { DebugSession } from "@vscode/debugadapter"; const debugConfiguration: vscode.DebugConfiguration = { type: "bun", @@ -21,17 +22,14 @@ const attachConfiguration: vscode.DebugConfiguration = { type: "bun", request: "attach", name: "Attach to Bun", - hostname: "localhost", - port: 6499, + url: "ws://localhost:6499/", }; const debugConfigurations: vscode.DebugConfiguration[] = [debugConfiguration, attachConfiguration]; -export function activateBunDebug(context: vscode.ExtensionContext, factory?: vscode.DebugAdapterDescriptorFactory) { - lockfile(context); - +export default function (context: vscode.ExtensionContext, factory?: vscode.DebugAdapterDescriptorFactory) { context.subscriptions.push( - vscode.commands.registerCommand("extension.bun.runEditorContents", (resource: vscode.Uri) => { + vscode.commands.registerCommand("extension.bun.runFile", (resource: vscode.Uri) => { let targetResource = resource; if (!targetResource && vscode.window.activeTextEditor) { targetResource = vscode.window.activeTextEditor.document.uri; @@ -42,7 +40,7 @@ export function activateBunDebug(context: vscode.ExtensionContext, factory?: vsc }); } }), - vscode.commands.registerCommand("extension.bun.debugEditorContents", (resource: vscode.Uri) => { + vscode.commands.registerCommand("extension.bun.debugFile", (resource: vscode.Uri) => { let targetResource = resource; if (!targetResource && vscode.window.activeTextEditor) { targetResource = vscode.window.activeTextEditor.document.uri; @@ -56,15 +54,6 @@ export function activateBunDebug(context: vscode.ExtensionContext, factory?: vsc }), ); - context.subscriptions.push( - vscode.commands.registerCommand("extension.bun.getProgramName", config => { - return vscode.window.showInputBox({ - placeHolder: "Please enter the name of a file in the workspace folder", - value: "src/index.js", - }); - }), - ); - const provider = new BunConfigurationProvider(); context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("bun", provider)); @@ -121,3 +110,38 @@ function isJavaScript(languageId: string): boolean { languageId === "typescriptreact" ); } + +export class VSCodeAdapter extends DebugSession { + #adapter: DebugAdapter; + #dap: vscode.OutputChannel; + + constructor(session: vscode.DebugSession) { + super(); + this.#dap = vscode.window.createOutputChannel("Debug Adapter Protocol"); + this.#adapter = new DebugAdapter({ + sendToAdapter: this.sendMessage.bind(this), + }); + } + + sendMessage(message: DAP.Request | DAP.Response | DAP.Event): void { + this.#dap.appendLine("--> " + JSON.stringify(message)); + const { type } = message; + if (type === "response") { + this.sendResponse(message); + } else if (type === "event") { + this.sendEvent(message); + } else { + throw new Error(`Not supported: ${type}`); + } + } + + handleMessage(message: DAP.Event | DAP.Request | DAP.Response): void { + this.#dap.appendLine("<-- " + JSON.stringify(message)); + this.#adapter.accept(message); + } + + dispose() { + this.#adapter.close(); + this.#dap.dispose(); + } +} diff --git a/packages/bun-vscode/src/lockfile.ts b/packages/bun-vscode/src/features/lockfile.ts index 81adf5b9e..81adf5b9e 100644 --- a/packages/bun-vscode/src/lockfile.ts +++ b/packages/bun-vscode/src/features/lockfile.ts diff --git a/packages/bun-vscode/src/web-extension.ts b/packages/bun-vscode/src/web-extension.ts index a30073e2e..cd2e2623e 100644 --- a/packages/bun-vscode/src/web-extension.ts +++ b/packages/bun-vscode/src/web-extension.ts @@ -1,8 +1,5 @@ import * as vscode from "vscode"; -import { activateBunDebug } from "./activate"; -export function activate(context: vscode.ExtensionContext) { - activateBunDebug(context); -} +export function activate(context: vscode.ExtensionContext) {} export function deactivate() {} |