-
Notifications
You must be signed in to change notification settings - Fork 33
Add VSCode Connection Bridge #156
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
Open
ChekTek
wants to merge
18
commits into
main
Choose a base branch
from
debug-adapter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9d47b36
add debug adapter
ChekTek 2030288
read port from file
ChekTek e1c1dea
tree view progress
ChekTek f8969ee
migrate to named pipes
ChekTek 1599ed1
folder restructure
ChekTek e7287e9
clarify names and structures
ChekTek 704dc30
clean up connection race condition
ChekTek 4892be4
clean up error handling
ChekTek 86904aa
fix cicd
ChekTek 7501bdc
remove unecessary function
ChekTek e162969
update test name
ChekTek 5ea245a
refactor: improve socket server initialization in BridgeSocket
ChekTek 36f0bef
add snapshot default value
ChekTek 6a87c14
queue snapshot promise
ChekTek 1468daa
fix socket data race condition
ChekTek 0d677af
add changeset
ChekTek 335b341
remove unecessary types, add resources to vscode adapter
ChekTek b74e1e3
rename snapshot to state
ChekTek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,6 @@ dist/ | |
| # Shared package files | ||
| packages/plugin/README.md | ||
| packages/plugin/LICENSE | ||
|
|
||
| # OS | ||
| .DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { vi } from "vitest"; | ||
|
|
||
| export const bridge = { | ||
| start: vi.fn().mockResolvedValue(undefined), | ||
| }; |
308 changes: 308 additions & 0 deletions
308
packages/plugin/src/plugin/bridge/__tests__/adapter.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,308 @@ | ||
| import type { JsonRpcRequest, JsonRpcResponse } from "@elgato/utils/rpc"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { DeviceType, type DeviceDidChange, type DidReceiveSettings, type WillAppear, type WillDisappear } from "../../../api/index.js"; | ||
|
|
||
| vi.mock("../../connection.js"); | ||
| vi.mock("../../manifest.js"); | ||
|
|
||
| describe("debug adapter", () => { | ||
| let adapter: Awaited<typeof import("../adapter.js")>["bridge"]; | ||
| let connection: Awaited<typeof import("../../connection.js")>["connection"]; | ||
| let sent: Array<JsonRpcRequest | JsonRpcResponse>; | ||
|
|
||
| beforeEach(async () => { | ||
| vi.resetModules(); | ||
| sent = []; | ||
|
|
||
| ({ connection } = await import("../../connection.js")); | ||
| ({ bridge: adapter } = await import("../adapter.js")); | ||
| adapter.attachRpc(async (value) => { | ||
| sent.push(value); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("builds a snapshot from manifest actions and visible instances", () => { | ||
| connection.emit("willAppear", createKeyWillAppear()); | ||
|
|
||
| expect(adapter.getSnapshot()).toEqual({ | ||
| actions: [ | ||
| { | ||
| instances: [ | ||
| { | ||
| context: "ctx_001", | ||
| controller: "Keypad", | ||
| device: "Device One", | ||
| position: { | ||
| column: 2, | ||
| kind: "key", | ||
| row: 3, | ||
| }, | ||
| settings: { | ||
| count: 42, | ||
| }, | ||
| }, | ||
| ], | ||
| name: "Action One", | ||
| uuid: "com.elgato.test.key", | ||
| }, | ||
| { | ||
| instances: [], | ||
| name: "Action Two", | ||
| uuid: "com.elgato.test.dial", | ||
| }, | ||
| ], | ||
| plugin: { | ||
| name: "Test Plugin", | ||
| uuid: "com.elgato.test", | ||
| version: "1.0.0", | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("publishes snapshot changes for visible instances", () => { | ||
| connection.emit("willAppear", createKeyWillAppear()); | ||
|
|
||
| expect(sent).toEqual([ | ||
| { | ||
| jsonrpc: "2.0", | ||
| method: "streamDeck.bridge.snapshotChanged", | ||
| params: adapter.getSnapshot(), | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("normalizes dial and multi-action positions", () => { | ||
| connection.emit("willAppear", createDialWillAppear()); | ||
|
|
||
| expect(adapter.getSnapshot().actions[1].instances[0]?.position).toEqual({ | ||
| column: 1, | ||
| index: 1, | ||
| kind: "dial", | ||
| row: 0, | ||
| }); | ||
|
|
||
| connection.emit("willAppear", createMultiActionWillAppear()); | ||
|
|
||
| expect(adapter.getSnapshot().actions[0].instances[0]?.position).toEqual({ | ||
| kind: "multi-action", | ||
| }); | ||
| }); | ||
|
|
||
| it("updates settings, device details, and removals from connection events", () => { | ||
| connection.emit("willAppear", createKeyWillAppear()); | ||
| clearMessages(sent); | ||
|
|
||
| connection.emit("didReceiveSettings", createDidReceiveSettings()); | ||
| expect(adapter.getSnapshot().actions[0].instances[0]?.settings).toEqual({ | ||
| count: 7, | ||
| }); | ||
| expect(sent).toHaveLength(1); | ||
|
|
||
| clearMessages(sent); | ||
| connection.emit("deviceDidChange", createDeviceDidChange()); | ||
| expect(adapter.getSnapshot().actions[0].instances[0]?.device).toBe("Renamed Device"); | ||
| expect(sent).toHaveLength(1); | ||
|
|
||
| clearMessages(sent); | ||
| connection.emit("willDisappear", createWillDisappear()); | ||
| expect(adapter.getSnapshot().actions[0].instances).toEqual([]); | ||
| expect(sent).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("responds to getSnapshot RPC requests", async () => { | ||
| connection.emit("willAppear", createKeyWillAppear()); | ||
| clearMessages(sent); | ||
|
|
||
| const handled = await adapter.receive({ | ||
| id: "request-1", | ||
| jsonrpc: "2.0", | ||
| method: "streamDeck.bridge.getSnapshot", | ||
| }); | ||
|
|
||
| expect(handled).toBe(true); | ||
| expect(sent).toEqual([ | ||
| { | ||
| id: "request-1", | ||
| jsonrpc: "2.0", | ||
| result: adapter.getSnapshot(), | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("does not start the websocket transport outside debug mode", async () => { | ||
| vi.resetModules(); | ||
| vi.doMock("../../common/utils.js", async () => { | ||
| const actual = await vi.importActual<typeof import("../../common/utils.js")>("../../common/utils.js"); | ||
|
|
||
| return { | ||
| ...actual, | ||
| isDebugMode: vi.fn().mockReturnValue(false), | ||
| }; | ||
| }); | ||
| vi.doMock("../socket.js", () => ({ | ||
| socket: { | ||
| start: vi.fn().mockResolvedValue(undefined), | ||
| }, | ||
| })); | ||
|
|
||
| const { bridge } = await import("../adapter.js"); | ||
| const { socket } = await import("../socket.js"); | ||
|
|
||
| await bridge.start(); | ||
|
|
||
| expect(socket.start).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
| * Clears recorded JSON-RPC messages between assertions. | ||
| * @param messages Recorded messages. | ||
| */ | ||
| function clearMessages(messages: Array<JsonRpcRequest | JsonRpcResponse>): void { | ||
| messages.splice(0, messages.length); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a device-change event for the seeded mock device. | ||
| * @returns Device-change event. | ||
| */ | ||
| function createDeviceDidChange(): DeviceDidChange { | ||
| return { | ||
| device: "DEV1", | ||
| deviceInfo: { | ||
| name: "Renamed Device", | ||
| size: { | ||
| columns: 5, | ||
| rows: 3, | ||
| }, | ||
| type: DeviceType.StreamDeckXL, | ||
| }, | ||
| event: "deviceDidChange", | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a settings update for the visible test key. | ||
| * @returns Did-receive-settings event. | ||
| */ | ||
| function createDidReceiveSettings(): DidReceiveSettings<{ count: number }> { | ||
| return { | ||
| action: "com.elgato.test.key", | ||
| context: "ctx_001", | ||
| device: "DEV1", | ||
| event: "didReceiveSettings", | ||
| payload: { | ||
| controller: "Keypad", | ||
| coordinates: { | ||
| column: 2, | ||
| row: 3, | ||
| }, | ||
| isInMultiAction: false, | ||
| resources: {}, | ||
| settings: { | ||
| count: 7, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a visible dial instance event. | ||
| * @returns Will-appear event for a dial. | ||
| */ | ||
| function createDialWillAppear(): WillAppear<{ target: string }> { | ||
| return { | ||
| action: "com.elgato.test.dial", | ||
| context: "ctx_002", | ||
| device: "DEV1", | ||
| event: "willAppear", | ||
| payload: { | ||
| controller: "Encoder", | ||
| coordinates: { | ||
| column: 1, | ||
| row: 0, | ||
| }, | ||
| isInMultiAction: false, | ||
| resources: {}, | ||
| settings: { | ||
| target: "master", | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a visible key instance event. | ||
| * @returns Will-appear event for a key. | ||
| */ | ||
| function createKeyWillAppear(): WillAppear<{ count: number }> { | ||
| return { | ||
| action: "com.elgato.test.key", | ||
| context: "ctx_001", | ||
| device: "DEV1", | ||
| event: "willAppear", | ||
| payload: { | ||
| controller: "Keypad", | ||
| coordinates: { | ||
| column: 2, | ||
| row: 3, | ||
| }, | ||
| isInMultiAction: false, | ||
| resources: {}, | ||
| settings: { | ||
| count: 42, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a visible multi-action key instance event. | ||
| * @returns Will-appear event for a multi-action key. | ||
| */ | ||
| function createMultiActionWillAppear(): WillAppear<{ count: number }> { | ||
| return { | ||
| action: "com.elgato.test.key", | ||
| context: "ctx_003", | ||
| device: "DEV1", | ||
| event: "willAppear", | ||
| payload: { | ||
| controller: "Keypad", | ||
| isInMultiAction: true, | ||
| resources: {}, | ||
| settings: { | ||
| count: 99, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a disappearance event for the visible test key. | ||
| * @returns Will-disappear event for a key. | ||
| */ | ||
| function createWillDisappear(): WillDisappear<{ count: number }> { | ||
| return { | ||
| action: "com.elgato.test.key", | ||
| context: "ctx_001", | ||
| device: "DEV1", | ||
| event: "willDisappear", | ||
| payload: { | ||
| controller: "Keypad", | ||
| coordinates: { | ||
| column: 2, | ||
| row: 3, | ||
| }, | ||
| isInMultiAction: false, | ||
| resources: {}, | ||
| settings: { | ||
| count: 7, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.