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

feat: Allow AvaloniaVS defered load #312

Merged
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
3 changes: 0 additions & 3 deletions AvaloniaVS.Shared/AvaloniaPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace AvaloniaVS
[Guid(Constants.PackageGuidString)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideEditorExtension(
typeof(EditorFactory),
"." + Constants.axaml,
Expand Down Expand Up @@ -64,8 +63,6 @@ namespace AvaloniaVS
DebuggingLogicalViewEditor = typeof(EditorFactory),
TextLogicalViewEditor = typeof(EditorFactory))]
[ProvideOptionPage(typeof(OptionsDialogPage), Constants.PackageName, "General", 113, 0, supportsAutomation: true)]


[ProvideBindingPath]
internal sealed class AvaloniaPackage : AsyncPackage
{
Expand Down
2 changes: 1 addition & 1 deletion AvaloniaVS.Shared/AvaloniaVS.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Converters\EnumValuesConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\NotNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Constants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Guids.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IntelliSense\TextChangeAdapter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IntelliSense\XamlCompletion.cs" />
<Compile Include="$(MSBuildThisFileDirectory)IntelliSense\XamlCompletionCommandHandler.cs" />
Expand All @@ -31,6 +30,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Models\ProjectInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\ProjectOutputInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Models\XamlBufferMetadata.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ProjectSystem\AvaloniaProject.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ServiceProviderExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\AvaloniaVSSettings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Services\EditorFactory.cs" />
Expand Down
7 changes: 6 additions & 1 deletion AvaloniaVS.Shared/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
namespace AvaloniaVS;
using System;

namespace AvaloniaVS;

internal static class Constants
{
public const string PackageGuidString = "865ba8d5-1180-4bf8-8821-345f72a4cb79";
public static readonly Guid PackageGuid = new (PackageGuidString);
public const string PackageName = "Avalonia Xaml Editor";
public const string axaml = nameof(axaml);
public const string xaml = nameof(xaml);
public const string paml = nameof(paml);

public const string AvaloviaFactoryEditorGuidString = @"6D5344A2-2FCD-49DE-A09D-6A14FD1B1224";
public static readonly Guid AvaloviaFactoryEditorGuid = new (AvaloviaFactoryEditorGuidString);

public const string AvaloniaCapability = nameof(Avalonia);
}
9 changes: 0 additions & 9 deletions AvaloniaVS.Shared/Guids.cs

This file was deleted.

38 changes: 38 additions & 0 deletions AvaloniaVS.Shared/ProjectSystem/AvaloniaProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.Shell;
using System.ComponentModel.Composition;
using IAsyncServiceProvider = Microsoft.VisualStudio.Shell.IAsyncServiceProvider;
using Microsoft.VisualStudio.Shell.Interop;
using Task = System.Threading.Tasks.Task;

namespace AvaloniaVS.ProjectSystem;

[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))]
[AppliesTo(Constants.AvaloniaCapability)]
internal class AvaloniaProject : IProjectDynamicLoadComponent
{
private IAsyncServiceProvider asyncServiceProvider;

public async Task LoadAsync()
{
if (asyncServiceProvider is null)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (ServiceProvider.GlobalProvider.GetService(typeof(IVsShell)) is IVsShell shell)
{
if (shell.IsPackageLoaded(Constants.PackageGuid, out var vsPackage)
!= Microsoft.VisualStudio.VSConstants.S_OK)
{
shell.LoadPackage(Constants.PackageGuid, out vsPackage);
}
asyncServiceProvider = (IAsyncServiceProvider)vsPackage;
}
}
}

public async Task UnloadAsync()
{
// Unload the feature
await Task.CompletedTask;
}
}
2 changes: 1 addition & 1 deletion AvaloniaVS.Shared/Services/EditorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public int CreateEditorInstance(

ppunkDocView = IntPtr.Zero;
ppunkDocData = IntPtr.Zero;
pguidCmdUI = Guids.AvaloniaDesignerEditorFactory;
pguidCmdUI = Constants.AvaloviaFactoryEditorGuid;
pgrfCDW = 0;
pbstrEditorCaption = string.Empty;

Expand Down
2 changes: 1 addition & 1 deletion AvaloniaVS.Shared/Views/EditorPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private void HandleBuildDone(vsBuildScope Scope, vsBuildAction Action)

int IVsDeferredDocView.get_CmdUIGuid(out System.Guid pGuidCmdId)
{
pGuidCmdId = Guids.AvaloniaDesignerEditorFactory;
pGuidCmdId = Constants.AvaloviaFactoryEditorGuid;
return VSConstants.S_OK;
}

Expand Down