Skip to content

fix(roslyn): drop Workspaces-layer formatting so USE_ROSLYN compiles with the installer's DLLs - #1404

Open
comedianhhh wants to merge 1 commit into
CoplayDev:betafrom
comedianhhh:fix/roslyn-formatting-needs-workspaces
Open

comedianhhh wants to merge 1 commit into
CoplayDev:betafrom
comedianhhh:fix/roslyn-formatting-needs-workspaces

Conversation

@comedianhhh

@comedianhhh comedianhhh commented Sep 15, 2026

Copy link
Copy Markdown

Description

Enabling USE_ROSLYN after the one-click installer fails with ManageScript.cs(17,30): error CS0234 ... 'Formatting'. The optional post-validation formatting uses AdhocWorkspace + Formatter.Format, which live in the Roslyn Workspaces assemblies; RoslynInstaller and the asmdef only ship/reference the compiler layer. Removing the formatting block (best-effort, inside try/catch, not part of the documented validation feature) fixes the build without pulling Workspaces and its transitive deps into the installer.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Test update

Changes Made

  • ManageScript.cs: remove using Microsoft.CodeAnalysis.Formatting and the AdhocWorkspace/Formatter.Format block under #if USE_ROSLYN.
  • RoslynAsmdefReferenceTests.cs: add EditorSources_DoNotUseRoslynWorkspacesLayer (fails if MCPForUnity/Editor references Microsoft.CodeAnalysis.Formatting, Microsoft.CodeAnalysis.Workspaces, or AdhocWorkspace); share the asmdef path lookup.

Compatibility / Package Source

  • Unity version(s) tested: 6000.6.0f1 (repro + package compile), 6000.0.58f2 (full EditMode run)
  • Package source used: file:../../../MCPForUnity

Testing/Screenshots/Recordings

  • Before: 6000.6.0f1 + the five installer DLLs in Assets/Plugins/Roslyn/ + -define:USE_ROSLYN → the exact CS0234 from the issue.
  • After, 6000.0.58f2 with USE_ROSLYN: EditMode 1244 total / 1162 passed / 80 skipped / 2 failed. The 2 failures (ExecuteCodeTests.Execute_CodedomBackend_*, "YamlDotNet.dll does not contain valid metadata") fail identically with the define off, so they are environmental.
  • Unity EditMode tests
  • Package import/compile check
  • Python tests — not applicable (no Python changes)

Documentation Updates

  • I have added/removed/modified tools or resources — no

Related Issues

Fixes #1391

Additional Notes

Adding Microsoft.CodeAnalysis.CSharp.Workspaces.dll to the asmdef alone would not be enough — AdhocWorkspace and Formatter are in Microsoft.CodeAnalysis.Workspaces.dll, which is not shipped either. If auto-formatting should stay, root.NormalizeWhitespace() is the compiler-layer alternative, but it reformats much more aggressively, so I did not swap it in silently.

Summary by CodeRabbit

  • Bug Fixes

    • Edited scripts are no longer automatically reformatted after validation.
    • Script validation continues to check edits for valid Roslyn syntax.
  • Tests

    • Added coverage to ensure editor scripts use only supported Roslyn compiler components.

…with installer DLLs

ManageScript's optional post-validation formatting used AdhocWorkspace and
Microsoft.CodeAnalysis.Formatting.Formatter, which live in the Roslyn
Workspaces assemblies. RoslynInstaller only ships the compiler layer
(Microsoft.CodeAnalysis + CSharp) and the asmdef only references those, so
enabling USE_ROSLYN via the recommended installer path fails with CS0234.

Remove the formatting block (it was best-effort inside try/catch and is not
part of the documented Roslyn validation feature) and add a regression test
that keeps Workspaces-layer APIs out of MCPForUnity.Editor.

Fixes CoplayDev#1391
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 40fe62c2-6e1c-4f4a-a9ca-d60c1bdf493c

📥 Commits

Reviewing files that changed from the base of the PR and between 2fcc179 and f8e58c6.

📒 Files selected for processing (2)
  • MCPForUnity/Editor/Tools/ManageScript.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup/RoslynAsmdefReferenceTests.cs
💤 Files with no reviewable changes (1)
  • MCPForUnity/Editor/Tools/ManageScript.cs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change removes Roslyn formatting from script edits while retaining syntax validation. It adds a test that rejects Roslyn Workspaces references in editor sources and extracts asmdef path lookup into a helper.

Changes

Roslyn Workspaces Removal

Layer / File(s) Summary
Remove formatting and add source guard
MCPForUnity/Editor/Tools/ManageScript.cs, TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup/RoslynAsmdefReferenceTests.cs
ApplyTextEdits no longer imports or invokes Roslyn formatting. The test scans editor C# sources for prohibited formatting and Workspaces references. The asmdef path lookup now uses a private helper.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to f8e58

The change removes the unsupported Workspaces formatting dependency and adds a guard against reintroducing those APIs. No actionable merge risk remains in the reviewed scope.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: removing the Roslyn Workspaces-layer formatting dependency so USE_ROSLYN compiles with the installer DLLs.
Description check ✅ Passed The description follows the repository template and provides the issue, change details, compatibility information, test results, documentation status, related issue, and additional notes.
Linked Issues check ✅ Passed The PR addresses #1391 by removing the Microsoft.CodeAnalysis.Formatting import and the optional post-validation formatting call from ManageScript.ApplyTextEdits. Roslyn syntax validation remains,…
Out of Scope Changes check ✅ Passed The reported changes are limited to the ManageScript.cs Roslyn dependency removal and a regression test that checks the editor source dependency boundary. The test helper refactor supports the new s…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Missing Microsoft.CodeAnalysis.CSharp.Workspaces.dll causes CS0234 Formatting namespace error in Unity 6

1 participant