Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 0 additions & 11 deletions MCPForUnity/Editor/Tools/ManageScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#if USE_ROSLYN
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Formatting;
#endif

#if UNITY_EDITOR
Expand Down Expand Up @@ -740,16 +739,6 @@ private static object ApplyTextEdits(
int endLineRos = firstLine + 5;
return new ErrorResponse("syntax_error", new { status = "syntax_error", diagnostics, evidenceWindow = new { startLine = startLineRos, endLine = endLineRos } });
}

// Optional formatting
try
{
var root = tree.GetRoot();
var workspace = new AdhocWorkspace();
root = Microsoft.CodeAnalysis.Formatting.Formatter.Format(root, workspace);
working = root.ToFullString();
}
catch { }
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@ public void EditorAsmdef_ReferencesEveryDllRoslynInstallerInstalls()
+ string.Join(", ", missing));
}

/// <summary>
/// RoslynInstaller ships the compiler layer only (Microsoft.CodeAnalysis + CSharp). The
/// Workspaces layer (AdhocWorkspace, Formatter, Microsoft.CodeAnalysis.Formatting) lives in
/// Microsoft.CodeAnalysis.Workspaces.dll / Microsoft.CodeAnalysis.CSharp.Workspaces.dll, which
/// the installer does not download and the asmdef does not reference. Any use of it under
/// USE_ROSLYN turns into CS0234 the moment the define is enabled (issue #1391).
/// </summary>
[Test]
public void EditorSources_DoNotUseRoslynWorkspacesLayer()
{
string[] workspacesApis =
{
"Microsoft.CodeAnalysis.Formatting",
"Microsoft.CodeAnalysis.Workspaces",
"AdhocWorkspace",
};

string editorRoot = Path.GetDirectoryName(ReadEditorAsmdefPath());
List<string> offenders = new List<string>();
foreach (string file in Directory.GetFiles(editorRoot, "*.cs", SearchOption.AllDirectories))
{
string source = File.ReadAllText(file);
foreach (string api in workspacesApis)
{
if (source.IndexOf(api, StringComparison.Ordinal) >= 0)
{
offenders.Add($"{Path.GetFileName(file)} uses {api}");
}
}
}

CollectionAssert.IsEmpty(offenders,
"MCPForUnity.Editor must only use the Roslyn compiler layer that RoslynInstaller installs; "
+ "the Workspaces layer is not shipped or referenced, so USE_ROSLYN would fail to compile. Found: "
+ string.Join(", ", offenders));
}

private static List<string> GetInstallerDllNames()
{
FieldInfo field = typeof(RoslynInstaller).GetField(
Expand All @@ -57,11 +94,16 @@ private static List<string> GetInstallerDllNames()
}

private static string ReadEditorAsmdefJson()
{
return File.ReadAllText(ReadEditorAsmdefPath());
}

private static string ReadEditorAsmdefPath()
{
string path = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName("MCPForUnity.Editor");
Assert.IsFalse(string.IsNullOrEmpty(path), "Could not locate MCPForUnity.Editor.asmdef");
Assert.IsTrue(File.Exists(path), $"asmdef path does not exist: {path}");
return File.ReadAllText(path);
return path;
}
}
}