Skip to content

Commit 716451b

Browse files
Перенос значений workspace в поля класса
1 parent 9f4d148 commit 716451b

4 files changed

Lines changed: 60 additions & 61 deletions

File tree

src/VSCode.DebugAdapter/DebugeeProcess.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public int ProtocolVersion
5959

6060
public bool WaitOnStart { get; set; }
6161

62+
public string HostWorkspace { get; set; }
63+
64+
public string RemoteWorkspace { get; set; }
65+
6266
public void Start()
6367
{
6468
_process = CreateProcess();
@@ -100,6 +104,7 @@ public void InitAttached()
100104
_attachMode = true;
101105
_process.EnableRaisingEvents = true;
102106
_process.Exited += Process_Exited;
107+
103108
}
104109

105110
public void Init(JObject args)

src/VSCode.DebugAdapter/OscriptDebugSession.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ public override void Attach(Response response, dynamic arguments)
137137
{
138138
LogCommandReceived();
139139
SubscribeForDebuggeeProcessEvents();
140+
140141
_debuggee.DebugPort = GetFromContainer(arguments, "debugPort", 2801);
142+
_debuggee.HostWorkspace = GetFromContainer(arguments, "hostWorkspace", "");
143+
_debuggee.RemoteWorkspace = GetFromContainer(arguments, "remoteWorkspace", "");
141144

142145
DebugClientFactory debugClientFactory;
143146
try
@@ -265,10 +268,49 @@ public override void SetBreakpoints(Response response, dynamic arguments)
265268

266269
private string NormalizeDriveLetter(string path)
267270
{
271+
var clientPath = path;
272+
268273
if (Path.IsPathRooted(path))
269-
return path[0].ToString().ToUpperInvariant() + path.Substring(1);
270-
else
271-
return path;
274+
clientPath = path[0].ToString().ToUpperInvariant() + path.Substring(1);
275+
276+
if (!string.IsNullOrWhiteSpace(_debuggee.HostWorkspace) && !string.IsNullOrWhiteSpace(_debuggee.RemoteWorkspace))
277+
{
278+
279+
var hostWorkspace = _debuggee.HostWorkspace;
280+
var remoteWorkspace = _debuggee.RemoteWorkspace;
281+
282+
string normalizedClientPath = clientPath.Replace('/', '\\').Trim();
283+
string normalizedHostWorkspace = hostWorkspace.Replace('/', '\\').Trim();
284+
285+
if (!normalizedHostWorkspace.EndsWith("\\"))
286+
normalizedHostWorkspace += "\\";
287+
288+
if (!normalizedClientPath.EndsWith("\\"))
289+
normalizedClientPath += "\\";
290+
291+
if (normalizedClientPath.StartsWith(normalizedHostWorkspace, StringComparison.OrdinalIgnoreCase))
292+
{
293+
294+
string relativePath = normalizedClientPath.Substring(normalizedHostWorkspace.Length);
295+
relativePath = relativePath.TrimStart('\\');
296+
297+
string normalizedRemote = remoteWorkspace.Trim().Replace('\\', '/');
298+
normalizedRemote = normalizedRemote.TrimEnd('/');
299+
300+
string result = string.IsNullOrEmpty(relativePath)
301+
? normalizedRemote
302+
: normalizedRemote + "/" + relativePath.Replace('\\', '/');
303+
304+
Console.Error.WriteLine($"Path mapped: '{clientPath}' -> '{result}'");
305+
return result;
306+
}
307+
else
308+
{
309+
Console.Error.WriteLine($"Path mapping skipped: '{clientPath}' doesn't start with '{hostWorkspace}'");
310+
}
311+
}
312+
313+
return clientPath;
272314

273315
}
274316

src/VSCode.DebugAdapter/PathHandlingStrategy.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -69,52 +69,6 @@ public string ConvertClientPathToDebugger(string clientPath)
6969
return null;
7070
}
7171

72-
string hostWorkspace = Environment.GetEnvironmentVariable("OSCRIPT_DEBUGWORKSPACE_HOST");
73-
string remoteWorkspace = Environment.GetEnvironmentVariable("OSCRIPT_DEBUGWORKSPACE_REMOTE");
74-
75-
if (!string.IsNullOrWhiteSpace(hostWorkspace) && !string.IsNullOrWhiteSpace(remoteWorkspace))
76-
{
77-
78-
string normalizedClientPath = clientPath.Replace('/', '\\').Trim();
79-
string normalizedHostWorkspace = hostWorkspace.Replace('/', '\\').Trim();
80-
81-
if (!normalizedHostWorkspace.EndsWith("\\"))
82-
normalizedHostWorkspace += "\\";
83-
84-
if (!normalizedClientPath.EndsWith("\\"))
85-
normalizedClientPath += "\\";
86-
87-
if (normalizedClientPath.StartsWith(normalizedHostWorkspace, StringComparison.OrdinalIgnoreCase))
88-
{
89-
90-
string relativePath = normalizedClientPath.Substring(normalizedHostWorkspace.Length);
91-
relativePath = relativePath.TrimStart('\\');
92-
93-
string normalizedRemote = remoteWorkspace.Trim().Replace('\\', '/');
94-
normalizedRemote = normalizedRemote.TrimEnd('/');
95-
96-
string result = string.IsNullOrEmpty(relativePath)
97-
? normalizedRemote
98-
: normalizedRemote + "/" + relativePath.Replace('\\', '/');
99-
100-
Console.Error.WriteLine($"Path mapped: '{clientPath}' -> '{result}'");
101-
return result;
102-
}
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");
116-
}
117-
11872
if (DebuggerPathsAreUri) {
11973
if (ClientPathsAreUri) {
12074
return clientPath;

src/VSCode.DebugAdapter/package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,17 @@
133133
"description": "Кодировка вывода отлаживаемого приложения. Отладчик будет интерпретировать вывод приложения в указанной кодировке",
134134
"default": ""
135135
},
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-
}
136+
"hostWorkspace": {
137+
"type": "string",
138+
"description": "Путь к каталогу проекта на локальной машине (при отладке удаленного процесса)",
139+
"default": ""
140+
},
141+
"remoteWorkspace": {
142+
"type": "string",
143+
"description": "Путь к каталогу проекта на удаленной машине (при отладке удаленного процесса)",
144+
"default": ""
148145
}
146+
149147
}
150148
}
151149
}

0 commit comments

Comments
 (0)