Skip to content

Commit ce231f8

Browse files
ref: include res_handler_script in request
This simplifies the injection queries
1 parent bbcd676 commit ce231f8

File tree

7 files changed

+7219
-11198
lines changed

7 files changed

+7219
-11198
lines changed

grammar.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ module.exports = grammar({
9595
seq(
9696
// field to easily find request node in each section
9797
field("request", $.request),
98-
repeat(
99-
choice(
100-
seq(alias($.var_comment, $.comment), repeat(NL)),
101-
seq($.res_handler_script, repeat(NL)),
102-
),
103-
),
10498
),
10599
),
106100

@@ -148,18 +142,21 @@ module.exports = grammar({
148142
optional(
149143
seq(
150144
repeat1($._blank_line),
151-
// repeat($.comment),
152-
repeat(alias($.var_comment, $.comment)),
153-
optional(
154-
field("body", choice(
155-
$.raw_body,
156-
$.multipart_form_data,
157-
$.xml_body,
158-
$.json_body,
159-
$.graphql_body,
160-
$._external_body,
161-
)),
162-
),
145+
prec.right(repeat(
146+
choice(
147+
alias($.var_comment, $.comment),
148+
field("body", choice(
149+
$.raw_body,
150+
$.multipart_form_data,
151+
$.xml_body,
152+
$.json_body,
153+
$.graphql_body,
154+
$._external_body,
155+
)),
156+
NL,
157+
$.res_handler_script,
158+
),
159+
)),
163160
),
164161
),
165162
)),
@@ -201,9 +198,9 @@ module.exports = grammar({
201198
token(prec(1, "}}")),
202199
),
203200

204-
pre_request_script: ($) => seq("<", WS, choice($.script, $.path), NL),
201+
pre_request_script: ($) => seq("<", WS, choice($.script, $.path), token(repeat1(NL))),
205202
res_handler_script: ($) =>
206-
seq(token(prec(3, ">")), WS, choice($.script, $.path), NL),
203+
seq(token(prec(3, ">")), WS, choice($.script, $.path), token(repeat1(NL))),
207204
script: (_) =>
208205
seq(
209206
token(prec(1, "{%")),
@@ -226,22 +223,22 @@ module.exports = grammar({
226223
xml_body: (_) =>
227224
seq(
228225
token(prec(2, /<[^\s@]/)),
229-
repeat1(LINE_TAIL),
226+
repeat1(token(prec(2, LINE_TAIL))),
230227
),
231228

232229
json_body: (_) =>
233230
seq(
234231
token(prec(2, /[{\[]\s+/)),
235-
repeat1(LINE_TAIL),
232+
repeat1(token(prec(2, LINE_TAIL))),
236233
),
237234

238-
graphql_body: ($) => seq($.graphql_data, optional($.json_body)),
235+
graphql_body: ($) => prec.right(seq($.graphql_data, optional($.json_body))),
239236
graphql_data: (_) =>
240237
seq(
241238
token(
242239
prec(2, seq(choice("query", "mutation"), WS, /.*\{/, NL)),
243240
),
244-
repeat1(LINE_TAIL),
241+
repeat1(token(prec(2, LINE_TAIL))),
245242
),
246243

247244
_external_body: ($) =>
@@ -260,13 +257,17 @@ module.exports = grammar({
260257
multipart_form_data: ($) =>
261258
prec.right(seq(
262259
token(prec(2, "--")),
263-
LINE_TAIL,
260+
token(prec(1, LINE_TAIL)),
264261
repeat(
265262
choice(
266-
$._blank_line,
263+
// $._blank_line,
267264
$.comment,
268265
seq($.external_body, choice(WS, NL)),
266+
token(prec(2, /<[^\s@]/)),
267+
token(prec(2, "--")),
268+
token(prec(2, /[{\[]\s+/)),
269269
token(prec(1, LINE_TAIL)),
270+
token(prec(2, NL)),
270271
),
271272
),
272273
)),
@@ -276,7 +277,6 @@ module.exports = grammar({
276277
seq(
277278
choice(
278279
token(prec(1, LINE_TAIL)),
279-
// seq($.external_body, NL),
280280
seq($._comment_prefix, $._not_comment),
281281
),
282282
optional($._raw_body),

queries/injections.scm

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,13 @@
1313
(#set! injection.language "graphql"))
1414

1515
; Script (default to javascript)
16-
((script) @injection.content
17-
(#offset! @injection.content 0 2 0 -2)
18-
(#set! injection.language "javascript"))
19-
20-
; Script with other languages
21-
((comment
22-
name: (_) @_name
23-
(#eq? @_name "lang")
24-
value: (_) @injection.language)
25-
.
26-
(_
27-
(script) @injection.content
28-
(#offset! @injection.content 0 2 0 -2)))
29-
30-
; post-request scripts for requests without body
31-
((request
32-
!body
16+
((#set! injection.language "javascript")
3317
(comment
3418
name: (_) @_name
3519
(#eq? @_name "lang")
36-
value: (_) @injection.language) .)
20+
value: (_) @injection.language
21+
)?
3722
.
38-
(res_handler_script
23+
(_
3924
(script) @injection.content
4025
(#offset! @injection.content 0 2 0 -2)))

0 commit comments

Comments
 (0)