Skip to content
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

Update MarkdownPreview to use Daytona. #6190

Merged
merged 22 commits into from
Jan 4, 2025
Merged
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
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.11.35005.70" />
<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" />
jgonz120 marked this conversation as resolved.
Show resolved Hide resolved
<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;
jgonz120 marked this conversation as resolved.
Show resolved Hide resolved
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}}" />
jgonz120 marked this conversation as resolved.
Show resolved Hide resolved
<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