Skip to content

Commit

Permalink
Update MarkdownPreview to use Daytona. (#6190)
Browse files Browse the repository at this point in the history
* Update package version

* Update version

* add build framework

* Ensure Daytona usage

* update config

* double mapped

* adjust for perf

* handle when getting component returns null

* perf changes

* Updated initialization

* switch to run

* Updated to allow for parsing markdown off main thread

* Update to use forget

* use intializeAsync cancellation token

* PR comment

* created extension method

* Update src/NuGet.Clients/NuGet.VisualStudio.Common/Telemetry/TaskExtensions.cs

Co-authored-by: Andy Zivkovic <[email protected]>

* pr comments

* pr comments

* Added IsReadmeTabEnable property to viewmodel

* updated comment

* Update src/NuGet.Clients/NuGet.PackageManagement.UI/Xamls/PackageReadmeControl.xaml.cs

Co-authored-by: Donnie Goodson <[email protected]>

---------

Co-authored-by: Andy Zivkovic <[email protected]>
Co-authored-by: Donnie Goodson <[email protected]>
  • Loading branch information
3 people authored Jan 4, 2025
1 parent c9a632f commit 89781a2
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<PackageVersion Include="Microsoft.Test.Apex.VisualStudio" Version="17.13.35619.14" />
<PackageVersion Include="Microsoft.TestPlatform.Portable" Version="17.1.0" />
<PackageVersion Include="Microsoft.VisualStudio.LanguageServices" Version="4.3.1" />
<PackageVersion Include="Microsoft.VisualStudio.Markdown.Platform" Version="17.11.119-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Markdown.Platform" Version="17.13.161" />
<PackageVersion Include="Microsoft.VisualStudio.ProjectSystem" Version="17.4.221-pre" />
<PackageVersion Include="Microsoft.VisualStudio.ProjectSystem.Managed" Version="17.2.0-beta1-20502-01" />
<PackageVersion Include="Microsoft.VisualStudio.ProjectSystem.Managed.VS" Version="17.2.0-beta1-20502-01" />
Expand Down
4 changes: 4 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<package pattern="messagepack.annotations" />
<package pattern="messagepackanalyzer" />
<package pattern="Microsoft.*" />
<package pattern="Microsoft.Build.Framework" />
<package pattern="Microsoft.NET.StringTools" />
<package pattern="Microsoft.VisualStudio.TemplateWizardInterface" />
<package pattern="moq" />
<package pattern="MSTest.TestAdapter" />
Expand Down Expand Up @@ -59,9 +61,11 @@
<package pattern="envdte80" />
<package pattern="envdte90" />
<package pattern="envdte90a" />
<package pattern="Microsoft.Build.Framework" />
<package pattern="Microsoft.DataAI.NuGetRecommender.Contracts" />
<package pattern="microsoft.internal.visualstudio.*" />
<package pattern="Microsoft.Internal.VisualStudio.Shell.Framework" />
<package pattern="Microsoft.NET.StringTools" />
<package pattern="microsoft.servicehub.*" />
<package pattern="Microsoft.ServiceHub.Framework" />
<package pattern="Microsoft.TeamFoundationServer.ExtendedClient" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Shipping>true</Shipping>
Expand Down Expand Up @@ -41,8 +41,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" />
<PackageReference Include="Microsoft.NET.StringTools" />
<PackageReference Include="Microsoft.VisualStudio.Markdown.Platform" />
<PackageReference Include="Microsoft.VisualStudio.Sdk" />
</ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface IPackageManagerControlViewModel
{
ItemFilter ActiveFilter { get; set; }
bool IsSolution { get; }
bool IsReadmeTabEnabled { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NuGet.VisualStudio;
using NuGet.VisualStudio.Internal.Contracts;
using NuGet.VisualStudio.Telemetry;
Expand Down Expand Up @@ -34,17 +33,14 @@ public PackageDetailsTabViewModel()
Tabs = new ObservableCollection<TitledPageViewModelBase>();
}

public async Task InitializeAsync(DetailControlModel detailControlModel, INuGetPackageFileService nugetPackageFileService, ItemFilter currentFilter, PackageMetadataTab initialSelectedTab)
public void Initialize(DetailControlModel detailControlModel, INuGetPackageFileService nugetPackageFileService, ItemFilter currentFilter, PackageMetadataTab initialSelectedTab, bool isReadmeTabEnabled)
{
var nuGetFeatureFlagService = await ServiceLocator.GetComponentModelServiceAsync<INuGetFeatureFlagService>();
_readmeTabEnabled = await nuGetFeatureFlagService.IsFeatureEnabledAsync(NuGetFeatureFlagConstants.RenderReadmeInPMUI);
#pragma warning disable CS0618 // Type or member is obsolete
ReadmePreviewViewModel = new ReadmePreviewViewModel(nugetPackageFileService, currentFilter, _readmeTabEnabled);
#pragma warning restore CS0618 // Type or member is obsolete
_readmeTabEnabled = isReadmeTabEnabled;
DetailControlModel = detailControlModel;

if (_readmeTabEnabled)
{
ReadmePreviewViewModel = new ReadmePreviewViewModel(nugetPackageFileService, currentFilter, _readmeTabEnabled);
Tabs.Add(ReadmePreviewViewModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public ReadmePreviewViewModel(INuGetPackageFileService packageFileService, ItemF
IsVisible = isReadmeFeatureEnabled;
}

public void SetVisibility(bool isVisible)
{
IsVisible = isVisible;
}

public bool IsReadmeReady { get => !IsBusy && !ErrorWithReadme; }

public bool ErrorWithReadme
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<UserControl
x:Name="PackageDetailsTab"
x:Class="NuGet.PackageManagement.UI.PackageDetailsTabControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -153,9 +154,10 @@
Margin="0,5,0,0"/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ReadmePreviewViewModel}">
<nuget:PackageReadmeControl
<ContentControl
Margin="22,0,0,0"
x:Name="_packageReadmeControl"/>
Content="{Binding ElementName=PackageDetailsTab, Path=PackageReadmeControl}"
/>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public PackageDetailsTabControl()
{
InitializeComponent();
DataContext = new PackageDetailsTabViewModel();
PackageReadmeControl = new PackageReadmeControl();
}

public PackageReadmeControl PackageReadmeControl { get; private set; }

public void Dispose()
{
Dispose(disposing: true);
Expand All @@ -41,7 +44,7 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
PackageDetailsTabViewModel.Dispose();
MarkdownPreviewSingleton.ResetInstance();
PackageReadmeControl.Dispose();
}
_disposed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.ServiceHub.Framework;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Threading;
using NuGet.Common;
using NuGet.Configuration;
Expand Down Expand Up @@ -68,6 +69,7 @@ public partial class PackageManagerControl : UserControl, IVsWindowSearch, IDisp
private bool _disposed = false;
private IPackageVulnerabilityService _packageVulnerabilityService;
private INuGetPackageFileService _nugetPackageFileService;
private bool _isReadmeTabEnabled;


private PackageManagerInstalledTabData _installedTabTelemetryData;
Expand All @@ -77,27 +79,34 @@ private PackageManagerControl()
InitializeComponent();
}

public static async ValueTask<PackageManagerControl> CreateAsync(PackageManagerModel model, INuGetUILogger uiLogger)
public static async ValueTask<PackageManagerControl> CreateAsync(PackageManagerModel model, INuGetUILogger uiLogger, CancellationToken cancellationToken)
{
Assumes.NotNull(model);

var packageManagerControl = new PackageManagerControl();
await packageManagerControl.InitializeAsync(model, uiLogger);
await packageManagerControl.InitializeAsync(model, uiLogger, cancellationToken);
return packageManagerControl;
}

private async ValueTask InitializeAsync(PackageManagerModel model, INuGetUILogger uiLogger)
private async ValueTask InitializeAsync(PackageManagerModel model, INuGetUILogger uiLogger, CancellationToken cancellationToken)
{
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
_sinceLastRefresh = Stopwatch.StartNew();

_installedTabTelemetryData = new PackageManagerInstalledTabData();

Model = model;
_uiLogger = uiLogger;
Settings = await ServiceLocator.GetComponentModelServiceAsync<ISettings>();

await TaskScheduler.Default;
Settings = await ServiceLocator.GetComponentModelServiceAsync<ISettings>();
_windowSearchHostFactory = await ServiceLocator.GetGlobalServiceAsync<SVsWindowSearchHostFactory, IVsWindowSearchHostFactory>();
var nuGetFeatureFlagService = await ServiceLocator.GetComponentModelServiceAsync<INuGetFeatureFlagService>();
var editorOptionsFactoryService = await ServiceLocator.GetComponentModelServiceAsync<IEditorOptionsFactoryService>();
NuGetExperimentationService = await ServiceLocator.GetComponentModelServiceAsync<INuGetExperimentationService>();
ISourceRepositoryProvider sourceRepositoryProvider = await ServiceLocator.GetComponentModelServiceAsync<ISourceRepositoryProvider>();
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

_serviceBroker = model.Context.ServiceBroker;

if (Model.IsSolution)
Expand Down Expand Up @@ -146,17 +155,20 @@ private async ValueTask InitializeAsync(PackageManagerModel model, INuGetUILogge

_nugetPackageFileService?.Dispose();
_nugetPackageFileService = await _serviceBroker.GetProxyAsync<INuGetPackageFileService>(NuGetServices.PackageFileService, CancellationToken.None);
_isReadmeTabEnabled = await nuGetFeatureFlagService.IsFeatureEnabledAsync(NuGetFeatureFlagConstants.RenderReadmeInPMUI);
if (_isReadmeTabEnabled)
{
_isReadmeTabEnabled = _packageDetail._packageDetailsTabControl.PackageReadmeControl.Initialize(editorOptionsFactoryService);
}

await _packageDetail._packageDetailsTabControl.PackageDetailsTabViewModel.InitializeAsync(_detailModel, _nugetPackageFileService, _topPanel.Filter, settings.SelectedPackageMetadataTab);
_packageDetail._packageDetailsTabControl.PackageDetailsTabViewModel.Initialize(_detailModel, _nugetPackageFileService, _topPanel.Filter, settings.SelectedPackageMetadataTab, _isReadmeTabEnabled);

await InitPackageSourcesAsync(settings, CancellationToken.None);
ApplySettings(settings, Settings);
_initialized = true;

await IsCentralPackageManagementEnabledAsync(CancellationToken.None);

NuGetExperimentationService = await ServiceLocator.GetComponentModelServiceAsync<INuGetExperimentationService>();

// UI is initialized. Start the first search
_packageList.CheckBoxesEnabled = _topPanel.Filter == ItemFilter.UpdatesAvailable;
_packageList.IsSolution = Model.IsSolution;
Expand All @@ -170,7 +182,6 @@ private async ValueTask InitializeAsync(PackageManagerModel model, INuGetUILogge
controller.PackageManagerControl = this;
}

ISourceRepositoryProvider sourceRepositoryProvider = await ServiceLocator.GetComponentModelServiceAsync<ISourceRepositoryProvider>();
var sourceRepositories = sourceRepositoryProvider.GetRepositories();
_packageVulnerabilityService = new PackageVulnerabilityService(sourceRepositories, _uiLogger);

Expand Down Expand Up @@ -210,6 +221,8 @@ private void Settings_SettingsChanged(object sender, EventArgs e)

public ItemFilter ActiveFilter { get => _topPanel.Filter; set => _topPanel.SelectFilter(value); }

public bool IsReadmeTabEnabled => _isReadmeTabEnabled;

public bool IsSolution => Model.IsSolution;

internal InfiniteScrollList PackageList => _packageList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<UserControl
x:Class="NuGet.PackageManagement.UI.PackageReadmeControl"
x:Name="PackageReadmeUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -13,7 +14,6 @@
Background="{DynamicResource {x:Static nuget:Brushes.DetailPaneBackground}}"
Foreground="{DynamicResource {x:Static nuget:Brushes.UIText}}"
DataContextChanged="UserControl_DataContextChanged"
Unloaded="PackageReadmeControl_Unloaded"
Loaded="PackageReadmeControl_Loaded"
mc:Ignorable="d"
d:DesignHeight="300"
Expand All @@ -30,11 +30,11 @@
x:Name="descriptionMarkdownPreview"
ClipToBounds="True"
Focusable="False"
Visibility="{Binding Path=IsReadmeReady, Mode=OneWay, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}" />
Visibility="{Binding ElementName=PackageReadmeUserControl, Path=IsReadmeReady, Mode=OneWay, FallbackValue=Collapsed, Converter={StaticResource BooleanToVisibilityConverter}}" />
<Grid
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding Path=IsBusy, Mode=OneWay, FallbackValue=Visible, Converter={StaticResource BooleanToVisibilityConverter}}" >
Visibility="{Binding ElementName=PackageReadmeUserControl, Path=IsBusy, Mode=OneWay, FallbackValue=Visible, Converter={StaticResource BooleanToVisibilityConverter}}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
Expand All @@ -60,10 +60,10 @@
<vs:LiveTextBlock.Resources>
<Style TargetType="vs:LiveTextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsBusy}" Value="True">
<DataTrigger Binding="{Binding ElementName=PackageReadmeUserControl, Path=IsBusy}" Value="True">
<Setter Property="Text" Value="{x:Static nuget:Resources.Text_LoadingReadme}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsBusy}" Value="False">
<DataTrigger Binding="{Binding ElementName=PackageReadmeUserControl, Path=IsBusy}" Value="False">
<Setter Property="Text" Value="{x:Static nuget:Resources.Text_ReadmeLoaded}"/>
</DataTrigger>
</Style.Triggers>
Expand Down
Loading

0 comments on commit 89781a2

Please sign in to comment.