Skip to content

Commit 6d5c1d1

Browse files
committed
OSX fix shorten filepaths
1 parent 6babb62 commit 6d5c1d1

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

package/Editor/Modules/Hyperlinks.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ public static void ApplyHyperlinkColor(ref string stacktrace)
178178
{
179179
if (string.IsNullOrEmpty(stacktrace)) return;
180180
var str = stacktrace;
181+
#if UNITY_EDITOR_OSX
182+
// https://regex101.com/r/C13Nan/1
183+
const string pattern = @"in (?<path>.*?):\d+";
184+
str = Regex.Replace(str, pattern, m =>
185+
{
186+
if (m.Success && SyntaxHighlighting.CurrentTheme.TryGetValue("link", out var col))
187+
{
188+
var path = m.Groups["path"].Value;
189+
ModifyFilePath(ref path);
190+
var col_0 = $"<color={col}>";
191+
var col_1 = "</color>";
192+
var newPath = $"{col_0}{path}{col_1}";
193+
// replace match with new path in m.Value
194+
var res = m.Value.Replace(m.Groups["path"].Value, newPath);
195+
return res;
196+
}
197+
198+
return m.Value;
199+
},
200+
RegexOptions.Compiled);
201+
#else
181202
const string pattern = @"(?<open>\(at )(?<pre><a href=.*?>)(?<path>.*)(?<post><\/a>)(?<close>\))";
182203
str = Regex.Replace(str, pattern, m =>
183204
{
@@ -198,6 +219,7 @@ public static void ApplyHyperlinkColor(ref string stacktrace)
198219
return m.Value;
199220
},
200221
RegexOptions.Compiled);
222+
#endif
201223
stacktrace = str;
202224
}
203225

@@ -213,7 +235,7 @@ private static void ModifyFilePath(ref string path)
213235
// var fileNameIndexStart = path.LastIndexOf('/');
214236
// if (fileNameIndexStart > 0)
215237
// path = path.Substring(fileNameIndexStart + 1);
216-
238+
217239
var isPackageCache = path.Contains("PackageCache");
218240
var match = capturePackageNameInPath.Match(path);
219241
if (match.Success)
@@ -226,7 +248,16 @@ private static void ModifyFilePath(ref string path)
226248
if (isPackageCache) path = "PackageCache/" + path;
227249
}
228250
}
229-
251+
// else
252+
// {
253+
// var pathSegments = path.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
254+
// if (pathSegments.Length >= 2)
255+
// {
256+
// var fileName = pathSegments[^1];
257+
// var parentFolder = pathSegments[^2];
258+
// path = parentFolder + "/" + fileName;
259+
// }
260+
// }
230261
}
231262
}
232263
}

0 commit comments

Comments
 (0)