Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@ private async Task ExecuteCommandAsync(Guid commandGuid, uint commandId, Cancell

var dispatcher = await TestServices.Shell.GetRequiredGlobalServiceAsync<SUIHostCommandDispatcher, IOleCommandTarget>(cancellationToken);

// Set up the command structure to query the command's status
var cmds = new OLECMD[1];
cmds[0].cmdID = commandId;
cmds[0].cmdf = 0;

// Wait for the command to become enabled and supported before executing it.
// This prevents COM exceptions that can occur when trying to execute commands
// before they're fully initialized (e.g., during language server startup).
await Helper.RetryAsync(ct =>
{
// Query whether the command is currently available
ErrorHandler.ThrowOnFailure(dispatcher.QueryStatus(ref commandGuid, 1, cmds, IntPtr.Zero));

var status = (OLECMDF)cmds[0].cmdf;
Expand All @@ -103,6 +108,7 @@ await Helper.RetryAsync(ct =>
return SpecializedTasks.False;
}, TimeSpan.FromMilliseconds(100), cancellationToken);

// Execute the command now that we've confirmed it's ready
ErrorHandler.ThrowOnFailure(dispatcher.Exec(commandGuid, commandId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero));
}

Expand Down
Loading