Forge
csharpdeeb25a2
1#nullable enable
2using CascadeIDE.Contracts;
3
4namespace CascadeIDE.Features.Chat;
5
6/// <summary>Нормализация путей в хвосте slash workspace/file (ADR 0125).</summary>
7public static class ChatSlashWorkspacePathHelper
8{
9 public static string? NormalizeArgsTail(string? tail) =>
10 ChatSlashCommandPresentation.NormalizeArgsTail(tail);
11
12 public static bool TryNormalizePathArgument(
13 string? tail,
14 string? workspaceRoot,
15 out string? fullPath,
16 out string? error)
17 {
18 fullPath = null;
19 error = null;
20 var trimmed = NormalizeArgsTail(tail);
21 if (string.IsNullOrWhiteSpace(trimmed))
22 {
23 error = "Укажи путь в хвосте команды.";
24 return false;
25 }
26
27 var unquoted = Unquote(trimmed);
28 try
29 {
30 if (Path.IsPathRooted(unquoted))
31 fullPath = CanonicalFilePath.Normalize(unquoted);
32 else if (string.IsNullOrWhiteSpace(workspaceRoot))
33 fullPath = CanonicalFilePath.Normalize(unquoted);
34 else
35 fullPath = CanonicalFilePath.Normalize(Path.Combine(workspaceRoot.Trim(), unquoted));
36 }
37 catch (Exception ex)
38 {
39 error = "Некорректный путь: " + ex.Message;
40 return false;
41 }
42
43 return true;
44 }
45
46 private static string Unquote(string value)
47 {
48 if (value.Length >= 2
49 && ((value[0] == '"' && value[^1] == '"') || (value[0] == '\'' && value[^1] == '\'')))
50 {
51 return value[1..^1];
52 }
53
54 return value;
55 }
56}
57
View only · write via MCP/CIDE