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

Set the correct toggled state as soon as the solution is fully loaded #15

Merged
merged 3 commits into from
Aug 21, 2018

Conversation

jnm2
Copy link
Contributor

@jnm2 jnm2 commented Jul 25, 2018

Fixes #13.

/cc @sharwell, @jcansdale

public EnvDTE.DTE ApplicationObject
{
get
{
return ServiceProvider.GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE;
return GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's either GetService, or JTF.Run on GetServiceAsync in BeforeQueryStatus and InvokeHandler.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it will be called on the UI thread, so GetService is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if somehow it wasn't called on the UI thread, we'd still need to switch to the UI thread because DTE isn't free-threaded, correct? So pretty much no matter what, this needs to be GetService?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using DTE on non-UI threads for years and it generally doesn't care. If you're being pedantic you should assume it isn't free-threaded. 😉

Copy link

@jcansdale jcansdale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good apart from needing a AllowsBackgroundLoading = true.

using IMenuCommandService = System.ComponentModel.Design.IMenuCommandService;
using Task = System.Threading.Tasks.Task;

[Guid(JustMyCodeToggleConstants.guidJustMyCodeTogglePackageString)]
[PackageRegistration(UseManagedResourcesOnly = true)]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be:

[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]

AllowsBackgroundLoading = true is like a master switch that allows the package to load on a b/g thread. PackageAutoLoadFlags.BackgroundLoad is just a hint for that particular ProvideAutoLoad.

public EnvDTE.DTE ApplicationObject
{
get
{
return ServiceProvider.GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE;
return GetService(typeof(EnvDTE._DTE)) as EnvDTE.DTE;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it will be called on the UI thread, so GetService is fine.

Copy link

@jcansdale jcansdale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

{
base.Initialize();
await JoinableTaskFactory.SwitchToMainThreadAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗️ Propagate cancellationToken

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, thanks. ReSharper usually tells me about this. :'(


var mcs = (IMenuCommandService)GetService(typeof(IMenuCommandService));
var mcs = (IMenuCommandService)await GetServiceAsync(typeof(IMenuCommandService));
Copy link
Member

@sharwell sharwell Aug 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗️ Use Assumes.Present after GetServiceAsync:

var mcs = (IMenuCommandService)await GetServiceAsync(typeof(IMenuCommandService));
Assumes.Present(mcs);

[ProvideMenuResource(1000, 1)]
internal class JustMyCodeTogglePackage : Package
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_string, PackageAutoLoadFlags.BackgroundLoad)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 This seems like a reasonable context for this

{
base.Initialize();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 It appears code typically calls the base implementation, but it's not sure if this is required:

await base.InitializeAsync(cancellationToken, progress);

// Rest of initialization ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had checked that it was returning CompletedTask, but the very fact that I had to check makes me suspicious of looking in the first place. Funny enough, this was the last PR before I started leaving base calls in my overrides. :D

@jnm2
Copy link
Contributor Author

jnm2 commented Aug 21, 2018

@sharwell Updated.

@@ -1,19 +1,24 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using Microsoft;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This should have been inside the namespace, but it also should have been detected by the build. I'll fix it in a follow-up pull request where I enable StyleCop Analyzers.

@sharwell sharwell merged commit b2482a3 into tunnelvisionlabs:master Aug 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants