@ian-pascoe/pi-dap 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/package.json +57 -0
- package/src/dap-observer-ui.ts +337 -0
- package/src/dap-protocol-client.ts +1103 -0
- package/src/dap-session-files.ts +110 -0
- package/src/dap-session.ts +1231 -0
- package/src/dap-tool-contract.ts +263 -0
- package/src/dap-tool-rendering.ts +512 -0
- package/src/dap-tool.ts +420 -0
- package/src/index.ts +1 -0
- package/src/pi-dap-extension.ts +110 -0
- package/src/pi-dap-settings.ts +406 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
|
|
3
|
+
const NonEmptyStringSchema = Type.String({ minLength: 1 });
|
|
4
|
+
const DapIdSchema = Type.Integer({ minimum: 0 });
|
|
5
|
+
const DapPresentationStringSchema = Type.String({ maxLength: 500 });
|
|
6
|
+
const EmptyOperationSchema = <TOperation extends string>(operation: TOperation) =>
|
|
7
|
+
Type.Object({ operation: Type.Literal(operation) }, { additionalProperties: false });
|
|
8
|
+
|
|
9
|
+
const LaunchParametersSchema = Type.Object(
|
|
10
|
+
{
|
|
11
|
+
operation: Type.Literal("launch"),
|
|
12
|
+
profile: Type.Optional(NonEmptyStringSchema),
|
|
13
|
+
program: Type.Optional(NonEmptyStringSchema),
|
|
14
|
+
args: Type.Optional(Type.Array(Type.String())),
|
|
15
|
+
cwd: Type.Optional(NonEmptyStringSchema),
|
|
16
|
+
},
|
|
17
|
+
{ additionalProperties: false },
|
|
18
|
+
);
|
|
19
|
+
const SetBreakpointsParametersSchema = Type.Object(
|
|
20
|
+
{
|
|
21
|
+
operation: Type.Literal("set_breakpoints"),
|
|
22
|
+
file_path: NonEmptyStringSchema,
|
|
23
|
+
breakpoints: Type.Array(
|
|
24
|
+
Type.Object(
|
|
25
|
+
{ line: Type.Integer({ minimum: 1 }), condition: Type.Optional(Type.String()) },
|
|
26
|
+
{ additionalProperties: false },
|
|
27
|
+
),
|
|
28
|
+
),
|
|
29
|
+
},
|
|
30
|
+
{ additionalProperties: false },
|
|
31
|
+
);
|
|
32
|
+
const StackParametersSchema = Type.Object(
|
|
33
|
+
{
|
|
34
|
+
operation: Type.Literal("stack"),
|
|
35
|
+
thread_id: Type.Optional(DapIdSchema),
|
|
36
|
+
start: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
37
|
+
count: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
38
|
+
},
|
|
39
|
+
{ additionalProperties: false },
|
|
40
|
+
);
|
|
41
|
+
const VariablesPageSchema = {
|
|
42
|
+
start: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
43
|
+
count: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
44
|
+
};
|
|
45
|
+
const VariablesParametersSchema = Type.Union([
|
|
46
|
+
Type.Object(
|
|
47
|
+
{ operation: Type.Literal("variables"), frame_id: DapIdSchema, ...VariablesPageSchema },
|
|
48
|
+
{ additionalProperties: false },
|
|
49
|
+
),
|
|
50
|
+
Type.Object(
|
|
51
|
+
{
|
|
52
|
+
operation: Type.Literal("variables"),
|
|
53
|
+
variables_reference: DapIdSchema,
|
|
54
|
+
...VariablesPageSchema,
|
|
55
|
+
},
|
|
56
|
+
{ additionalProperties: false },
|
|
57
|
+
),
|
|
58
|
+
]);
|
|
59
|
+
const EvaluateParametersSchema = Type.Object(
|
|
60
|
+
{
|
|
61
|
+
operation: Type.Literal("evaluate"),
|
|
62
|
+
expression: NonEmptyStringSchema,
|
|
63
|
+
frame_id: Type.Optional(DapIdSchema),
|
|
64
|
+
},
|
|
65
|
+
{ additionalProperties: false },
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
/** Strict model-facing contract for the package's twelve DAP operations. */
|
|
69
|
+
export const DapToolParametersSchema = Type.Union([
|
|
70
|
+
LaunchParametersSchema,
|
|
71
|
+
SetBreakpointsParametersSchema,
|
|
72
|
+
EmptyOperationSchema("continue"),
|
|
73
|
+
EmptyOperationSchema("next"),
|
|
74
|
+
EmptyOperationSchema("step_in"),
|
|
75
|
+
EmptyOperationSchema("step_out"),
|
|
76
|
+
EmptyOperationSchema("pause"),
|
|
77
|
+
StackParametersSchema,
|
|
78
|
+
VariablesParametersSchema,
|
|
79
|
+
EvaluateParametersSchema,
|
|
80
|
+
EmptyOperationSchema("status"),
|
|
81
|
+
EmptyOperationSchema("stop"),
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
/** Parsed input for one invocation of the strict `dap` tool. */
|
|
85
|
+
export type DapToolParameters = Static<typeof DapToolParametersSchema>;
|
|
86
|
+
|
|
87
|
+
const DapStateSchema = Type.Union([
|
|
88
|
+
Type.Literal("idle"),
|
|
89
|
+
Type.Literal("launching"),
|
|
90
|
+
Type.Literal("running"),
|
|
91
|
+
Type.Literal("stopped"),
|
|
92
|
+
Type.Literal("terminated"),
|
|
93
|
+
]);
|
|
94
|
+
const DapOperationSchema = Type.Union([
|
|
95
|
+
Type.Literal("launch"),
|
|
96
|
+
Type.Literal("set_breakpoints"),
|
|
97
|
+
Type.Literal("continue"),
|
|
98
|
+
Type.Literal("next"),
|
|
99
|
+
Type.Literal("step_in"),
|
|
100
|
+
Type.Literal("step_out"),
|
|
101
|
+
Type.Literal("pause"),
|
|
102
|
+
Type.Literal("stack"),
|
|
103
|
+
Type.Literal("variables"),
|
|
104
|
+
Type.Literal("evaluate"),
|
|
105
|
+
Type.Literal("status"),
|
|
106
|
+
Type.Literal("stop"),
|
|
107
|
+
]);
|
|
108
|
+
const DapSourceFields = {
|
|
109
|
+
source_name: Type.Optional(DapPresentationStringSchema),
|
|
110
|
+
source_path: Type.Optional(DapPresentationStringSchema),
|
|
111
|
+
};
|
|
112
|
+
const BreakpointsPresentationSchema = Type.Object(
|
|
113
|
+
{
|
|
114
|
+
kind: Type.Literal("breakpoints"),
|
|
115
|
+
rows: Type.Array(
|
|
116
|
+
Type.Object(
|
|
117
|
+
{
|
|
118
|
+
id: Type.Optional(DapIdSchema),
|
|
119
|
+
verified: Type.Boolean(),
|
|
120
|
+
message: Type.Optional(DapPresentationStringSchema),
|
|
121
|
+
line: Type.Optional(Type.Integer()),
|
|
122
|
+
...DapSourceFields,
|
|
123
|
+
},
|
|
124
|
+
{ additionalProperties: false },
|
|
125
|
+
),
|
|
126
|
+
{ maxItems: 20 },
|
|
127
|
+
),
|
|
128
|
+
omitted_count: Type.Integer({ minimum: 0 }),
|
|
129
|
+
},
|
|
130
|
+
{ additionalProperties: false },
|
|
131
|
+
);
|
|
132
|
+
const StackPresentationSchema = Type.Object(
|
|
133
|
+
{
|
|
134
|
+
kind: Type.Literal("stack_frames"),
|
|
135
|
+
rows: Type.Array(
|
|
136
|
+
Type.Object(
|
|
137
|
+
{
|
|
138
|
+
id: DapIdSchema,
|
|
139
|
+
name: DapPresentationStringSchema,
|
|
140
|
+
line: Type.Integer(),
|
|
141
|
+
column: Type.Integer(),
|
|
142
|
+
...DapSourceFields,
|
|
143
|
+
},
|
|
144
|
+
{ additionalProperties: false },
|
|
145
|
+
),
|
|
146
|
+
{ maxItems: 20 },
|
|
147
|
+
),
|
|
148
|
+
total_count: Type.Integer({ minimum: 0 }),
|
|
149
|
+
omitted_count: Type.Integer({ minimum: 0 }),
|
|
150
|
+
},
|
|
151
|
+
{ additionalProperties: false },
|
|
152
|
+
);
|
|
153
|
+
const VariableRowSchema = Type.Union([
|
|
154
|
+
Type.Object(
|
|
155
|
+
{
|
|
156
|
+
kind: Type.Literal("group"),
|
|
157
|
+
name: DapPresentationStringSchema,
|
|
158
|
+
variables_reference: DapIdSchema,
|
|
159
|
+
expensive: Type.Boolean(),
|
|
160
|
+
},
|
|
161
|
+
{ additionalProperties: false },
|
|
162
|
+
),
|
|
163
|
+
Type.Object(
|
|
164
|
+
{
|
|
165
|
+
kind: Type.Literal("variable"),
|
|
166
|
+
group: Type.Optional(DapPresentationStringSchema),
|
|
167
|
+
name: DapPresentationStringSchema,
|
|
168
|
+
value: DapPresentationStringSchema,
|
|
169
|
+
type: Type.Optional(DapPresentationStringSchema),
|
|
170
|
+
variables_reference: DapIdSchema,
|
|
171
|
+
},
|
|
172
|
+
{ additionalProperties: false },
|
|
173
|
+
),
|
|
174
|
+
]);
|
|
175
|
+
const VariablesPresentationSchema = Type.Object(
|
|
176
|
+
{
|
|
177
|
+
kind: Type.Literal("variables"),
|
|
178
|
+
rows: Type.Array(VariableRowSchema, { maxItems: 20 }),
|
|
179
|
+
omitted_count: Type.Integer({ minimum: 0 }),
|
|
180
|
+
},
|
|
181
|
+
{ additionalProperties: false },
|
|
182
|
+
);
|
|
183
|
+
const EvaluationPresentationSchema = Type.Object(
|
|
184
|
+
{
|
|
185
|
+
kind: Type.Literal("evaluation"),
|
|
186
|
+
value: DapPresentationStringSchema,
|
|
187
|
+
type: Type.Optional(DapPresentationStringSchema),
|
|
188
|
+
variables_reference: DapIdSchema,
|
|
189
|
+
},
|
|
190
|
+
{ additionalProperties: false },
|
|
191
|
+
);
|
|
192
|
+
const DapExecutionWaitOperationSchema = Type.Union([
|
|
193
|
+
Type.Literal("launch"),
|
|
194
|
+
Type.Literal("continue"),
|
|
195
|
+
Type.Literal("next"),
|
|
196
|
+
Type.Literal("step_in"),
|
|
197
|
+
Type.Literal("step_out"),
|
|
198
|
+
]);
|
|
199
|
+
const ExecutionWaitPresentationSchema = Type.Object(
|
|
200
|
+
{
|
|
201
|
+
kind: Type.Literal("execution_wait"),
|
|
202
|
+
operation: DapExecutionWaitOperationSchema,
|
|
203
|
+
cancelled: Type.Literal(true),
|
|
204
|
+
},
|
|
205
|
+
{ additionalProperties: false },
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
/** Bounded operation-specific data used only by the Observer UI. */
|
|
209
|
+
export const DapPresentationDetailsSchema = Type.Union([
|
|
210
|
+
BreakpointsPresentationSchema,
|
|
211
|
+
StackPresentationSchema,
|
|
212
|
+
VariablesPresentationSchema,
|
|
213
|
+
EvaluationPresentationSchema,
|
|
214
|
+
ExecutionWaitPresentationSchema,
|
|
215
|
+
]);
|
|
216
|
+
|
|
217
|
+
/** Bounded operation-specific data used only by the Observer UI. */
|
|
218
|
+
export type DapPresentationDetails = Static<typeof DapPresentationDetailsSchema>;
|
|
219
|
+
|
|
220
|
+
/** Structured, runtime-validated details returned with every successful DAP operation. */
|
|
221
|
+
export const DapToolResultDetailsSchema = Type.Object(
|
|
222
|
+
{
|
|
223
|
+
operation: DapOperationSchema,
|
|
224
|
+
state: DapStateSchema,
|
|
225
|
+
adapter_id: Type.Optional(NonEmptyStringSchema),
|
|
226
|
+
profile_id: Type.Optional(NonEmptyStringSchema),
|
|
227
|
+
stop_reason: Type.Optional(Type.String()),
|
|
228
|
+
thread_id: Type.Optional(DapIdSchema),
|
|
229
|
+
stack_frame_ids: Type.Optional(Type.Array(DapIdSchema)),
|
|
230
|
+
exit_code: Type.Optional(Type.Integer()),
|
|
231
|
+
termination_reason: Type.Optional(Type.String()),
|
|
232
|
+
output_discarded_bytes: Type.Integer({ minimum: 0 }),
|
|
233
|
+
output_truncated: Type.Boolean(),
|
|
234
|
+
spill_path: Type.Optional(NonEmptyStringSchema),
|
|
235
|
+
presentation: Type.Optional(DapPresentationDetailsSchema),
|
|
236
|
+
},
|
|
237
|
+
{ additionalProperties: false },
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
/** Validated metadata accompanying one successful DAP tool result. */
|
|
241
|
+
export type DapToolResultDetails = Static<typeof DapToolResultDetailsSchema>;
|
|
242
|
+
|
|
243
|
+
/** One bounded elapsed-time update shown while an execution operation waits. */
|
|
244
|
+
export const DapToolProgressDetailsSchema = Type.Object(
|
|
245
|
+
{
|
|
246
|
+
kind: Type.Literal("progress"),
|
|
247
|
+
operation: DapExecutionWaitOperationSchema,
|
|
248
|
+
elapsed_ms: Type.Integer({ minimum: 0 }),
|
|
249
|
+
},
|
|
250
|
+
{ additionalProperties: false },
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
/** One bounded elapsed-time update shown while an execution operation waits. */
|
|
254
|
+
export type DapToolProgressDetails = Static<typeof DapToolProgressDetailsSchema>;
|
|
255
|
+
|
|
256
|
+
/** Final or partial details accepted by the DAP transcript renderer. */
|
|
257
|
+
export const DapToolRenderDetailsSchema = Type.Union([
|
|
258
|
+
DapToolResultDetailsSchema,
|
|
259
|
+
DapToolProgressDetailsSchema,
|
|
260
|
+
]);
|
|
261
|
+
|
|
262
|
+
/** Final or partial details accepted by the DAP transcript renderer. */
|
|
263
|
+
export type DapToolRenderDetails = Static<typeof DapToolRenderDetailsSchema>;
|