Skip to content

Commit 6312ec2

Browse files
committed
Update
1 parent 88fc8f1 commit 6312ec2

2 files changed

Lines changed: 51 additions & 29 deletions

File tree

MCPForUnity/Editor/Tools/ExecuteCode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class ExecuteCode
1818
private const int MaxCodeLength = 50000;
1919
private const int MaxHistoryEntries = 50;
2020
private const int MaxHistoryCodePreview = 500;
21-
private const int WrapperLineOffset = 10;
21+
internal const int WrapperLineOffset = 10;
2222
private const string WrapperClassName = "MCPDynamicCode";
2323
private const string WrapperMethodName = "Execute";
2424

@@ -141,6 +141,7 @@ private static object HandleGetHistory(JObject @params)
141141
e.elapsedMs,
142142
e.timestamp,
143143
e.safetyChecksEnabled,
144+
e.compiler,
144145
}).ToList(),
145146
});
146147
}
@@ -658,7 +659,7 @@ public static Assembly Compile(string source, string[] assemblyPaths, out List<s
658659
var msgProp = diag.GetType().GetMethod("GetMessage", new[] { typeof(System.Globalization.CultureInfo) });
659660
string msg = (string)msgProp.Invoke(diag, new object[] { null });
660661

661-
int userLine = Math.Max(1, line + 1 - 10); // WrapperLineOffset
662+
int userLine = Math.Max(1, line + 1 - ExecuteCode.WrapperLineOffset);
662663
errors.Add($"Line {userLine}: {msg}");
663664
}
664665
return null;

MCPForUnity/Editor/Windows/MCPForUnityEditorWindow.cs

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,11 @@ private static void BuildDependenciesSection(VisualElement container)
749749
installAllButton.SetEnabled(false);
750750
installAllButton.text = "Installing...";
751751
if (!RoslynInstaller.IsInstalled()) RoslynInstaller.Install(interactive: false);
752-
BatchUpmAdd(upmPackages);
752+
BatchUpmAdd(upmPackages, () =>
753+
{
754+
installAllButton.SetEnabled(true);
755+
installAllButton.text = "Install All";
756+
});
753757
});
754758
installAllButton.text = "Install All";
755759
installAllButton.AddToClassList("action-button");
@@ -765,7 +769,11 @@ private static void BuildDependenciesSection(VisualElement container)
765769
uninstallAllButton.SetEnabled(false);
766770
uninstallAllButton.text = "Removing...";
767771
UninstallRoslyn();
768-
BatchUpmRemove(upmPackages);
772+
BatchUpmRemove(upmPackages, () =>
773+
{
774+
uninstallAllButton.SetEnabled(true);
775+
uninstallAllButton.text = "Uninstall All";
776+
});
769777
});
770778
uninstallAllButton.text = "Uninstall All";
771779
uninstallAllButton.AddToClassList("action-button");
@@ -869,32 +877,44 @@ private static void AddDependencyRow(VisualElement parent, string name, string d
869877

870878
if (!isInstalled && installAction != null)
871879
{
872-
Button installButton = null;
873-
installButton = new Button(() =>
880+
Button btn = null;
881+
btn = new Button(() =>
874882
{
875-
installButton.SetEnabled(false);
876-
installButton.text = "Installing...";
877-
installAction();
883+
btn.SetEnabled(false);
884+
btn.text = "Installing...";
885+
try { installAction(); }
886+
catch (Exception e)
887+
{
888+
Debug.LogError($"[MCP] Install failed: {e.Message}");
889+
btn.SetEnabled(true);
890+
btn.text = "Install";
891+
}
878892
});
879-
installButton.text = "Install";
880-
installButton.AddToClassList("action-button");
881-
buttonRow.Add(installButton);
893+
btn.text = "Install";
894+
btn.AddToClassList("action-button");
895+
buttonRow.Add(btn);
882896
}
883897

884898
if (isInstalled && uninstallAction != null)
885899
{
886-
Button uninstallButton = null;
887-
uninstallButton = new Button(() =>
900+
Button btn = null;
901+
btn = new Button(() =>
888902
{
889903
if (!EditorUtility.DisplayDialog("Remove " + name,
890904
$"Are you sure you want to remove {name}?", "Remove", "Cancel")) return;
891-
uninstallButton.SetEnabled(false);
892-
uninstallButton.text = "Removing...";
893-
uninstallAction();
905+
btn.SetEnabled(false);
906+
btn.text = "Removing...";
907+
try { uninstallAction(); }
908+
catch (Exception e)
909+
{
910+
Debug.LogError($"[MCP] Uninstall failed: {e.Message}");
911+
btn.SetEnabled(true);
912+
btn.text = "Uninstall";
913+
}
894914
});
895-
uninstallButton.text = "Uninstall";
896-
uninstallButton.AddToClassList("action-button");
897-
buttonRow.Add(uninstallButton);
915+
btn.text = "Uninstall";
916+
btn.AddToClassList("action-button");
917+
buttonRow.Add(btn);
898918
}
899919

900920
if (buttonRow.childCount > 0)
@@ -903,31 +923,31 @@ private static void AddDependencyRow(VisualElement parent, string name, string d
903923
parent.Add(row);
904924
}
905925

906-
private static void InstallUpmPackage(string packageId)
926+
private static void InstallUpmPackage(string packageId, Action onComplete = null)
907927
{
908-
BatchUpmAdd(new[] { packageId });
928+
BatchUpmAdd(new[] { packageId }, onComplete);
909929
}
910930

911-
private static void RemoveUpmPackage(string packageId)
931+
private static void RemoveUpmPackage(string packageId, Action onComplete = null)
912932
{
913-
BatchUpmRemove(new[] { packageId });
933+
BatchUpmRemove(new[] { packageId }, onComplete);
914934
}
915935

916-
private static void BatchUpmAdd(string[] packageIds)
936+
private static void BatchUpmAdd(string[] packageIds, Action onComplete = null)
917937
{
918938
var request = UnityEditor.PackageManager.Client.AddAndRemove(packageIds, null);
919939
EditorUtility.DisplayProgressBar("Installing Packages", $"Installing {packageIds.Length} package(s)...", 0.5f);
920-
PollUpmRequest(request, "install");
940+
PollUpmRequest(request, "install", onComplete);
921941
}
922942

923-
private static void BatchUpmRemove(string[] packageIds)
943+
private static void BatchUpmRemove(string[] packageIds, Action onComplete = null)
924944
{
925945
var request = UnityEditor.PackageManager.Client.AddAndRemove(null, packageIds);
926946
EditorUtility.DisplayProgressBar("Removing Packages", $"Removing {packageIds.Length} package(s)...", 0.5f);
927-
PollUpmRequest(request, "remove");
947+
PollUpmRequest(request, "remove", onComplete);
928948
}
929949

930-
private static void PollUpmRequest(UnityEditor.PackageManager.Requests.AddAndRemoveRequest request, string verb)
950+
private static void PollUpmRequest(UnityEditor.PackageManager.Requests.AddAndRemoveRequest request, string verb, Action onComplete)
931951
{
932952
EditorApplication.CallbackFunction pollCallback = null;
933953
pollCallback = () =>
@@ -939,6 +959,7 @@ private static void PollUpmRequest(UnityEditor.PackageManager.Requests.AddAndRem
939959
Debug.Log($"[MCP] Package {verb} succeeded.");
940960
else
941961
Debug.LogError($"[MCP] Package {verb} failed: {request.Error?.message}");
962+
onComplete?.Invoke();
942963
};
943964
EditorApplication.update += pollCallback;
944965
}

0 commit comments

Comments
 (0)