Skip to content

Commit

Permalink
Fix Attach to .NET Process before Roslyn LSP is ready (#7427)
Browse files Browse the repository at this point in the history
* Fix Attach to .NET Process before Roslyn LSP is ready

This PR passes the roslynServerStartedProcess to the coreClrDebug
activate call as the Roslyn Server registers the 'coreclr'
DebugConfigurationProvider that will handle the process listing for the
user to select the process ID.

If the configuration provider is not registered but the adapter factory
is, it will send it to the debugger without a processName or processId
and will fail with that error.
  • Loading branch information
WardenGnaw authored Aug 9, 2024
1 parent 25dc516 commit c01efc0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"Unexpected message received from debugger.": "Unexpected message received from debugger.",
"[ERROR]: C# Extension failed to install the debugger package.": "[ERROR]: C# Extension failed to install the debugger package.",
"Could not find a process id to attach.": "Could not find a process id to attach.",
"Unable to launch Attach to Process dialog: ": "Unable to launch Attach to Process dialog: ",
"[ERROR] The debugger cannot be installed. The debugger is not supported on '{0}'": "[ERROR] The debugger cannot be installed. The debugger is not supported on '{0}'",
"[ERROR] The debugger cannot be installed. The debugger requires macOS 12 (Monterey) or newer.": "[ERROR] The debugger cannot be installed. The debugger requires macOS 12 (Monterey) or newer.",
"[WARNING]: x86 Windows is not supported by the .NET debugger. Debugging will not be available.": "[WARNING]: x86 Windows is not supported by the .NET debugger. Debugging will not be available.",
Expand Down
16 changes: 15 additions & 1 deletion src/coreclrDebug/activate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export async function activate(
context: vscode.ExtensionContext,
platformInformation: PlatformInformation,
eventStream: EventStream,
csharpOutputChannel: vscode.OutputChannel
csharpOutputChannel: vscode.OutputChannel,
languageServerStartedPromise: Promise<any> | undefined
) {
const disposables = new CompositeDisposable();

Expand Down Expand Up @@ -66,6 +67,19 @@ export async function activate(
// Register a command to fire attach to process for the coreclr debug engine.
disposables.add(
vscode.commands.registerCommand('csharp.attachToProcess', async () => {
// Ensure dotnetWorkspaceConfigurationProvider is registered
if (languageServerStartedPromise) {
try {
await languageServerStartedPromise;
} catch (e: any) {
if (e as Error) {
throw new Error(vscode.l10n.t('Unable to launch Attach to Process dialog: ') + e.message);
} else {
throw e;
}
}
}

vscode.debug.startDebugging(
undefined,
{
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ export async function activate(
context,
platformInfo,
eventStream,
csharpChannel
csharpChannel,
roslynLanguageServerStartedPromise ?? omnisharpLangServicePromise
);
}

Expand Down

0 comments on commit c01efc0

Please sign in to comment.