Skip to content

Update progression work to have context menu. #78754

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

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b13cd7
Merge branch 'separateCommandHandler' into removeProgressionContextMe…
CyrusNajmabadi May 29, 2025
807e52a
in progress
CyrusNajmabadi May 29, 2025
ae70d80
Enable
CyrusNajmabadi May 29, 2025
e47fbef
more
CyrusNajmabadi May 29, 2025
c8a834b
In progress
CyrusNajmabadi May 29, 2025
7beee16
Make dynamic
CyrusNajmabadi May 29, 2025
97ff155
Correct value
CyrusNajmabadi May 29, 2025
9fb32ad
Working
CyrusNajmabadi May 29, 2025
af2121c
Almost working
CyrusNajmabadi May 29, 2025
92b8756
Merge branch 'separateCommandHandler' into removeProgressionContextMe…
CyrusNajmabadi May 29, 2025
ad7678f
Merge branch 'main' into removeProgressionContextMenuWork
CyrusNajmabadi May 29, 2025
47e9703
Merge branch 'removeProgression' into removeProgressionContextMenuWork
CyrusNajmabadi May 30, 2025
3f27218
Merge branch 'removeProgression' into removeProgressionContextMenuWork
CyrusNajmabadi May 30, 2025
2ca4e2a
Fix renames across different extensions
CyrusNajmabadi May 30, 2025
a41e4f2
Merge remote-tracking branch 'upstream/main' into removeProgressionCo…
CyrusNajmabadi May 30, 2025
2122e97
Add docs
CyrusNajmabadi May 30, 2025
edefec3
Add docs
CyrusNajmabadi May 30, 2025
3e0d8db
Update src/VisualStudio/Core/Def/PackageRegistration.pkgdef
CyrusNajmabadi May 30, 2025
d0dee3b
Explicitly reset
CyrusNajmabadi May 30, 2025
c68bd41
Reset state
CyrusNajmabadi May 30, 2025
3e8f832
Add docs
CyrusNajmabadi May 30, 2025
0798403
Simplify
CyrusNajmabadi May 30, 2025
c3d83f2
Revert
CyrusNajmabadi May 30, 2025
25b0a37
Simplify
CyrusNajmabadi May 30, 2025
0481cef
Simplify
CyrusNajmabadi May 30, 2025
1b6c967
Update src/VisualStudio/Core/Def/Commands.vsct
CyrusNajmabadi May 30, 2025
1c054b7
Update src/VisualStudio/Core/Impl/SolutionExplorer/SymbolTree/SymbolI…
CyrusNajmabadi May 30, 2025
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 @@ -36,6 +36,9 @@ public bool ExecuteCommand(TCommandArgs args, CommandExecutionContext context)
if (!_navigationService.IsAvailable(document))
return false;

return _navigationService.ExecuteCommand(document, caret.Value.Position);
// We were called on the current snapshot of a buffer, and we have a position within that buffer.
// We should never have an invalid position here, so pass "false" for allowInvalidPosition so we
// blow up if some invariant was broken.
return _navigationService.ExecuteCommand(document, caret.Value.Position, allowInvalidPosition: false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected virtual StreamingFindUsagesPresenterOptions GetStreamingPresenterOptio
public bool IsAvailable([NotNullWhen(true)] Document? document)
=> document?.GetLanguageService<TLanguageService>() != null;

public bool ExecuteCommand(Document document, int position)
public bool ExecuteCommand(Document document, int position, bool allowInvalidPosition)
{
_threadingContext.ThrowIfNotOnUIThread();
if (document is null)
Expand All @@ -100,14 +100,16 @@ public bool ExecuteCommand(Document document, int position)

// we're going to return immediately from ExecuteCommand and kick off our own async work to invoke the
// operation. Once this returns, the editor will close the threaded wait dialog it created.
_inProgressCommand = ExecuteCommandAsync(document, service, position, _cancellationTokenSource);
_inProgressCommand = ExecuteCommandAsync(
document, service, position, allowInvalidPosition, _cancellationTokenSource);
return true;
}

private async Task ExecuteCommandAsync(
Document document,
TLanguageService service,
int position,
bool allowInvalidPosition,
CancellationTokenSource cancellationTokenSource)
{
// This is a fire-and-forget method (nothing guarantees observing it). As such, we have to handle cancellation
Expand All @@ -127,7 +129,8 @@ private async Task ExecuteCommandAsync(
// any failures from it. Technically this should not be possible as it should be inside this same
// try/catch. however this code wants to be very resilient to any prior mistakes infecting later operations.
await _inProgressCommand.NoThrowAwaitable(captureContext: false);
await ExecuteCommandWorkerAsync(document, service, position, cancellationTokenSource).ConfigureAwait(false);
await ExecuteCommandWorkerAsync(
document, service, position, allowInvalidPosition, cancellationTokenSource).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
Expand All @@ -141,6 +144,7 @@ private async Task ExecuteCommandWorkerAsync(
Document document,
TLanguageService service,
int position,
bool allowInvalidPosition,
CancellationTokenSource cancellationTokenSource)
{
// Switch to the BG immediately so we can keep as much work off the UI thread.
Expand All @@ -161,7 +165,8 @@ private async Task ExecuteCommandWorkerAsync(

var cancellationToken = cancellationTokenSource.Token;
var delayBeforeShowingResultsWindowTask = DelayAsync(cancellationToken);
var findTask = FindResultsAsync(findContext, document, service, position, cancellationToken);
var findTask = FindResultsAsync(
findContext, document, service, position, allowInvalidPosition, cancellationToken);

var firstFinishedTask = await Task.WhenAny(delayBeforeShowingResultsWindowTask, findTask).ConfigureAwait(false);
if (cancellationToken.IsCancellationRequested)
Expand Down Expand Up @@ -247,7 +252,12 @@ private async Task PresentResultsInStreamingPresenterAsync(
}

private async Task FindResultsAsync(
IFindUsagesContext findContext, Document document, TLanguageService service, int position, CancellationToken cancellationToken)
IFindUsagesContext findContext,
Document document,
TLanguageService service,
int position,
bool allowInvalidPosition,
CancellationToken cancellationToken)
{
// Ensure that we relinquish the thread so that the caller can proceed with their work.
await TaskScheduler.Default.SwitchTo(alwaysYield: true);
Expand All @@ -266,6 +276,14 @@ await findContext.ReportMessageAsync(
EditorFeaturesResources.The_results_may_be_incomplete_due_to_the_solution_still_loading_projects, NotificationSeverity.Information, cancellationToken).ConfigureAwait(false);
}

// If we're allowing invalid positions (say from features that are passed stale positions),
// then ensure the position is within the bounds of the document before proceeding.
if (allowInvalidPosition)
{
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
position = Math.Min(text.Length, position);
}

// We were able to find the doc prior to loading the workspace (or else we would not have the service).
// So we better be able to find it afterwards.
await FindActionAsync(findContext, document, service, position, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ internal interface IGoOrFindNavigationService
string DisplayName { get; }

bool IsAvailable([NotNullWhen(true)] Document? document);
bool ExecuteCommand(Document document, int position);
bool ExecuteCommand(Document document, int position, bool allowInvalidPosition);
}
60 changes: 50 additions & 10 deletions src/VisualStudio/Core/Def/Commands.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<Group guid="guidRoslynGrpId" id="grpAnalyzerFolderContextMenu" priority="0x000">
<Parent guid="guidRoslynGrpId" id="cmdidAnalyzerFolderContextMenu"/>
</Group>

<Group guid="guidRoslynGrpId" id="grpSolutionExplorerSymbolItemContextMenu" priority="0x000">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea if what is in here is correct - def need someone else to take a look at this (if anyone does)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. this was done with Jason/Joey yesterday. It's black magic to me as well :)

<Parent guid="guidRoslynGrpId" id="cmdidSolutionExplorerSymbolItemContextMenu"/>
</Group>

<Group guid="guidRoslynGrpId" id="grpErrorListContextMenu" priority="0x0A01">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_ERRORLIST"/>
Expand Down Expand Up @@ -377,6 +381,33 @@
<LocCanonicalName>ResetVisualBasicInteractiveFromProject</LocCanonicalName>
</Strings>
</Button>

<!-- Solution Explorer Symbol Item commands -->

<Button guid="guidRoslynGrpId" id="cmdidSolutionExplorerSymbolItemGoToBase" priority="100" type="Button">
<Parent guid="guidRoslynGrpId" id="grpSolutionExplorerSymbolItemContextMenu" />
<Strings>
<ButtonText>Go To Base</ButtonText>
<CanonicalName>GoToBase</CanonicalName>
<LocCanonicalName>GoToBase</LocCanonicalName>
</Strings>
</Button>
<Button guid="guidRoslynGrpId" id="cmdidSolutionExplorerSymbolItemGoToImplementation" priority="200" type="Button">
<Parent guid="guidRoslynGrpId" id="grpSolutionExplorerSymbolItemContextMenu" />
<Strings>
<ButtonText>Go To Implementation</ButtonText>
<CanonicalName>GoToImplementation</CanonicalName>
<LocCanonicalName>GoToImplementation</LocCanonicalName>
</Strings>
</Button>
<Button guid="guidRoslynGrpId" id="cmdidSolutionExplorerSymbolItemFindAllReferences" priority="300" type="Button">
<Parent guid="guidRoslynGrpId" id="grpSolutionExplorerSymbolItemContextMenu" />
<Strings>
<ButtonText>Find All References</ButtonText>
<CanonicalName>FindAllReferences</CanonicalName>
<LocCanonicalName>FindAllReferences</LocCanonicalName>
</Strings>
</Button>

<!-- Run code analysis commands -->

Expand Down Expand Up @@ -476,7 +507,7 @@
<CommandFlag>IconAndText</CommandFlag>
<Strings>
<ButtonText>Clear</ButtonText>
<CommandName>CleearStackTraceExplorerCommandName</CommandName>
<CommandName>ClearStackTraceExplorerCommandName</CommandName>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume renaming this won't potentially break something else? Are these visible to other components in VS?

<CanonicalName>ClearStackTraceExplorer</CanonicalName>
<LocCanonicalName>ClearStackTraceExplorer</LocCanonicalName>
</Strings>
Expand Down Expand Up @@ -557,7 +588,7 @@
<LocCanonicalName>Analyzer</LocCanonicalName>
</Strings>
</Menu>

<Menu guid="guidRoslynGrpId" id="cmdidAnalyzerFolderContextMenu" priority="100" type="Context">
<Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_SOLNEXPL_ALL" />
<Strings>
Expand Down Expand Up @@ -622,6 +653,13 @@
</Strings>
</Menu>

<Menu guid="guidRoslynGrpId" id="cmdidSolutionExplorerSymbolItemContextMenu" type="Context">
<Strings>
<MenuText>Solution Explorer Symbol Tree</MenuText>
<ButtonText>Solution Explorer Symbol Tree</ButtonText>
</Strings>
</Menu>

<!-- Document Outline toolbar -->
<Menu guid="guidRoslynGrpId" id="cmdidDocumentOutlineToolbar" type="Toolbar">
<CommandFlag>NotInTBList</CommandFlag>
Expand Down Expand Up @@ -774,14 +812,10 @@
<IDSymbol name="grpErrorListDiagnosticSeverityItems" value="0x012a" />

<IDSymbol name="cmdidGoToImplementation" value="0x0200" />

<IDSymbol name="cmdidRunCodeAnalysisForProject" value="0x0201" />

<IDSymbol name="cmdidRemoveUnusedReferences" value="0x202" />

<IDSymbol name="cmdidshowValueTracking" value="0x0203" />

<IDSymbol name="cmdidSyncNamespaces" value="0x204" />
<IDSymbol name="cmdidRunCodeAnalysisForProject" value="0x0201" />
<IDSymbol name="cmdidRemoveUnusedReferences" value="0x0202" />
<IDSymbol name="cmdidshowValueTracking" value="0x0203" />
<IDSymbol name="cmdidSyncNamespaces" value="0x0204" />

<IDSymbol name="cmdidDocumentOutlineToolbar" value="0x300" />
<IDSymbol name="cmdidDocumentOutlineExpandAll" value="0x311"/>
Expand All @@ -790,6 +824,12 @@
<IDSymbol name="cmdidDocumentOutlineSortByOrder" value="0x314"/>
<IDSymbol name="cmdidDocumentOutlineSortByType" value="0x315"/>
<IDSymbol name="cmdidDocumentOutlineToolbarGroup" value="0x350" />

<IDSymbol name="grpSolutionExplorerSymbolItemContextMenu" value="0x0400" />
<IDSymbol name="cmdidSolutionExplorerSymbolItemContextMenu" value="0x0401" />
<IDSymbol name="cmdidSolutionExplorerSymbolItemGoToBase" value="0x0402" />
<IDSymbol name="cmdidSolutionExplorerSymbolItemGoToImplementation" value="0x0403" />
<IDSymbol name="cmdidSolutionExplorerSymbolItemFindAllReferences" value="0x0404" />
</GuidSymbol>

<GuidSymbol name="guidCSharpInteractiveCommandSet" value="{1492db0a-85a2-4e43-bf0d-ce55b89a8cc6}">
Expand Down
5 changes: 5 additions & 0 deletions src/VisualStudio/Core/Def/ID.RoslynCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public static class RoslynCommands
public const int DocumentOutlineSortByOrder = 0x314;
public const int DocumentOutlineSortByType = 0x315;
public const int DocumentOutlineToolbarGroup = 0x350;

public const int SolutionExplorerSymbolItemContextMenu = 0x401;
public const int SolutionExplorerSymbolItemGoToBase = 0x402;
public const int SolutionExplorerSymbolItemGoToImplementation = 0x403;
public const int SolutionExplorerSymbolItemFindAllReferences = 0x404;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Options;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;

Expand Down
2 changes: 1 addition & 1 deletion src/VisualStudio/Core/Def/PackageRegistration.pkgdef
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[$RootKey$\Menus]
"{6cf2e545-6109-4730-8883-cf43d7aec3e1}"=", Menus.ctmenu, 21"
"{6cf2e545-6109-4730-8883-cf43d7aec3e1}"=", Menus.ctmenu, 24"

// [ProvideUIContextRule(
// Guids.EncCapableProjectExistsInWorkspaceUIContextString,
Expand Down
44 changes: 42 additions & 2 deletions src/VisualStudio/Core/Def/xlf/Commands.vsct.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 42 additions & 2 deletions src/VisualStudio/Core/Def/xlf/Commands.vsct.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading