tree-sitter-http icon indicating copy to clipboard operation
tree-sitter-http copied to clipboard

`application/json;v=2` or similar setups in the Accept header are not accepted by parser

Open daneorie opened this issue 1 year ago • 7 comments

When attempting to run the below request...

GET https://reqres.in/api/users?page=5
Accept: application/json;v=2

...I get the following error:

[rest.nvim] ERROR: The tree-sitter node at the range [0:0 - 1:28] has a syntax error and cannot be parsed
Error executing Lua callback: .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:143: attempt to index local 'document_node' (a nil value)
stack traceback:
        .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:143: in function 'traverse_variables'
        .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:436: in function 'parse'
        ...al/share/nvim/lazy/rest.nvim/lua/rest-nvim/functions.lua:61: in function 'exec'
        ...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:44: in function 'impl'
        ...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:182: in function <...cal/share/nvim/lazy/rest.nvim/lua/rest-nvim/commands.lua:165>

Note: the example request wouldn't give a different response from Accept: application/json, but this is just an example of a setup that I would expect to work and works for normal cURL requests.

Is this something that could be easy to fix? I'd be glad to fix it, but I don't understand enough about the parser to know where to look.

daneorie avatar May 16 '24 20:05 daneorie

Transferred this issue to the tree-sitter-http parser repository.

This may be because we are only including alphanumeric values for a header value, see grammar.js:156-164

NTBBloodbath avatar May 16 '24 20:05 NTBBloodbath

Excuse my ignorance, but I'm having difficultly understanding how exactly this repo ties into rest.nvim. I understand at a high level that this is defining the parsing mechanics for http files with tree sitter, but I'm not understanding how/where that's actually getting linked into rest.nvim. I see that the Makefile creates parser/http.so, and I understand that tree sitter uses these files in the same relative directory (parser/), but I'm not able to figure out the next step where the created http.so file is used by tree-sitter for rest.nvim.

I'm essentially struggling to figure out how to test this locally, because I'm not understanding how to link all of this together. Any direction would be greatly appreciated!

daneorie avatar May 22 '24 00:05 daneorie

Nevermind, I think I understand it now. Let me see what I can figure out from here.

daneorie avatar May 22 '24 00:05 daneorie

Transferred this issue to the tree-sitter-http parser repository.

This may be because we are only including alphanumeric values for a header value, see grammar.js:156-164

Hi, @NTBBloodbath Thanks for your reply. But I'm confused why the HTTP header value must be alphanumeric. It is common to have other symbols like "=" in cookies. In the current situation, I can't add cookies for my request using rest.nvim.

skyf0cker avatar Jun 05 '24 06:06 skyf0cker

FYI, i usually add cookies in http request like the following screenshot image

skyf0cker avatar Jun 05 '24 06:06 skyf0cker

@skyf0cker, I’m sure it was just implemented in the simplest way. I don’t think it was limited for any reason outside of simplicity.

I’ve tried looking into updating the grammar to allow for more characters, but I haven’t been successful in implementation quite yet, and I haven’t been able to put much time into it given a new baby.

Are you at all familiar with updating and building tree-sitter grammars? Maybe you could help.

daneorie avatar Jun 05 '24 12:06 daneorie

I don't have much experience about treesitter grammer, but i will look into it and have a try in my spare time. If there are any progress, i will post here 😃

skyf0cker avatar Jun 05 '24 12:06 skyf0cker