Forge
csharpcf25d736
1#nullable enable
2
3namespace CascadeIDE.Services.Lsp;
4
5/// <summary>file:// URI и пути для LSP (общий слой для C#, Marksman и др.).</summary>
6public static class LspFileUri
7{
8 public static string NormalizePath(string path) =>
9 CanonicalFilePath.Normalize(path);
10
11 public static string PathToFileUri(string fullPath)
12 {
13 var full = CanonicalFilePath.Normalize(fullPath);
14 return new Uri(full).AbsoluteUri;
15 }
16
17 public static bool TryUriToPath(string uri, out string path)
18 {
19 path = "";
20 try
21 {
22 var u = new Uri(uri);
23 path = u.LocalPath;
24 if (OperatingSystem.IsWindows() && path.StartsWith('/') && path.Length > 2 && path[2] == ':')
25 path = path.TrimStart('/');
26 return !string.IsNullOrEmpty(path);
27 }
28 catch
29 {
30 return false;
31 }
32 }
33}
34
View only · write via MCP/CIDE