diff options
author | Miguel Costa <miguel.costa@qt.io> | 2024-02-09 17:26:11 +0100 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2024-02-29 14:50:36 +0000 |
commit | 0b18f963094e71b217d6bec97e3518f03051c8c1 (patch) | |
tree | 2d3b8a761d4aa1761f8d3bbc4d8bf3d9bfca53c5 | |
parent | 62adf01da1f9daefc2ffc8dc49b4c7dc2a551b77 (diff) |
Fix package InitializeAsync call delay
Specified some additional auto-load contexts for the AsyncPackage, to
handle the case where VS is started with the option to immediately load
a solution/project.
Also, the wait-event that signals initialization complete is now static
and async. An await for initialization was added to the QML LSP client,
to avoid the consequences of race conditions between MEF and package
initialization.
Change-Id: Ib065e12be1ace5d6275bf178d5ce2e1fc504b7ec
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs | 4 | ||||
-rw-r--r-- | QtVsTools.Package/QML/Language/QmlLspClient.cs | 2 | ||||
-rw-r--r-- | QtVsTools.Package/QtVsToolsPackage.cs | 20 |
3 files changed, 17 insertions, 9 deletions
diff --git a/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs b/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs index 242e0cdf..5b8f56d6 100644 --- a/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs +++ b/QtVsTools.Package/QML/Debugging/QmlDebugLauncher.cs @@ -253,11 +253,11 @@ namespace QtVsTools.Qml.Debug return; ExcludedProcIds.Add(procId); - if (!Package.IsInitialized) + if (!QtVsToolsPackage.IsInitialized) Notifications.NotifyMessage.Show("QML Debugger: Waiting for package initialization..."); await TaskScheduler.Default; - Package.WaitUntilInitialized(); + await QtVsToolsPackage.WaitUntilInitializedAsync(); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); Notifications.NotifyMessage.Close(); LaunchDebug(execPath, cmd, procId); diff --git a/QtVsTools.Package/QML/Language/QmlLspClient.cs b/QtVsTools.Package/QML/Language/QmlLspClient.cs index c7f6f1a7..696ddd77 100644 --- a/QtVsTools.Package/QML/Language/QmlLspClient.cs +++ b/QtVsTools.Package/QML/Language/QmlLspClient.cs @@ -74,6 +74,8 @@ namespace QtVsTools.Qml.Language public async Task OnLoadedAsync() { + await QtVsToolsPackage.WaitUntilInitializedAsync(); + if (!Package.Options.QmlLspEnable) Disconnect(); else diff --git a/QtVsTools.Package/QtVsToolsPackage.cs b/QtVsTools.Package/QtVsToolsPackage.cs index a6c6300d..47518184 100644 --- a/QtVsTools.Package/QtVsToolsPackage.cs +++ b/QtVsTools.Package/QtVsToolsPackage.cs @@ -21,6 +21,8 @@ using Microsoft.Win32; using Task = System.Threading.Tasks.Task; +using static Microsoft.VisualStudio.Shell.PackageAutoLoadFlags; + namespace QtVsTools { using Common; @@ -44,8 +46,12 @@ namespace QtVsTools [InstalledProductRegistration(Vsix.Name, Vsix.Description, Version.PRODUCT_VERSION)] [ProvideMenuResource("Menus.ctmenu", 1)] [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] - [ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] - [ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)] + [ProvideAutoLoad(UIContextGuids.SolutionExists, BackgroundLoad)] + [ProvideAutoLoad(UIContextGuids.NoSolution, BackgroundLoad)] + [ProvideAutoLoad(UIContextGuids.EmptySolution, BackgroundLoad)] + [ProvideAutoLoad(UIContextGuids.SolutionHasSingleProject, BackgroundLoad)] + [ProvideAutoLoad(UIContextGuids.SolutionHasMultipleProjects, BackgroundLoad)] + [ProvideAutoLoad(UIContextGuids.CodeWindow, BackgroundLoad)] [ProvideEditorExtension(typeof(Package.MsBuild.ConversionReportViewer), extension: ".qtvscr", @@ -105,8 +111,8 @@ namespace QtVsTools public Editors.QtLinguist QtLinguist { get; private set; } private Editors.QtResourceEditor QtResourceEditor { get; set; } - public EventWaitHandle Initialized { get; } = new(false, EventResetMode.ManualReset); - private bool InitializationAwaited { get; set; } = false; + public static EventWaitHandle Initialized { get; } = new(false, EventResetMode.ManualReset); + private static bool InitializationAwaited { get; set; } = false; public static QtVsToolsPackage Instance { get; private set; } @@ -354,13 +360,13 @@ namespace QtVsTools await base.OnAfterPackageLoadedAsync(cancellationToken); } - public bool WaitUntilInitialized(int timeout = -1) + public static async Task WaitUntilInitializedAsync() { InitializationAwaited = true; - return Initialized.WaitOne(timeout); + await Initialized; } - public bool IsInitialized => WaitUntilInitialized(0); + public static bool IsInitialized => Initialized.WaitOne(0); private async Task CheckVersionsAsync() { |