Skip to content

separate parsing from running steps#217

Merged
teto merged 2 commits intorest-nvim:mainfrom
teto:treesitter-engine
Jul 15, 2023
Merged

separate parsing from running steps#217
teto merged 2 commits intorest-nvim:mainfrom
teto:treesitter-engine

Conversation

@teto
Copy link
Copy Markdown
Collaborator

@teto teto commented Jul 11, 2023

the treesitter backend is promising but it is too much work to reach feature parity with our current parser:
#174

what I am proposing here is a first refactoring to delay variable splicing until last minute.
It untangles parsing & running requests. Right now you need variables to exist when parsing which means you have to execute the request when parsing them else you get errors.
This PR replaces (aka "splices") the variables at the last minute so you can parse requests without executing them.
It allowed me to add a buf_list_request function in the current backend, which was not possible before, so now run_file is backend agnostic (it first lists requests and then run them).

In this PR, you can't change backend yet but in a future one, I will add a treesitter backend to parse request.
We will then be able to switch (optional) to a treesitter backend even though it's not complete (One could even imagine a hurl backend) which will make working on it easier.

@teto teto force-pushed the treesitter-engine branch 2 times, most recently from e0edb29 to 884a89a Compare July 11, 2023 23:41
@teto teto force-pushed the treesitter-engine branch 2 times, most recently from 316b902 to 7de3dcf Compare July 13, 2023 13:00
@teto teto marked this pull request as ready for review July 13, 2023 13:01
@teto teto force-pushed the treesitter-engine branch from 7de3dcf to 626ccb8 Compare July 13, 2023 15:10
return { external = true, filename_tpl = importfile }
else
lines = vim.api.nvim_buf_get_lines(bufnr, start_line - 1, stop_line, false)
lines = vim.api.nvim_buf_get_lines(bufnr, start_line, stop_line, false)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit afraid removing the -1 might create bugs down the line but it was incorrect, i.e, if you look at the main branch today the request in tests/basic_get.http

GET https://reqres.in/api/users?page=5

loads with GET https://reqres.in/api/users?page=5 as body xD

This means we could use golden (also called "snapshot") tests to make sure this is not the case. This PR helps making rest.nvim more "api-like" so I think it's a move in the good direction overall.

@teto teto force-pushed the treesitter-engine branch from 626ccb8 to e385655 Compare July 13, 2023 15:16
teto added 2 commits July 13, 2023 17:18
Right now we splice variables as we parse the request. This is annoying for several resons: variable needs to exist to create the request, so probably we need to run the previous requests before that.
@teto teto force-pushed the treesitter-engine branch from e385655 to f811cfe Compare July 13, 2023 15:19
@teto teto changed the title feat: implementing backend-agnostic run_request separate parsing from running steps Jul 13, 2023
@teto teto requested a review from NTBBloodbath July 13, 2023 15:30
@teto
Copy link
Copy Markdown
Collaborator Author

teto commented Jul 15, 2023

I noticed that we dont tests variable splicing in tests but I've done some manual testing and it looked fine. Planning to add them to tests in next PRs. I think I'll merge and if bugs are spotted, I will correct them ^^''

@teto teto merged commit ca14c8c into rest-nvim:main Jul 15, 2023
@teto teto deleted the treesitter-engine branch July 15, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant