Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ openas
opencode
OPENFILENAME
opensource
openurl
openxmlformats
OPTIMIZEFORINVOKE
ORPHANEDDIALOGTITLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.CmdPal.Core.Common.Helpers;

/// <summary>
Expand Down Expand Up @@ -36,24 +32,36 @@ public SupersedingAsyncGate(Func<CancellationToken, Task> action)
public async Task ExecuteAsync(CancellationToken cancellationToken = default)
{
TaskCompletionSource<bool> tcs;
var startWorker = false;

lock (_lock)
{
// Cancel the currently running iteration (if any) before replacing its TCS.
_currentCancellationSource?.Cancel();

// Mark prior waiter as superseded. Fault (not cancel) so callers can distinguish.
_currentTcs?.TrySetException(new OperationCanceledException("Superseded by newer call"));

tcs = new();
// IMPORTANT: RunContinuationsAsynchronously prevents continuations from running
// inside this lock, avoiding reentrancy / potential deadlocks.
tcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
_currentTcs = tcs;
_callId++;

var shouldStartExecution = _executingTask is null;
if (shouldStartExecution)
if (_executingTask is null)
{
_executingTask = Task.Run(ExecuteLoop, CancellationToken.None);
startWorker = true;
}
}

await using var ctr = cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken));
// Start worker outside lock to avoid holding lock while scheduling.
if (startWorker)
{
// Fire-and-forget loop; all state transitions guarded by _lock.
_executingTask = Task.Run(ExecuteLoop, cancellationToken);
}

using var ctr = cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken));
await tcs.Task;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ private void InitializeCommands(ICommandItem[] commands, IFallbackCommandItem[]
Func<ICommandItem?, bool, TopLevelViewModel> makeAndAdd = (ICommandItem? i, bool fallback) =>
{
CommandItemViewModel commandItemViewModel = new(new(i), pageContext);
TopLevelViewModel topLevelViewModel = new(commandItemViewModel, fallback, ExtensionHost, ProviderId, settings, providerSettings, serviceProvider);
TopLevelViewModel topLevelViewModel = new(commandItemViewModel, fallback, ExtensionHost, ProviderId, settings, providerSettings, serviceProvider, i);
topLevelViewModel.InitializeProperties();

return topLevelViewModel;
};

if (commands is not null)
{
TopLevelItems = commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CmdPal.Core.ViewModels.Messages;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;

Expand All @@ -27,9 +26,9 @@ public override ICommandItem[] TopLevelCommands() =>

public override IFallbackCommandItem[] FallbackCommands() =>
[
new FallbackCommandItem(quitCommand, displayTitle: Properties.Resources.builtin_quit_subtitle) { Subtitle = Properties.Resources.builtin_quit_subtitle },
new FallbackCommandItem(quitCommand, displayTitle: Properties.Resources.builtin_quit_subtitle, quitCommand.Id) { Subtitle = Properties.Resources.builtin_quit_subtitle },
_fallbackReloadItem,
_fallbackLogItem,
_fallbackLogItem
];

public BuiltInsCommandProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ internal sealed partial class FallbackLogItem : FallbackCommandItem
{
private readonly LogMessagesPage _logMessagesPage;

private const string _id = "com.microsoft.cmdpal.log";

public FallbackLogItem()
: base(new LogMessagesPage() { Id = "com.microsoft.cmdpal.log" }, Resources.builtin_log_subtitle)
: base(new LogMessagesPage() { Id = _id }, Resources.builtin_log_subtitle, _id)
{
_logMessagesPage = (LogMessagesPage)Command!;
Title = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.CommandPalette.Extensions.Toolkit;

namespace Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;
Expand All @@ -11,10 +10,13 @@ internal sealed partial class FallbackReloadItem : FallbackCommandItem
{
private readonly ReloadExtensionsCommand _reloadCommand;

private const string _id = "com.microsoft.cmdpal.reload";

public FallbackReloadItem()
: base(
new ReloadExtensionsCommand() { Id = "com.microsoft.cmdpal.reload" },
Properties.Resources.builtin_reload_display_title)
new ReloadExtensionsCommand() { Id = _id },
Properties.Resources.builtin_reload_display_title,
_id)
{
_reloadCommand = (ReloadExtensionsCommand)Command!;
Title = string.Empty;
Expand Down
Loading
Loading