Skip to content

Commit

Permalink
fix(parser): make parse_request handle request TS nodes
Browse files Browse the repository at this point in the history
Problem:

Placing cursor between a request method and a uri and then invoking
`:Rest run` causes the node to be incorrectly parsed leading to an error.

See the following where the column above the caret (^) denotes the
cursor position:

```
GET https://google.com
   ^ cursor above caret
```

Running this will cause an error. This is because the
`parser.parse_request` method cannot handle Treesitter nodes of type
`request`.

Solution:

Make the `parser.parse_request` function handle Treesitter nodes of type
`request` by recursively calling itself on the `request` node and taking
that output when it finds a `request` node.
  • Loading branch information
PriceHiller authored and NTBBloodbath committed Mar 18, 2024
1 parent 272ce95 commit a74e940
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/rest-nvim/parser/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ function parser.parse_request(children_nodes, variables)
elseif node_type == "http_version" then
local http_version = assert(get_node_text(node, 0))
request.http_version = http_version:gsub("HTTP/", "")
elseif node_type == "request" then
request = parser.parse_request(traverse_request(node), variables)
end
end

Expand Down

0 comments on commit a74e940

Please sign in to comment.