forked from swiftlang/vscode-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added module enum for workbench commands string constant
- Added comments for clarification - Added utilities to listen for dap message, this is useful for test synchronization. Code takes inspiration from swiftlang#1126
- Loading branch information
1 parent
2b59455
commit 91f7852
Showing
8 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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,19 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the VS Code Swift open source project | ||
// | ||
// Copyright (c) 2024 the VS Code Swift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
export enum Workbench { | ||
ACTION_DEBUG_CONTINUE = "workbench.action.debug.continue", | ||
ACTION_CLOSEALLEDITORS = "workbench.action.closeAllEditors", | ||
ACTION_RELOADWINDOW = "workbench.action.reloadWindow", | ||
} |
This file contains 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 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 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 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 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 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,78 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the VS Code Swift open source project | ||
// | ||
// Copyright (c) 2024 the VS Code Swift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
import * as vscode from "vscode"; | ||
import { Workbench } from "../../src/utilities/command"; | ||
import { DebugAdapter } from "../../src/debugger/debugAdapter"; | ||
import { WorkspaceContext } from "../../src/WorkspaceContext"; | ||
|
||
export async function continueSession(): Promise<void> { | ||
await vscode.commands.executeCommand(Workbench.ACTION_DEBUG_CONTINUE); | ||
} | ||
|
||
/** | ||
* Waits for a specific message from the debug adapter. | ||
* | ||
* @param name The name of the debug session to wait for. | ||
* @param matches A function to match the desired message. | ||
* @param workspaceContext The workspace context containing toolchain information. | ||
* @returns A promise that resolves with the matching message. | ||
*/ | ||
export async function waitForDebugAdapterMessage( | ||
name: string, | ||
matches: (message: any) => boolean, | ||
workspaceContext: WorkspaceContext | ||
): Promise<any> { | ||
return await new Promise<any>(res => { | ||
const disposable = vscode.debug.registerDebugAdapterTrackerFactory( | ||
DebugAdapter.getLaunchConfigType(workspaceContext.toolchain.swiftVersion), | ||
{ | ||
createDebugAdapterTracker: function ( | ||
session: vscode.DebugSession | ||
): vscode.ProviderResult<vscode.DebugAdapterTracker> { | ||
if (session.name !== name) { | ||
return; | ||
} | ||
return { | ||
onDidSendMessage(message) { | ||
if (matches(message)) { | ||
disposable.dispose(); | ||
res(message); | ||
} | ||
}, | ||
}; | ||
}, | ||
} | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Waits for a specific command to be sent by the debug adapter. | ||
* | ||
* @param name The name of the debug session to wait for. | ||
* @param command The command to wait for. | ||
* @param workspaceContext The workspace context containing toolchain information. | ||
* @returns A promise that resolves with the matching command message. | ||
*/ | ||
export async function waitForDebugAdapterCommand( | ||
name: string, | ||
command: string, | ||
workspaceContext: WorkspaceContext | ||
): Promise<any> { | ||
return await waitForDebugAdapterMessage( | ||
name, | ||
(m: any) => m.command === command, | ||
workspaceContext | ||
); | ||
} |