Skip to content

Commit

Permalink
feat(http): more comprehensive highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 authored and clason committed Nov 22, 2024
1 parent eff88f4 commit 2d5c122
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
16 changes: 14 additions & 2 deletions queries/http/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +33,7 @@
(request
url: (_) @string.special.url)

(http_version) @constant
(http_version) @string.special

; Response
(status_code) @number
Expand All @@ -36,8 +44,12 @@
[
"{{"
"}}"
"{%"
"%}"
] @punctuation.bracket

">" @punctuation.special

(header
":" @punctuation.delimiter)

Expand Down
33 changes: 33 additions & 0 deletions tests/query/highlights/http/test.http
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions tests/query/injections/http/injections.http
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d5c122

Please sign in to comment.