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

Consume newer Roslyn APIs for language services #9455

Merged
merged 22 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
29 changes: 17 additions & 12 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<!--
NOTE packages and their versions listed here must be specified in the dotnet-project-system-public-packages feed here:
https://dev.azure.com/azure-public/vside/_artifacts/feed/dotnet-project-system-public-packages
-->

<ItemGroup>
<!-- Infrastructure -->
<!-- This package is deprecated. CodecovUploader is now the recommended package. -->
Expand All @@ -26,18 +31,18 @@
<PackageVersion Include="Microsoft.VisualStudio.Internal.MicroBuild.NpmPack" Version="2.0.117" />
<PackageVersion Include="Microsoft.VisualStudio.Internal.MicroBuild.Swix" Version="2.0.115" />
<PackageVersion Include="Microsoft.VisualStudio.Internal.MicroBuild.Vsman" Version="2.0.115" />
<PackageVersion Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="1.0.0" />
drewnoakes marked this conversation as resolved.
Show resolved Hide resolved
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.79-alpha" />
<PackageVersion Include="Nerdbank.Streams" Version="2.10.69" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<PackageVersion Include="StreamJsonRpc" Version="2.18.48" />

<!-- VS SDK -->
<!-- https://dev.azure.com/azure-public/vside/_artifacts/feed/vssdk -->
<PackageVersion Include="EnvDTE" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.Internal.VisualStudio.Interop" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.ServiceHub.Framework" Version="4.3.57" />
<PackageVersion Include="Microsoft.ServiceHub.Framework" Version="4.4.23" />
<PackageVersion Include="Microsoft.VisualStudio.ComponentModelHost" Version="17.3.198" />
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.7.29" />
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.10.8-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Data.Core" Version="17.0.0-preview-2-31223-026" />
<PackageVersion Include="Microsoft.VisualStudio.Data.Services" Version="17.0.0-preview-2-31223-026" />
<PackageVersion Include="Microsoft.VisualStudio.DataDesign.Common" Version="17.0.0-preview-2-31223-026" />
Expand All @@ -56,13 +61,13 @@
<PackageVersion Include="Microsoft.VisualStudio.Shell.Framework" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.Telemetry" Version="17.8.9" />
<PackageVersion Include="Microsoft.VisualStudio.TemplateWizardInterface" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.9.28" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.10.45" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.45" />
<PackageVersion Include="Microsoft.VisualStudio.Utilities" Version="17.7.36307-preview.2" />
<PackageVersion Include="Microsoft.VisualStudio.Validation" Version="17.8.8" />
<PackageVersion Include="Microsoft.VisualStudio.XmlEditor" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VSSDK.BuildTools" Version="17.5.18-preview1" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="8.0.0" />
<PackageVersion Include="Microsoft.VSDesigner" Version="17.0.0-preview-2-31223-026" />
<PackageVersion Include="VsWebSite.Interop" Version="16.8.30523.219" />

Expand All @@ -77,18 +82,18 @@
<PackageVersion Include="Microsoft.VisualStudio.ProjectSystem.XamlTypes" Version="$(CPSPackageVersion)" />

<!-- Roslyn -->
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.8.0-3.final" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0-3.final" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="4.11.0-1.24225.10" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.11.0-1.24225.10" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.10.0-3.24157.9" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.11.0-1.24225.10" />
drewnoakes marked this conversation as resolved.
Show resolved Hide resolved
<PackageVersion Include="Microsoft.VisualStudio.IntegrationTest.Utilities" Version="2.6.0-beta1-62113-02" />
<PackageVersion Include="Microsoft.VisualStudio.LanguageServices" Version="4.8.0-3.final" />
<PackageVersion Include="Microsoft.VisualStudio.LanguageServices" Version="4.11.0-1.24225.10" />

<!-- Analyzers -->
<PackageVersion Include="CSharpIsNullAnalyzer" Version="0.1.329" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.23472.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.8.0-3.final" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle" Version="4.8.0-3.final" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeStyle" Version="4.11.0-1.24225.10" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeStyle" Version="4.11.0-1.24225.10" />
<PackageVersion Include="Roslyn.Diagnostics.Analyzers" Version="3.11.0-beta1.23472.1" />

<!-- NuGet -->
Expand Down
5 changes: 3 additions & 2 deletions eng/imports/HostAgnostic.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
https://github.com/dotnet/sourcelink#using-source-link-in-net-projects
-->
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
<!-- Path Property: PkgMicrosoft_VisualStudioEng_MicroBuild_Core -->
<PackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" PrivateAssets="all" GeneratePathProperty="true" />
<!-- Note: We require Nerdbank.GitVersioning beyond simply generating version numbers. It also produces some assembly information such as AssemblyName and PublicKeyToken into a *.ThisAssembly.cs file. -->
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" />
<PackageReference Include="Nerdbank.Streams" ExcludeAssets="all" />
Expand Down Expand Up @@ -58,6 +56,9 @@

<!-- Host-Agnostic Visual Studio -->
<PackageReference Include="Microsoft.VisualStudio.ImageCatalog" />

<!-- To resolve assembly versioning issue by pinning a specific version. Should remove in future when packages fixed. -->
<PackageReference Include="StreamJsonRpc" />
</ItemGroup>

<ItemGroup Condition="'$(IsUnitTestProject)' == 'true'">
Expand Down
1 change: 1 addition & 0 deletions spelling.dic
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ unescape
unescapes
ushort
usings
vbproj
vswhidbey
watson
xaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ItemGroup>
<PackageReference Remove="Microsoft.VisualStudio.ProjectSystem*" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Common\ManagedCodeMarkers.vb">
<Link>ManagedCodeMarkers.vb</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void AddToContextIfNotPresent(IWorkspaceProjectContext context, string f
if (!_paths.Contains(fullPath))
{
logger.WriteLine("Adding additional file '{0}'", fullPath);
context.AddAdditionalFile(fullPath, isActiveContext);
context.AddAdditionalFile(fullPath, folderNames: [], isActiveContext);
bool added = _paths.Add(fullPath);
Assumes.True(added);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ internal class CommandLineNotificationHandler : IWorkspaceUpdateHandler, IComman
public CommandLineNotificationHandler(UnconfiguredProject project)
{
// See FSharpCommandLineParserService.HandleCommandLineNotifications for an example of this export
CommandLineNotifications = new OrderPrecedenceImportCollection<Action<string, BuildOptions, BuildOptions>>(projectCapabilityCheckProvider: project);
CommandLineNotifications = new OrderPrecedenceImportCollection<Action<string?, BuildOptions, BuildOptions>>(projectCapabilityCheckProvider: project);
}

/// <remarks>
/// See <see cref="FSharpCommandLineParserService.HandleCommandLineNotifications"/> for an export.
/// </remarks>
[ImportMany]
public OrderPrecedenceImportCollection<Action<string, BuildOptions, BuildOptions>> CommandLineNotifications { get; }
public OrderPrecedenceImportCollection<Action<string?, BuildOptions, BuildOptions>> CommandLineNotifications { get; }

public void Handle(IWorkspaceProjectContext context, IComparable version, BuildOptions added, BuildOptions removed, ContextState state, IManagedProjectDiagnosticOutputService logger)
{
foreach (Lazy<Action<string, BuildOptions, BuildOptions>, IOrderPrecedenceMetadataView> value in CommandLineNotifications)
foreach (Lazy<Action<string?, BuildOptions, BuildOptions>, IOrderPrecedenceMetadataView> value in CommandLineNotifications)
{
value.Value(context.BinOutputPath, added, removed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,14 @@ async Task ApplyInBatchAsync()
isActiveEditorContext: _activeEditorContextTracker.IsActiveEditorContext(ContextId),
isActiveConfiguration: IsPrimary);

Context.StartBatch();

try
{
await using IAsyncDisposable _ = await Context.CreateBatchScopeAsync(cancellationToken);

applyFunc(update, contextState, cancellationToken);
}
finally
{
await Context.EndBatchAsync();

UpdateProgressRegistration();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@
<ItemGroup>
<NpmContent Include="exports.json" />
<!-- We have a runtime dependency on Microsoft.CodeAnalysis.dll in VS Code scenarios. -->
<NpmContent Include="$(PkgMicrosoft_CodeAnalysis_Common)\lib\net7.0\Microsoft.CodeAnalysis.dll" />
<NpmContent Include="$(PkgMicrosoft_CodeAnalysis_Common)\lib\net8.0\Microsoft.CodeAnalysis.dll" />
<NpmContent Include="@(SatelliteDllsProjectOutputGroupOutput)">
<PackagePath>%(SatelliteDllsProjectOutputGroupOutput.TargetPath)</PackagePath>
</NpmContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,13 @@ namespace Microsoft.VisualStudio.ProjectSystem
{
internal partial class IProjectThreadingServiceFactory
{
private class ProjectThreadingService : IProjectThreadingService
private class ProjectThreadingService(bool verifyOnUIThread = true) : IProjectThreadingService
{
private readonly bool _verifyOnUIThread;

public ProjectThreadingService(bool verifyOnUIThread = true) => _verifyOnUIThread = verifyOnUIThread;

#pragma warning disable VSSDK005
public JoinableTaskContextNode JoinableTaskContext { get; } = new JoinableTaskContextNode(new JoinableTaskContext());
#pragma warning restore VSSDK005

public JoinableTaskFactory JoinableTaskFactory => JoinableTaskContext.Factory;

public bool IsOnMainThread
{
get
{
if (!_verifyOnUIThread)
return true;

return JoinableTaskContext.IsOnMainThread;
}
}
public bool IsOnMainThread => !verifyOnUIThread || JoinableTaskContext.IsOnMainThread;

public void ExecuteSynchronously(Func<Task> asyncAction)
{
Expand All @@ -42,16 +27,15 @@ public T ExecuteSynchronously<T>(Func<Task<T>> asyncAction)

public void VerifyOnUIThread()
{
if (!_verifyOnUIThread)
return;

if (!IsOnMainThread)
if (verifyOnUIThread && !IsOnMainThread)
{
throw new InvalidOperationException();
}
}

public IDisposable SuppressProjectExecutionContext()
{
return new DisposableObject();
return DisposableObject.Instance;
}

public void Fork(
Expand All @@ -68,6 +52,8 @@ public void Fork(

private class DisposableObject : IDisposable
{
public static IDisposable Instance { get; } = new DisposableObject();

public void Dispose()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,5 @@ public static IProjectThreadingService Create(bool verifyOnUIThread = true)
{
return new ProjectThreadingService(verifyOnUIThread);
}

public static IProjectThreadingService ImplementVerifyOnUIThread(Action action)
{
var mock = new Mock<IProjectThreadingService>();

mock.Setup(s => s.VerifyOnUIThread())
.Callback(action);

return mock.Object;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public async Task ProjectFileProperties_GetEvaluatedPropertyAsync(string code, s
"""[assembly: System.AssemblyDescriptionAttribute("MyDescription")]""")]
public async Task SourceFileProperties_SetPropertyValueAsync(string code, string propertyName, string propertyValue, string expectedCode)
{
using var _ = SynchronizationContextUtil.Suppress();
drewnoakes marked this conversation as resolved.
Show resolved Hide resolved

var provider = CreateProviderForSourceFileValidation(code, out Workspace workspace);
var projectFilePath = workspace.CurrentSolution.Projects.First().FilePath;
Assumes.NotNull(projectFilePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

namespace Microsoft.VisualStudio;

internal static class SynchronizationContextUtil
drewnoakes marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Sets a <see langword="null"/> <see cref="SynchronizationContext"/>, and restores
/// whatever context was <see cref="SynchronizationContext.Current"/> when disposed.
/// </summary>
/// <remarks>
/// This method is intended for use in tests where we use JTF and test code that
/// wants to switch to the main thread. Some of our tests don't actually construct
/// JTF in a way that creates a main thread that can be switched to. For these cases,
/// whatever thread creates the <see cref="Threading.JoinableTaskContext"/> is considered
/// the main thread. In unit tests, it's likely this is a thread pool thread, and
/// attempting to switch to the main thread will land on another thread pool thread.
/// <see cref="Threading.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken)"/>
/// attempts to validate the switch was successful, and throws when not. This causes test
/// failures where we don't have a main thread to switch to. A workaround for this is
/// to suppress the synchronization context, which disables the check and allows the test
/// to pass.
/// </remarks>
/// <returns>An object that restores the previous synchronization context when disposed.</returns>
public static IDisposable Suppress()
{
SynchronizationContext old = SynchronizationContext.Current;

SynchronizationContext.SetSynchronizationContext(null);

return new SuppressionReleaser(old);
}

private sealed class SuppressionReleaser(SynchronizationContext old) : IDisposable
{
private int _isDisposed;

public void Dispose()
{
if (Interlocked.Exchange(ref _isDisposed, 1) is 0)
{
SynchronizationContext.SetSynchronizationContext(old);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ internal class IWorkspaceProjectContextMock : AbstractMock<IWorkspaceProjectCont
public IWorkspaceProjectContextMock()
{
SetupAllProperties();

Mock<IAsyncDisposable> batchScopeDisposable = new();

batchScopeDisposable.Setup(o => o.DisposeAsync());

Setup(o => o.CreateBatchScopeAsync(It.IsAny<CancellationToken>()))
.Returns(new ValueTask<IAsyncDisposable>(batchScopeDisposable.Object));
}
}
}
Loading
Loading