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
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static CodeClassItem MapClass(ClassDeclarationSyntax member,
{
// If it is part of a region, add the implemented interface item to the region, add the member to the interface item
var regionItem = RegionMapper.GetRegion(regions, implementedInterfaceItemMember);
AddImplementedInterfaceMember(regionItem, implementedInterfaceItem, implementedInterfaceItemMember);
AddImplementedInterfaceMember(regionItem!, implementedInterfaceItem, implementedInterfaceItemMember);
}
else
{
Expand Down
30 changes: 30 additions & 0 deletions src/CodeNav.OutOfProc/Services/CodeDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using CodeNav.OutOfProc.Models;
using CodeNav.OutOfProc.ViewModels;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.ToolWindows;
using Microsoft.VisualStudio.Extensibility.UI;
using System.Windows;

Expand Down Expand Up @@ -36,6 +37,8 @@ public class CodeDocumentService(

public OutliningService OutliningService => outliningService;

public ToolWindow? ToolWindow { get; set; }

public async Task<CodeDocumentViewModel> UpdateCodeDocumentViewModel(
VisualStudioExtensibility? extensibility,
string? filePath,
Expand Down Expand Up @@ -80,9 +83,16 @@ public async Task<CodeDocumentViewModel> UpdateCodeDocumentViewModel(
if (!codeItems.Any())
{
CodeDocumentViewModel.CodeItems = PlaceholderHelper.CreateNoCodeItemsFound();

// No code items found, hide the tool window after showing the "No code items found" message
await HideToolWindow(cancellationToken);

return CodeDocumentViewModel;
}

// Code items were found, make sure the tool window is visible
await ShowToolWindow(cancellationToken);

// Sort the list of code items,
// And update the DataContext for the tool window
CodeDocumentViewModel.CodeItems = SortHelper.Sort(codeItems, CodeDocumentViewModel.SortOrder);
Expand Down Expand Up @@ -204,4 +214,24 @@ public async Task LoadGlobalSettings(bool readFromDisk = false)
await LogHelper.LogException(this, "Error loading global settings", e);
}
}

private async Task HideToolWindow(CancellationToken cancellationToken)
{
if (ToolWindow == null)
{
return;
}

await ToolWindow.HideAsync(cancellationToken);
}

private async Task ShowToolWindow(CancellationToken cancellationToken)
{
if (ToolWindow == null)
{
return;
}

await ToolWindow.ShowAsync(activate: false, cancellationToken);
}
}
6 changes: 4 additions & 2 deletions src/CodeNav.OutOfProc/ToolWindows/CodeNavToolWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace CodeNav.OutOfProc.ToolWindows;

[VisualStudioContribution]
internal class CodeNavToolWindow(CodeDocumentService documentService) : ToolWindow
internal class CodeNavToolWindow(CodeDocumentService codeDocumentService) : ToolWindow
{
public override ToolWindowConfiguration ToolWindowConfiguration => new()
{
Expand All @@ -20,9 +20,11 @@ public override Task InitializeAsync(CancellationToken cancellationToken)
{
Title = "CodeNav";

codeDocumentService.ToolWindow = this;

return Task.CompletedTask;
}

public override Task<IRemoteUserControl> GetContentAsync(CancellationToken cancellationToken)
=> Task.FromResult<IRemoteUserControl>(new CodeNavToolWindowControl(documentService.CodeDocumentViewModel));
=> Task.FromResult<IRemoteUserControl>(new CodeNavToolWindowControl(codeDocumentService.CodeDocumentViewModel));
}
7 changes: 6 additions & 1 deletion src/CodeNav/Services/TextViewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ private async Task<IVsTextView> GetCurrentNativeTextViewAsync()
/// Gets the text view from the window frame.
/// </summary>
/// <returns><see langword="null"/> if the window isn't a document window.</returns>
private async Task<IWpfTextView?> GetTextView(IVsWindowFrame windowFrame)
private async Task<IWpfTextView?> GetTextView(IVsWindowFrame? windowFrame)
{
if (windowFrame == null)
{
return null;
}

try
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
Expand Down
Loading