Skip to content

Conversation

dsarno
Copy link
Collaborator

@dsarno dsarno commented Sep 2, 2025

Summary by CodeRabbit

  • Bug Fixes
    • More reliable uv.exe detection on Windows, including Microsoft Store Python installs.
    • Asset imports now run even when the Unity Editor window is unfocused.
    • Asset paths are normalized to avoid duplicate prefixes and wrong separators during imports.
  • Chores
    • Updated embedded server version to 3.2.0.

…ous ImportAsset and RequestScriptCompilation\n- Debounced refresh calls ImportAsset instead of Refresh\n- Path sanitation for Assets/ and slashes\n- Atomic writes with Windows-safe fallbacks\n- Nudge Editor tick for debounce reliability
Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

Adds a Windows Store Python probe to FindUvPath on Windows, expands asset import scheduling to sanitize paths, nudges the editor loop via QueuePlayerLoopUpdate, and bumps the server version to 3.2.0. Public API adds ManageScriptRefreshHelpers.SanitizeAssetsPath(string).

Changes

Cohort / File(s) Summary
Windows uv discovery
UnityMcpBridge/Editor/Helpers/ServerInstaller.cs
Adds LINQ import; augments FindUvPath() on Windows to probe Windows Store Python packages’ LocalCache/local-packages for uv.exe with validation; probe runs after PATH/where checks and returns early if found; wrapped in try/catch.
Asset refresh and path sanitization
UnityMcpBridge/Editor/Tools/ManageScript.cs
Adds EditorApplication.QueuePlayerLoopUpdate() in Schedule; introduces public ManageScriptRefreshHelpers.SanitizeAssetsPath(string) to normalize asset paths; applies sanitizer in Tick, ScheduleScriptRefresh, and ImportAndRequestCompile before ImportAsset with ForceUpdate and ForceSynchronousImport.
Version bump
UnityMcpBridge/UnityMcpServer~/src/server_version.txt
Updates version from 3.1.1 to 3.2.0.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Editor as Unity Editor
  participant ServerInstaller as ServerInstaller.FindUvPath
  participant OS as Windows FS/Env

  User->>Editor: Trigger uv path resolution
  Editor->>ServerInstaller: FindUvPath()
  ServerInstaller->>OS: Check PATH / where uv.exe
  alt uv.exe found on PATH
    ServerInstaller-->>Editor: Return uv.exe path
  else Not on PATH
    note over ServerInstaller: New probe
    ServerInstaller->>OS: Scan %LOCALAPPDATA%/Packages/PythonSoftwareFoundation.Python.* 
    ServerInstaller->>OS: Traverse LocalCache/local-packages/Python*/Scripts/uv.exe
    alt uv.exe validated
      ServerInstaller-->>Editor: Return uv.exe path (Windows Store)
    else Not found / error
      ServerInstaller->>OS: Fallback to existing candidate resolution
      ServerInstaller-->>Editor: Return candidate or null
    end
  end
Loading
sequenceDiagram
  autonumber
  actor Source as Change Source
  participant Manage as ManageScript (Scheduler)
  participant Helpers as ManageScriptRefreshHelpers
  participant Unity as AssetDatabase/Editor

  Source->>Manage: ScheduleScriptRefresh(relPath)
  Manage->>Helpers: SanitizeAssetsPath(relPath)  Note over Helpers: Normalize slashes, strip prefixes, ensure "Assets/"
  Helpers-->>Manage: sanitizedPath
  Manage->>Unity: Queue import of sanitizedPath
  Manage->>Unity: EditorApplication.QueuePlayerLoopUpdate()  Note over Unity: Nudge loop for unfocused editor
  loop Tick
    Manage->>Helpers: SanitizeAssetsPath(p)
    Helpers-->>Manage: sp
    Manage->>Unity: ImportAsset(sp, ForceUpdate|ForceSynchronousImport)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • msanatan
  • Scriptwonder

Poem

Hop-hop, I sniffed a uv trail,
Through Python burrows where binaries dwell.
I sweep the paths, make slashes align,
Nudge the loop—tick-tock, right on time.
Version seeds sprout 3.2.0—huzzah!
A happy hare ships code with awe. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
UnityMcpBridge/Editor/Helpers/ServerInstaller.cs (1)

573-596: Nice addition: Windows Store (Appx) Python probe for uv.exe.

Good coverage of PythonSoftwareFoundation package layouts and safe try/catch wrapping. One reliability tweak: PATH entries can sometimes be quoted; consider trimming quotes in the later manual PATH scan to avoid false negatives.

Apply this to the manual PATH scan to handle quoted segments:

-                string[] parts = pathEnv.Split(Path.PathSeparator);
-                foreach (string part in parts)
+                string[] parts = pathEnv.Split(Path.PathSeparator);
+                foreach (string part in parts)
                 {
                     try
                     {
-                        // Check both uv and uv.exe
-                        string candidateUv = Path.Combine(part, "uv");
-                        string candidateUvExe = Path.Combine(part, "uv.exe");
+                        // Check both uv and uv.exe; trim surrounding quotes on PATH entries
+                        var dir = (part ?? string.Empty).Trim().Trim('"');
+                        if (string.IsNullOrWhiteSpace(dir)) continue;
+                        string candidateUv = Path.Combine(dir, "uv");
+                        string candidateUvExe = Path.Combine(dir, "uv.exe");
                         if (File.Exists(candidateUv) && ValidateUvBinary(candidateUv)) return candidateUv;
                         if (File.Exists(candidateUvExe) && ValidateUvBinary(candidateUvExe)) return candidateUvExe;
                     }
                     catch { }
                 }
UnityMcpBridge/Editor/Tools/ManageScript.cs (4)

2571-2573: Guard QueuePlayerLoopUpdate by Unity version to avoid compile breaks on older editors.

Safe no-op on older versions; keeps the “nudge” on supported versions.

Apply:

-        // Nudge the editor loop so ticks run even if the window is unfocused
-        EditorApplication.QueuePlayerLoopUpdate();
+        // Nudge the editor loop so ticks run even if the window is unfocused
+#if UNITY_2020_2_OR_NEWER
+        EditorApplication.QueuePlayerLoopUpdate();
+#endif

2600-2604: Sanitizing before import is good; add a null/empty guard to be defensive.

Prevents accidental null path imports if a caller ever passes empty.

-            foreach (var p in toImport)
-            {
-                var sp = ManageScriptRefreshHelpers.SanitizeAssetsPath(p);
-                AssetDatabase.ImportAsset(sp, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
-            }
+            foreach (var p in toImport)
+            {
+                var sp = ManageScriptRefreshHelpers.SanitizeAssetsPath(p);
+                if (string.IsNullOrEmpty(sp)) continue;
+                AssetDatabase.ImportAsset(sp, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
+            }

2615-2626: Scope the method to internal for clarity.

The containing type isn’t public; making the method public suggests an API surface that isn’t actually exposed. Prefer internal for consistency.

-    public static string SanitizeAssetsPath(string p)
+    internal static string SanitizeAssetsPath(string p)

2636-2640: Defensive guard before ImportAsset.

Mirror the Tick() check to avoid null path imports if called directly.

-        var sp = SanitizeAssetsPath(relPath);
+        var sp = SanitizeAssetsPath(relPath);
+        if (string.IsNullOrEmpty(sp)) return;
         var opts = ImportAssetOptions.ForceUpdate;
         if (synchronous) opts |= ImportAssetOptions.ForceSynchronousImport;
         AssetDatabase.ImportAsset(sp, opts);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 35e7d89 and 96326ee.

📒 Files selected for processing (3)
  • UnityMcpBridge/Editor/Helpers/ServerInstaller.cs (2 hunks)
  • UnityMcpBridge/Editor/Tools/ManageScript.cs (3 hunks)
  • UnityMcpBridge/UnityMcpServer~/src/server_version.txt (1 hunks)
🔇 Additional comments (3)
UnityMcpBridge/UnityMcpServer~/src/server_version.txt (1)

1-1: Version bump acknowledged (3.2.0).

Matches the installer’s semver compare flow; no further action.

UnityMcpBridge/Editor/Helpers/ServerInstaller.cs (1)

6-6: LINQ import looks necessary.

Required for OrderByDescending in the Windows Store probe.

UnityMcpBridge/Editor/Tools/ManageScript.cs (1)

2630-2632: LGTM: Centralizing sanitize at scheduling call site.

Reduces downstream surprises and normalizes inputs early.

@dsarno dsarno merged commit c27b8bf into CoplayDev:main Sep 2, 2025
1 check passed
@dsarno dsarno deleted the fix/winstore-uv-detection branch September 5, 2025 22:44
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.

1 participant