Merge pull request #18 from zhust2003/master

Add macOS and Linux support for finding and reusing Cursor workspace instances
This commit is contained in:
boxqkrtm
2025-05-19 18:52:25 +09:00
committed by GitHub
2 changed files with 46 additions and 4 deletions

View File

@@ -125,7 +125,17 @@ namespace Microsoft.Unity.VisualStudio.Editor
{ {
var workspaces = new List<string>(); var workspaces = new List<string>();
var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var cursorStoragePath = Path.Combine(userProfile, "AppData", "Roaming", "cursor", "User", "workspaceStorage"); string cursorStoragePath;
#if UNITY_EDITOR_OSX
cursorStoragePath = Path.Combine(userProfile, "Library", "Application Support", "cursor", "User", "workspaceStorage");
#elif UNITY_EDITOR_LINUX
cursorStoragePath = Path.Combine(userProfile, ".config", "Cursor", "User", "workspaceStorage");
#else
cursorStoragePath = Path.Combine(userProfile, "AppData", "Roaming", "cursor", "User", "workspaceStorage");
#endif
Debug.Log($"[Cursor] Looking for workspaces in: {cursorStoragePath}");
if (Directory.Exists(cursorStoragePath)) if (Directory.Exists(cursorStoragePath))
{ {
@@ -186,6 +196,10 @@ namespace Microsoft.Unity.VisualStudio.Editor
} }
} }
} }
else
{
Debug.LogWarning($"[Cursor] Workspace storage directory not found: {cursorStoragePath}");
}
return workspaces.Distinct().ToArray(); return workspaces.Distinct().ToArray();
} }

View File

@@ -450,10 +450,29 @@ namespace Microsoft.Unity.VisualStudio.Editor {
} }
private Process FindRunningCursorWithSolution(string solutionPath) { private Process FindRunningCursorWithSolution(string solutionPath) {
var directory = IOPath.GetDirectoryName(solutionPath); var normalizedTargetPath = solutionPath.Replace('\\', '/').TrimEnd('/').ToLowerInvariant();
var processes = Process.GetProcessesByName("cursor");
var normalizedTargetPath = directory.Replace('\\', '/').TrimEnd('/').ToLowerInvariant(); #if UNITY_EDITOR_WIN
// Keep as is for Windows platform since path already includes drive letter
#else
// Ensure path starts with / for macOS and Linux platforms
if (!normalizedTargetPath.StartsWith("/")) {
normalizedTargetPath = "/" + normalizedTargetPath;
}
#endif
var processes = new List<Process>();
// Get process name list based on different operating systems
#if UNITY_EDITOR_OSX
processes.AddRange(Process.GetProcessesByName("Cursor"));
processes.AddRange(Process.GetProcessesByName("Cursor Helper"));
#elif UNITY_EDITOR_LINUX
processes.AddRange(Process.GetProcessesByName("cursor"));
processes.AddRange(Process.GetProcessesByName("Cursor"));
#else
processes.AddRange(Process.GetProcessesByName("cursor"));
#endif
foreach (var process in processes) { foreach (var process in processes) {
try { try {
@@ -461,6 +480,15 @@ namespace Microsoft.Unity.VisualStudio.Editor {
if (workspaces != null && workspaces.Length > 0) { if (workspaces != null && workspaces.Length > 0) {
foreach (var workspace in workspaces) { foreach (var workspace in workspaces) {
var normalizedWorkspaceDir = workspace.Replace('\\', '/').TrimEnd('/').ToLowerInvariant(); var normalizedWorkspaceDir = workspace.Replace('\\', '/').TrimEnd('/').ToLowerInvariant();
#if UNITY_EDITOR_WIN
// Keep as is for Windows platform
#else
// Ensure path starts with / for macOS and Linux platforms
if (!normalizedWorkspaceDir.StartsWith("/")) {
normalizedWorkspaceDir = "/" + normalizedWorkspaceDir;
}
#endif
if (string.Equals(normalizedWorkspaceDir, normalizedTargetPath, StringComparison.OrdinalIgnoreCase) || if (string.Equals(normalizedWorkspaceDir, normalizedTargetPath, StringComparison.OrdinalIgnoreCase) ||
normalizedTargetPath.StartsWith(normalizedWorkspaceDir + "/", StringComparison.OrdinalIgnoreCase) || normalizedTargetPath.StartsWith(normalizedWorkspaceDir + "/", StringComparison.OrdinalIgnoreCase) ||