Skip to content

Commit

Permalink
Simplify using non-generic TaskCompletionSource polyfill
Browse files Browse the repository at this point in the history
.NET Core defines a non-generic `System.Threading.Tasks.TaskCompletionSource`. This would be handy in .NET Framework too, so we defined our own version of this as a polyfill. However ours was in the `Microsoft.VisualStudio.Threading.Tasks` namespace.

Once we started multi-targeting to .NET Framework and .NET Core, this mismatch created issues. That was worked around with an alias. The approach in this change reduces the friction and improves discoverability of this type. With this, we won't see "ambiguous type" warnings in new code any more.
  • Loading branch information
drewnoakes committed Oct 6, 2023
1 parent 0e3a298 commit fea9bc3
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
using Microsoft.VisualStudio.ProjectSystem.Utilities;
using Microsoft.VisualStudio.Threading;

// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not.
// For consistency, always use the one we define.
using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource;

namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
using Microsoft.VisualStudio.ProjectSystem.Utilities;
using Microsoft.VisualStudio.Threading;

// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not.
// For consistency, always use the one we define.
using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource;

namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading;
using Microsoft.VisualStudio.Threading.Tasks;

namespace Microsoft.VisualStudio.ProjectSystem.VS
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not.
// For consistency, always use the one we define.
using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource;

namespace Microsoft.VisualStudio.ProjectSystem.Build
{
[Export(typeof(IConfiguredProjectReadyToBuild))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
using Microsoft.VisualStudio.Threading;
using Microsoft.VisualStudio.Threading.Tasks;

// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not.
// For consistency, always use the one we define.
using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource;

namespace Microsoft.VisualStudio.ProjectSystem.Debug
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

using Microsoft.VisualStudio.Threading;

// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not.
// For consistency, always use the one we define.
using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource;

namespace Microsoft.VisualStudio.ProjectSystem
{
[Export]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

#if NETFRAMEWORK

using System.ComponentModel;

namespace Microsoft.VisualStudio.Threading.Tasks
namespace System.Threading.Tasks
{
/// <inheritdoc cref="TaskCompletionSource{TResult}"/>
/// <remarks>
Expand Down Expand Up @@ -54,3 +56,5 @@ public bool TrySetResult()
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using Microsoft.VisualStudio.Threading.Tasks;
using Xunit.Sdk;

namespace Microsoft.VisualStudio.ProjectSystem.VS.TempPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.LanguageServices;
using Microsoft.VisualStudio.Telemetry;
using Microsoft.VisualStudio.Threading.Tasks;
using Xunit.Sdk;

namespace Microsoft.VisualStudio.ProjectSystem.VS.TempPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Threading.Tasks;
using Xunit.Sdk;

// Nullable annotations don't add a lot of value to this class, and until https://github.com/dotnet/roslyn/issues/33199 is fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using Microsoft.VisualStudio.Threading.Tasks;

namespace Microsoft.VisualStudio.ProjectSystem.VS.Utilities
{
internal static class TestUtil
Expand Down

0 comments on commit fea9bc3

Please sign in to comment.