aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRiley Bruins <ribru17@hotmail.com>2024-11-02 19:55:35 -0700
committerChristian Clason <ch.clason+github@icloud.com>2024-11-22 08:56:14 +0100
commit2d5c122af9c3c842d74a137446dae8ff349206ac (patch)
tree750f103b5b55eae65d2671287d7947e29382496b
parentbot(lockfile): update nu, perl, robot, scala, sql, teal (diff)
downloadnvim-treesitter-2d5c122af9c3c842d74a137446dae8ff349206ac.tar
nvim-treesitter-2d5c122af9c3c842d74a137446dae8ff349206ac.tar.gz
nvim-treesitter-2d5c122af9c3c842d74a137446dae8ff349206ac.tar.bz2
nvim-treesitter-2d5c122af9c3c842d74a137446dae8ff349206ac.tar.lz
nvim-treesitter-2d5c122af9c3c842d74a137446dae8ff349206ac.tar.xz
nvim-treesitter-2d5c122af9c3c842d74a137446dae8ff349206ac.tar.zst
nvim-treesitter-2d5c122af9c3c842d74a137446dae8ff349206ac.zip
feat(http): more comprehensive highlights
-rw-r--r--queries/http/highlights.scm16
-rw-r--r--tests/query/highlights/http/test.http33
-rw-r--r--tests/query/injections/http/injections.http21
3 files changed, 68 insertions, 2 deletions
diff --git a/queries/http/highlights.scm b/queries/http/highlights.scm
index 76d62778c..1ac243729 100644
--- a/queries/http/highlights.scm
+++ b/queries/http/highlights.scm
@@ -5,9 +5,17 @@
(header
name: (_) @constant)
+(header
+ value: (_) @string)
+
; Variables
+(identifier) @variable
+
(variable_declaration
- name: (identifier) @variable)
+ "@" @character.special)
+
+(variable_declaration
+ (value) @string)
; Operators
(comment
@@ -25,7 +33,7 @@
(request
url: (_) @string.special.url)
-(http_version) @constant
+(http_version) @string.special
; Response
(status_code) @number
@@ -36,8 +44,12 @@
[
"{{"
"}}"
+ "{%"
+ "%}"
] @punctuation.bracket
+">" @punctuation.special
+
(header
":" @punctuation.delimiter)
diff --git a/tests/query/highlights/http/test.http b/tests/query/highlights/http/test.http
new file mode 100644
index 000000000..00fca50ab
--- /dev/null
+++ b/tests/query/highlights/http/test.http
@@ -0,0 +1,33 @@
+@ENDPOINT=http://localhost:8080/api
+# <- @character.special
+# ^^^^^^^ @variable
+# ^ @operator
+# ^^^^^^^^^^^^^^^^^^^^^^^^^ @string
+
+### GET USERS
+GET {{ENDPOINT}}/users HTTP/1.1
+# ^^ @punctuation.bracket
+# ^^^^^^^^ @variable
+# ^^ @punctuation.bracket
+# ^^^^^^ @string.special.url
+# ^^^^^^^^ @string.special
+
+### GET USERS by Offset
+GET {{ENDPOINT}}/users?offset=30 HTTP/1.1
+# <- @function.method
+
+### POST login
+POST {{ENDPOINT}}/auth/login HTTP/1.1
+Content-Type: application/json
+
+{
+ "username": "admin",
+ "password": "password"
+}
+
+### Log Out
+POST {{ENDPOINT}}/auth/logout HTTP/1.1
+Content-Type: application/json
+# ^^^^^^^^^^ @constant
+# ^ @punctuation.delimiter
+# vim: ft=http
diff --git a/tests/query/injections/http/injections.http b/tests/query/injections/http/injections.http
new file mode 100644
index 000000000..0f339cb6f
--- /dev/null
+++ b/tests/query/injections/http/injections.http
@@ -0,0 +1,21 @@
+### post-request script
+GET https://jsonplaceholder.typicode.com/posts/3
+
+# @lang=lua
+> {%
+local body = vim.json.decode(response.body)
+client.global.set("postId", body.id)
+-- ^ @lua
+%}
+
+
+### run request with variable
+
+GET https://jsonplaceholder.typicode.com/posts/{{postId}}
+
+> {%
+ client.global.set("auth_token", response.body.jwt);
+ // ^ @javascript
+%}
+
+### vim: ft=http