Skip to content

Commit c6710c9

Browse files
committed
Вызов получения переменных модуля в зависимости от версии протокола
1 parent 16e326b commit c6710c9

10 files changed

Lines changed: 78 additions & 20 deletions

File tree

src/OneScript.DebugProtocol/IDebuggerService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ public interface IDebuggerService
5252
/// <param name="path"></param>
5353
/// <returns></returns>
5454
Variable[] GetVariables(int threadId, int frameIndex, int[] path);
55+
56+
/// <summary>
57+
/// Получает переменные модуля для указанного фрейма
58+
/// </summary>
59+
/// <param name="threadId"></param>
60+
/// <param name="frameIndex"></param>
61+
/// <param name="path"></param>
62+
/// <returns></returns>
63+
Variable[] GetModuleVariables(int threadId, int frameIndex, int[] path);
5564

5665
/// <summary>
5766
/// Получает значения переменных вычисленного выражения

src/OneScript.DebugServices/DefaultDebugger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DefaultDebugger : IDebugger
2020
// NB! должен быть согласован с перечислением TransportProtocols в адаптере
2121
private const short JSON_FORMAT_MARKER = 2;
2222
// NB! должен быть согласован с файлом ProtocolVersions в адаптере
23-
private const short SUPPORTED_FORMAT_VERSION = 3;
23+
private const short SUPPORTED_FORMAT_VERSION = 4;
2424

2525
private readonly IDebugServer _transport;
2626
private IDebugSession _session;

src/OneScript.DebugServices/Internal/DebuggerServiceImpl.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ public Variable[] GetVariables(int threadId, int frameIndex, int[] path)
138138

139139
return GetDebugVariables(locals);
140140
}
141+
142+
public Variable[] GetModuleVariables(int threadId, int frameIndex, int[] path)
143+
{
144+
var machine = GetMachine(threadId);
145+
146+
var moduleVars = machine.GetModuleVariables(frameIndex);
147+
148+
foreach (var step in path)
149+
{
150+
var variable = moduleVars[step];
151+
moduleVars = GetChildVariables(variable);
152+
}
153+
154+
return GetDebugVariables(moduleVars);
155+
}
141156

142157
public Variable[] GetEvaluatedVariables(string expression, int threadId, int frameIndex, int[] path)
143158
{

src/VSCode.DebugAdapter/OneScriptDebuggerClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ public Variable[] GetVariables(int threadId, int frameIndex, int[] path)
132132

133133
return GetResponse<Variable[]>();
134134
}
135+
136+
public Variable[] GetModuleVariables(int threadId, int frameIndex, int[] path)
137+
{
138+
WriteCommand(new object[]
139+
{
140+
threadId,
141+
frameIndex,
142+
path
143+
});
144+
145+
return GetResponse<Variable[]>();
146+
}
135147

136148
public Variable[] GetEvaluatedVariables(string expression, int threadId, int frameIndex, int[] path)
137149
{

src/VSCode.DebugAdapter/OscriptDebugSession.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,13 @@ public override void Scopes(Response response, dynamic arguments)
379379
var localHandle = _threadState.RegisterVariablesProvider(localProvider);
380380
scopes.Add(new Scope("Локальные переменные", localHandle));
381381

382-
// Scope 2: Переменные модуля (для будущего расширения)
383-
// Раскомментировать когда будет готов протокол:
384-
// var moduleProvider = new ModuleScopeProvider(frame.ThreadId, frame.Index);
385-
// var moduleHandle = _threadState.RegisterVariablesProvider(moduleProvider);
386-
// scopes.Add(new Scope("Переменные модуля", moduleHandle));
382+
// Scope 2: Переменные модуля (начиная с протокола версии 4)
383+
if (_debuggee.ProtocolVersion >= ProtocolVersions.Version4)
384+
{
385+
var moduleProvider = new ModuleScopeProvider(frame.ThreadId, frame.Index);
386+
var moduleHandle = _threadState.RegisterVariablesProvider(moduleProvider);
387+
scopes.Add(new Scope("Переменные модуля", moduleHandle));
388+
}
387389

388390
SendResponse(response, new ScopesResponseBody(scopes.ToArray()));
389391
}

src/VSCode.DebugAdapter/Transport/ProtocolVersions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public static int Adjust(int valueToAdjust)
4141
/// Выделенный тип для параметра в SetExceptionBreakpoints
4242
/// </summary>
4343
public const int Version3 = 3;
44+
45+
/// <summary>
46+
/// Переменные модуля
47+
/// </summary>
48+
public const int Version4 = 4;
4449

4550
/// <summary>
4651
/// Значение, безопасное для всех версий движка
@@ -50,6 +55,6 @@ public static int Adjust(int valueToAdjust)
5055
/// <summary>
5156
/// Контрольное значение
5257
/// </summary>
53-
public const int LatestKnownVersion = Version3;
58+
public const int LatestKnownVersion = Version4;
5459
}
5560
}

src/VSCode.DebugAdapter/Variables/ChildVariablesProvider.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,38 @@ This Source Code Form is subject to the terms of the
1111
namespace VSCode.DebugAdapter
1212
{
1313
/// <summary>
14-
/// Провайдер вложенных переменных объекта
14+
/// Универсальный провайдер вложенных переменных
1515
/// </summary>
1616
public class ChildVariablesProvider : IVariablesProvider
1717
{
1818
private readonly int _threadId;
1919
private readonly int _frameIndex;
2020
private readonly int[] _path;
21+
private readonly Func<IDebuggerService, int, int, int[], Variable[]> _fetchFunc;
2122

22-
public ChildVariablesProvider(int threadId, int frameIndex, int[] path)
23+
public ChildVariablesProvider(
24+
int threadId,
25+
int frameIndex,
26+
int[] path,
27+
Func<IDebuggerService, int, int, int[], Variable[]> fetchFunc)
2328
{
2429
_threadId = threadId;
2530
_frameIndex = frameIndex;
2631
_path = path;
32+
_fetchFunc = fetchFunc;
2733
}
2834

2935
public Variable[] FetchVariables(IDebuggerService service)
3036
{
31-
return service.GetVariables(_threadId, _frameIndex, _path);
37+
return _fetchFunc(service, _threadId, _frameIndex, _path);
3238
}
3339

3440
public IVariablesProvider CreateChildProvider(int variableIndex)
3541
{
3642
var newPath = new int[_path.Length + 1];
3743
Array.Copy(_path, newPath, _path.Length);
3844
newPath[_path.Length] = variableIndex;
39-
return new ChildVariablesProvider(_threadId, _frameIndex, newPath);
45+
return new ChildVariablesProvider(_threadId, _frameIndex, newPath, _fetchFunc);
4046
}
4147
}
4248
}

src/VSCode.DebugAdapter/Variables/EvaluatedExpressionProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public IVariablesProvider CreateChildProvider(int variableIndex)
4646
var newPath = new int[_path.Length + 1];
4747
Array.Copy(_path, newPath, _path.Length);
4848
newPath[_path.Length] = variableIndex;
49-
return new EvaluatedExpressionProvider(_expression, _threadId, _frameIndex, newPath);
49+
return new ChildVariablesProvider(
50+
_threadId,
51+
_frameIndex,
52+
newPath,
53+
(service, tid, fid, path) => service.GetEvaluatedVariables(_expression, tid, fid, path));
5054
}
5155
}
5256
}

src/VSCode.DebugAdapter/Variables/LocalScopeProvider.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ public Variable[] FetchVariables(IDebuggerService service)
3232

3333
public IVariablesProvider CreateChildProvider(int variableIndex)
3434
{
35-
return new ChildVariablesProvider(_threadId, _frameIndex, new[] { variableIndex });
35+
return new ChildVariablesProvider(
36+
_threadId,
37+
_frameIndex,
38+
new[] { variableIndex },
39+
(service, tid, fid, path) => service.GetVariables(tid, fid, path));
3640
}
3741
}
3842
}

src/VSCode.DebugAdapter/Variables/ModuleScopeProvider.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ This Source Code Form is subject to the terms of the
1111
namespace VSCode.DebugAdapter
1212
{
1313
/// <summary>
14-
/// Провайдер переменных модуля (для будущего расширения)
15-
/// Требует расширения протокола отладки для получения переменных модуля
14+
/// Провайдер переменных модуля
1615
/// </summary>
1716
public class ModuleScopeProvider : IVariablesProvider
1817
{
1918
private readonly int _threadId;
2019
private readonly int _frameIndex;
21-
// В будущем может потребоваться moduleId или другой идентификатор
2220

2321
public ModuleScopeProvider(int threadId, int frameIndex)
2422
{
@@ -28,14 +26,17 @@ public ModuleScopeProvider(int threadId, int frameIndex)
2826

2927
public Variable[] FetchVariables(IDebuggerService service)
3028
{
31-
// TODO: когда будет расширен протокол - заменить на GetModuleVariables или подобное
32-
// Пока возвращаем пустой массив
33-
throw new NotImplementedException("Module scope requires protocol extension");
29+
// path пустой - получаем переменные модуля верхнего уровня фрейма
30+
return service.GetModuleVariables(_threadId, _frameIndex, Array.Empty<int>());
3431
}
3532

3633
public IVariablesProvider CreateChildProvider(int variableIndex)
3734
{
38-
throw new NotImplementedException("Module scope requires protocol extension");
35+
return new ChildVariablesProvider(
36+
_threadId,
37+
_frameIndex,
38+
new[] { variableIndex },
39+
(service, tid, fid, path) => service.GetModuleVariables(tid, fid, path));
3940
}
4041
}
4142
}

0 commit comments

Comments
 (0)