Skip to content

Commit b71749d

Browse files
Перенос переменных в attach, доработка нормализации
1 parent ed6cdae commit b71749d

2 files changed

Lines changed: 46 additions & 11 deletions

File tree

src/VSCode.DebugAdapter/PathHandlingStrategy.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,47 @@ public string ConvertClientPathToDebugger(string clientPath)
7272
string hostWorkspace = Environment.GetEnvironmentVariable("OSCRIPT_DEBUGWORKSPACE_HOST");
7373
string remoteWorkspace = Environment.GetEnvironmentVariable("OSCRIPT_DEBUGWORKSPACE_REMOTE");
7474

75-
if (!string.IsNullOrEmpty(hostWorkspace) && !string.IsNullOrEmpty(remoteWorkspace))
75+
if (!string.IsNullOrWhiteSpace(hostWorkspace) && !string.IsNullOrWhiteSpace(remoteWorkspace))
7676
{
77-
string normalizedClientPath = clientPath.Replace('/', '\\');
78-
string normalizedHostWorkspace = hostWorkspace.Replace('/', '\\');
77+
78+
string normalizedClientPath = clientPath.Replace('/', '\\').Trim();
79+
string normalizedHostWorkspace = hostWorkspace.Replace('/', '\\').Trim();
7980

81+
if (!normalizedHostWorkspace.EndsWith("\\"))
82+
normalizedHostWorkspace += "\\";
83+
84+
if (!normalizedClientPath.EndsWith("\\"))
85+
normalizedClientPath += "\\";
86+
8087
if (normalizedClientPath.StartsWith(normalizedHostWorkspace, StringComparison.OrdinalIgnoreCase))
8188
{
89+
8290
string relativePath = normalizedClientPath.Substring(normalizedHostWorkspace.Length);
91+
relativePath = relativePath.TrimStart('\\');
8392

84-
string normalizedRemote = remoteWorkspace.Replace('\\', '/');
85-
string normalizedRelative = relativePath.Replace('\\', '/');
93+
string normalizedRemote = remoteWorkspace.Trim().Replace('\\', '/');
94+
normalizedRemote = normalizedRemote.TrimEnd('/');
8695

87-
string result = normalizedRemote.TrimEnd('/') + "/" + normalizedRelative.TrimStart('/');
88-
96+
string result = string.IsNullOrEmpty(relativePath)
97+
? normalizedRemote
98+
: normalizedRemote + "/" + relativePath.Replace('\\', '/');
99+
100+
Console.Error.WriteLine($"Path mapped: '{clientPath}' -> '{result}'");
89101
return result;
90102
}
103+
else
104+
{
105+
Console.Error.WriteLine($"Path mapping skipped: '{clientPath}' doesn't start with '{hostWorkspace}'");
106+
}
107+
}
108+
else
109+
{
110+
if (string.IsNullOrWhiteSpace(hostWorkspace) && string.IsNullOrWhiteSpace(remoteWorkspace))
111+
Console.Error.WriteLine("Path mapping: both OSCRIPT_DEBUGWORKSPACE_HOST and OSCRIPT_DEBUGWORKSPACE_REMOTE are not set");
112+
else if (string.IsNullOrWhiteSpace(hostWorkspace))
113+
Console.Error.WriteLine("Path mapping: OSCRIPT_DEBUGWORKSPACE_HOST is not set or empty");
114+
else if (string.IsNullOrWhiteSpace(remoteWorkspace))
115+
Console.Error.WriteLine("Path mapping: OSCRIPT_DEBUGWORKSPACE_REMOTE is not set or empty");
91116
}
92117

93118
if (DebuggerPathsAreUri) {

src/VSCode.DebugAdapter/package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@
8686
"type": "string"
8787
}
8888
},
89-
"default": {
90-
"OSCRIPT_DEBUGWORKSPACE_HOST": "",
91-
"OSCRIPT_DEBUGWORKSPACE_REMOTE": ""
92-
}
89+
"default": null
9390
},
9491
"runtimeExecutable": {
9592
"type": [
@@ -135,6 +132,19 @@
135132
"type": "string",
136133
"description": "Кодировка вывода отлаживаемого приложения. Отладчик будет интерпретировать вывод приложения в указанной кодировке",
137134
"default": ""
135+
},
136+
"env": {
137+
"type": "object",
138+
"description": "Переменные окружения для debug adapter",
139+
"patternProperties": {
140+
"[a-zA-Z_][0-9a-zA-Z_]+": {
141+
"type": "string"
142+
}
143+
},
144+
"default": {
145+
"OSCRIPT_DEBUGWORKSPACE_HOST": "",
146+
"OSCRIPT_DEBUGWORKSPACE_REMOTE": ""
147+
}
138148
}
139149
}
140150
}

0 commit comments

Comments
 (0)