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

[Editor] Upgrade RolsynPad.Roslyn to v4.8.0 #2124

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

a-tsymbal
Copy link

PR Details

Upgraded RoslynPad.Roslyn* packages to version 4.8.0

Description

Upgraded required packages, added ability for MEF to access internal implementations of contracts using IgnoresAccessChecksToGenerator.

To get access to some required unpublished as Nuget packages contracts from Microsoft.CodeAnalysis.LanguageServer.Protocol namespace added Stride.RestoreHelper. Copied GetLibReferences to other places where Stride.props and Stride.Core.props were not referenced to fix build.

The approach was the same as was used by RoslynPad in relation to Microsoft.CodeAnalysis.* internal dependencies. On Stride side same actions were required in relation to RoslynPad.Roslyn internal dependencies.

! Commented out RoslynWorkspace.EnableDiagnostics() (same happens with DiagnosticProvider.Enable()) call because of error:

  InvalidCastException: Unable to cast object of type 'Stride.Assets.Presentation.AssetEditors.ScriptEditor.StrideRoslynWorkspace' to type 'RoslynPad.Roslyn.RoslynWorkspace'.
     at RoslynPad.Roslyn.DocumentTrackingServiceFactory.DocumentTrackingService..ctor(Workspace workspace)
     at RoslynPad.Roslyn.DocumentTrackingServiceFactory.CreateService(HostWorkspaceServices workspaceServices)
     at Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.<>c__DisplayClass5_0.<.ctor>b__1()
     at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
     at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
     at System.Lazy`1.CreateValue()
     at Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.GetService[TWorkspaceService]()
     at Microsoft.CodeAnalysis.Host.HostWorkspaceServices.GetRequiredService[TWorkspaceService]()
     at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.WorkCoordinator..ctor(IAsynchronousOperationListener listener, IEnumerable`1 analyzerProviders, Boolean initializeLazily, Registration registration)
     at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.EnsureRegistration(Workspace workspace, Boolean initializeLazily)
     at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.Register(Workspace workspace)
     at Microsoft.CodeAnalysis.SolutionCrawler.SolutionCrawlerRegistrationService.Microsoft.CodeAnalysis.SolutionCrawler.ISolutionCrawlerRegistrationService.Register(Workspace workspace)
     at Microsoft.CodeAnalysis.DiagnosticProvider.Enable(Workspace workspace)
     at Stride.Assets.Presentation.AssetEditors.ScriptEditor.StrideRoslynWorkspace..ctor(RoslynHost host) in E:\github\stride\sources\editor\Stride.Assets.Presentation\AssetEditors\ScriptEditor\StrideRoslynWorkspace.cs:line 37
     at Stride.Assets.Presentation.AssetEditors.ScriptEditor.RoslynHost..ctor() in E:\github\stride\sources\editor\Stride.Assets.Presentation\AssetEditors\ScriptEditor\RoslynHost.cs:line 50

Probably MEF is resolving RoslynPad's workspace type instead of Stride's.

! So maybe some things related to diagnostics might stop working.

Related Issue

2043 Fixed issue mentioned in this comment

Motivation and Context

Fixes some functionality related to code analysis in script editor.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

Copy link
Member

@Kryptos-FR Kryptos-FR left a comment

Choose a reason for hiding this comment

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

It might work but it feels very hackish. We shouldn't need all of that to make it work.

Instead, we should either properly reimplement the custom workspace/host or reuse the one provided by RoslynPad library.

Copy link
Member

Choose a reason for hiding this comment

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

What is this file? It seems unrelated to Roslyn.

Copy link
Author

Choose a reason for hiding this comment

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

https://github.com/microsoft/MSBuildSdks/blob/main/src/NoTargets/README.md ("This can be useful for utility projects that just copy files, ...")

This is a helper project to copy requred dll from nuget folder
~.nuget\packages\microsoft.codeanalysis.languageserver.protocol\4.8.0-7.23558.1\lib\net7.0\Microsoft.CodeAnalysis.LanguageServer.Protocol.dll

We use it because now this dll is deprecated on nuget
https://www.nuget.org/packages/Microsoft.CodeAnalysis.LanguageServer.Protocol/3.9.0-5.21120.8

global.json Outdated Show resolved Hide resolved
Comment on lines +6 to +11
<RestoreSources>
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json;
https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json;
https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json;
https://api.nuget.org/v3/index.json
</RestoreSources>
Copy link
Member

Choose a reason for hiding this comment

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

What are those sources?

Copy link
Author

Choose a reason for hiding this comment

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

Comment on lines 36 to 49
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.CSharp" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.Features" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.CSharp.Features" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.CSharp.EditorFeatures" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.Scripting" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.CSharp.Scripting" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.Workspaces" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<InternalsAssemblyName Include="Microsoft.CodeAnalysis.LanguageServer.Protocol" />

<InternalsAssemblyName Include="RoslynPad.Roslyn" />
<InternalsAssemblyName Include="RoslynPad.Roslyn.Windows" />
Copy link
Member

Choose a reason for hiding this comment

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

Why is it needed, and what does it do?

Copy link
Author

Choose a reason for hiding this comment

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

It allows to use internal implementation from other assemblies https://github.com/aelij/IgnoresAccessChecksToGenerator.
E.g implementation of the IDiagnosticsService interface from RoslynPad looks like this https://github.com/roslynpad/roslynpad/blob/main/src/RoslynPad.Roslyn/Diagnostics/DiagnosticsService.cs#L7.
It is internal and I think MEF is not able to find it so we see this error: #2043 (comment)
System.Composition.Hosting.CompositionFailedException: 'No export was found for the contract 'IDiagnosticService'.

Same thing RoslynPad is doing with Microsoft.CodeAnalysis dependencies https://github.com/roslynpad/roslynpad/blob/main/src/RoslynPad.Roslyn/RoslynPad.Roslyn.csproj#L32.

Copy link
Author

Choose a reason for hiding this comment

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

Removed not used internals, left only required.

@@ -2,6 +2,9 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<PropertyGroup>
<RoslynPrivateVersion>4.8.0-7.23558.1</RoslynPrivateVersion>
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't be needed if the <PackageVersion>version is defined in this file.

Copy link
Author

@a-tsymbal a-tsymbal Jan 25, 2024

Choose a reason for hiding this comment

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

It is not defined in this file but we could move this to Stride.RestoreHelper.csproj and set it directly there.

Comment on lines +18 to +22
<Target Name="GetLibReferences" Outputs="@(Reference)">
<ItemGroup>
<Reference Include="$(PkgMicrosoft_CodeAnalysis_LanguageServer_Protocol)/lib/net7.0/*.dll" />
</ItemGroup>
</Target>
Copy link
Member

Choose a reason for hiding this comment

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

How does it work? Where is the reference (documentation) for this trick?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

@Ethereal77
Copy link
Contributor

Instead, we should either properly reimplement the custom workspace/host or reuse the one provided by RoslynPad library.

That won't do. The RoslynPad workspace is not a MSBuild workspace operating on a solution with many projects like Stride does. RoslynPad creates a simple Roslyn workspace per document (as they are independent from one another), and is way simpler than what we have in Stride. Also it has no need to detect external changes, as RoslynPad has all of this "project" structure in memory.

At least, that's the way it was implemented the last time I checked (last year).

I have a prototype I made some time ago where I integrated RoslynPad inside Stride (i.e. not as an assembly reference but as code, to ease customization and get only the needed parts). I had to reimplement some parts of the Stride workspace mixing it with RoslynPad's.

@a-tsymbal
Copy link
Author

Instead, we should either properly reimplement the custom workspace/host or reuse the one provided by RoslynPad library.

When I was working on this PR I wondered why some code looks almost the same as in RoslynPad repository and why it wasn't used. But from this #2124 (comment) explained it.

In this PR I just fixed issue by issue that was happening after upgrading RoslynPad.Roslyn* packages.

@IXLLEGACYIXL
Copy link
Collaborator

IXLLEGACYIXL commented Jan 25, 2024

i cant run this PR , ive ran
git clean -xfd
dotnet restore

but i end up with these errors
it says that language server protocols 4.8 isnt found and that stride presentation dll wasnt found
grafik
https://gist.github.com/IXLLEGACYIXL/54ce8f77f4e0c8b52c29bc49e5f39a08

@a-tsymbal
Copy link
Author

Probably you don't have this package in the .nuget folder.
It is located here: C:\Documents and Settings%user%.nuget\packages\microsoft.codeanalysis.languageserver.protocol\4.8.0-7.23558.1\lib\net7.0\Microsoft.CodeAnalysis.LanguageServer.Protocol.dll

I think it was added there by some of the .NET SDKs as it is not available on nuget website, here is my SDKs:

dotnet --info

.NET SDKs installed:
  7.0.115 [C:\Program Files\dotnet\sdk]
  8.0.101 [C:\Program Files\dotnet\sdk]

@IXLLEGACYIXL
Copy link
Collaborator

Probably you don't have this package in the .nuget folder. It is located here: C:\Documents and Settings%user%.nuget\packages\microsoft.codeanalysis.languageserver.protocol\4.8.0-7.23558.1\lib\net7.0\Microsoft.CodeAnalysis.LanguageServer.Protocol.dll

I think it was added there by some of the .NET SDKs as it is not available on nuget website, here is my SDKs:

dotnet --info

.NET SDKs installed:
  7.0.115 [C:\Program Files\dotnet\sdk]
  8.0.101 [C:\Program Files\dotnet\sdk]

grafik
i have these sdks too

@a-tsymbal a-tsymbal marked this pull request as draft February 18, 2024 08:28
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.

None yet

4 participants