Skip to content

Commit ed6cdae

Browse files
Замена path в source отладки по переменным окружения
1 parent 5897c42 commit ed6cdae

2 files changed

Lines changed: 53 additions & 29 deletions

File tree

src/VSCode.DebugAdapter/PathHandlingStrategy.cs

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,55 @@ public string ConvertDebuggerPathToClient(string path)
6363
}
6464
}
6565

66-
public string ConvertClientPathToDebugger(string clientPath)
67-
{
68-
if (clientPath == null) {
69-
return null;
70-
}
66+
public string ConvertClientPathToDebugger(string clientPath)
67+
{
68+
if (clientPath == null) {
69+
return null;
70+
}
7171

72-
if (DebuggerPathsAreUri) {
73-
if (ClientPathsAreUri) {
74-
return clientPath;
75-
}
76-
else {
77-
var uri = new System.Uri(clientPath);
78-
return uri.AbsoluteUri;
79-
}
80-
}
81-
else {
82-
if (ClientPathsAreUri) {
83-
if (Uri.IsWellFormedUriString(clientPath, UriKind.Absolute)) {
84-
Uri uri = new Uri(clientPath);
85-
return uri.LocalPath;
86-
}
87-
Console.Error.WriteLine("path not well formed: '{0}'", clientPath);
88-
return null;
89-
}
90-
else {
91-
return clientPath;
92-
}
93-
}
94-
}
72+
string hostWorkspace = Environment.GetEnvironmentVariable("OSCRIPT_DEBUGWORKSPACE_HOST");
73+
string remoteWorkspace = Environment.GetEnvironmentVariable("OSCRIPT_DEBUGWORKSPACE_REMOTE");
74+
75+
if (!string.IsNullOrEmpty(hostWorkspace) && !string.IsNullOrEmpty(remoteWorkspace))
76+
{
77+
string normalizedClientPath = clientPath.Replace('/', '\\');
78+
string normalizedHostWorkspace = hostWorkspace.Replace('/', '\\');
79+
80+
if (normalizedClientPath.StartsWith(normalizedHostWorkspace, StringComparison.OrdinalIgnoreCase))
81+
{
82+
string relativePath = normalizedClientPath.Substring(normalizedHostWorkspace.Length);
83+
84+
string normalizedRemote = remoteWorkspace.Replace('\\', '/');
85+
string normalizedRelative = relativePath.Replace('\\', '/');
86+
87+
string result = normalizedRemote.TrimEnd('/') + "/" + normalizedRelative.TrimStart('/');
88+
89+
return result;
90+
}
91+
}
92+
93+
if (DebuggerPathsAreUri) {
94+
if (ClientPathsAreUri) {
95+
return clientPath;
96+
}
97+
else {
98+
var uri = new System.Uri(clientPath);
99+
return uri.AbsoluteUri;
100+
}
101+
}
102+
else {
103+
if (ClientPathsAreUri) {
104+
if (Uri.IsWellFormedUriString(clientPath, UriKind.Absolute)) {
105+
Uri uri = new Uri(clientPath);
106+
return uri.LocalPath;
107+
}
108+
Console.Error.WriteLine("path not well formed: '{0}'", clientPath);
109+
return null;
110+
}
111+
else {
112+
return clientPath;
113+
}
114+
}
115+
}
95116
}
96117
}

src/VSCode.DebugAdapter/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@
8686
"type": "string"
8787
}
8888
},
89-
"default": null
89+
"default": {
90+
"OSCRIPT_DEBUGWORKSPACE_HOST": "",
91+
"OSCRIPT_DEBUGWORKSPACE_REMOTE": ""
92+
}
9093
},
9194
"runtimeExecutable": {
9295
"type": [

0 commit comments

Comments
 (0)