rest.nvim icon indicating copy to clipboard operation
rest.nvim copied to clipboard

Error when `Rest run` apparently with Treesitter http

Open toniher opened this issue 1 year ago • 12 comments

I'm testing a basic GET with Rest run:

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

and I'm getting this error:

Error executing Lua callback: ...-linux64/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 10 for language http
stack traceback:
	[C]: in function '_ts_parse_query'
	...-linux64/share/nvim/runtime/lua/vim/treesitter/query.lua:259: in function 'parse'
	.../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:166: in function 'parse_variables'
	.../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:232: in function 'parse_request'
	.../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:438: 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>

Treesitter HTTP is installed and highlighting correctly. I get this error once I run the command and don't receive any output.

Do you have any idea where to look?

I'm using the last rest-nvim and treesitter http version with Neovim 0.9.5 and nvim-treesitter 0.9.2

toniher avatar Apr 18 '24 16:04 toniher

Do you have any requests before GET https://reqres.in/api/users?page=5 in your .http?

daniilrozanov avatar Apr 20 '24 10:04 daniilrozanov

Do you have any requests before GET https://reqres.in/api/users?page=5 in your .http?

No. I'm using this simple file: https://github.com/rest-nvim/rest.nvim/blob/main/tests/reqs/basic_get.http but it's failing the same with all the others...

toniher avatar Apr 20 '24 14:04 toniher

Then I have no idea why the error occurs( I've copied your request and it works fine within my neovim. Maybe you should update your plugin and http treesitter

daniilrozanov avatar Apr 21 '24 11:04 daniilrozanov

I might have a similar issue. The request previously worked fine but now produces an error

Request

@y = 2024
@m = 09
@d = 04

@n = 5055
@t = 9000

POST https://jira.beauit.com/rest/api/2/issue/GENGY-{{n}}/worklog
Authorization: Basic _hidden_
Content-Type: application/json

{
    "timeSpentSeconds": "{{t}}",
    "started": "{{y}}-{{m}}-{{d}}T12:00:00.000+0000",
    "comment": ""
}

errors

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>
[rest.nvim] ERROR: The tree-sitter node at the range [7:0 - 16:0] has a syntax error and cannot be parsed

Emptyfruit avatar Apr 22 '24 08:04 Emptyfruit

Hi, are you running the request with your cursor over the request? It seems like you're trying to run it from line 7, which is empty and doesn't belong to the request on itself.

Edit: please check :InspectTree and use it to know which lines belong to your request node.

NTBBloodbath avatar Apr 22 '24 14:04 NTBBloodbath

Hi. Yes, i am running the request from line 8 where the POST ... is. The code i provided is the full contents of the .http file. I also tried lines 9, 10. Accorind to InstpectTree, the request is (request) ; [8:1 - 17:0].

Btw, if i try to run request from lines 1-3 (or any line before first empty line) the full request gets highlighted correctly, but still gives an error.

Emptyfruit avatar Apr 22 '24 17:04 Emptyfruit

So I personally have always found Treesitter to be very finicky when it comes to installs. I was having the same issue.

I have two computers I use nvim on and both had the same issue.

  1. For one of them, I fixed it when :TSUpdate ran while updating my packages from Lazy
  2. For the other one, I had to :TSUninstall all first, and then did TSUpdate. I updated all my dependencies before this as well, I'd guess mainly rest.nvim, luarocks, and probably Treesitter are the only ones that you'd need to make sure are up to date as possible.

jonathan-elize avatar Apr 27 '24 18:04 jonathan-elize

Reinstalling treesitter grammars did not help. As for debugging, the issue in my case is in the parameters. Inlining values fixes the request, but, of course, lacks the functionality.

this version works

POST https://jira.beauit.com/rest/api/2/issue/GENGY-5109/worklog
Authorization: Basic hidden
Content-Type: application/json

{
    "timeSpentSeconds": "1800",
    "started": "2024-04-22T12:00:00.000+0000",
    "comment": ""
}

Emptyfruit avatar May 02 '24 08:05 Emptyfruit

For the sake of information, it is still not working for me, and I cannot make it work with the last case either... I am testing it on Ubuntu 22.04, in case it can be helpful.

toniher avatar May 02 '24 11:05 toniher

Using Neovim 0.10.0, I still cannot manage to run it, but the error is slightly different:

Error executing Lua callback: ...m-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 1:11. Impossible pattern:
(variable name: (_) @name)
          ^

stack traceback:
	[C]: in function '_ts_parse_query'
	...m-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
	...nvim-0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'parse'
	.../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:166: in function 'parse_variables'
	.../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:232: in function 'parse_request'
	.../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>

toniher avatar May 24 '24 15:05 toniher

I'm having the same issue as @toniher I can't get any requests to work :(

Also on nvim 0.10

elshize avatar Jun 13 '24 16:06 elshize

I also get the same error as @toniher.

I've been trying it off and on to see if I can get it working but nothing seems to resolve the issues. I am on nvim 0.10. All parsers up to date. All plugins up to date. On Mac.

Here's mine:

Error executing Lua callback: ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 1:11. Impossible pattern:
(variable name: (_) @name)
          ^

stack traceback:
        [C]: in function '_ts_parse_query'
        ...m/0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
        ...ovim/0.10.0/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'parse'
        .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:166: in function 'parse_variables'
        .../share/nvim/lazy/rest.nvim/lua/rest-nvim/parser/init.lua:232: in function 'parse_request'
        .../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>
Screenshot 2024-06-13 at 3 27 48 PM

[!NOTE] When running: :echo nvim_get_runtime_file('parser', v:true) I see that it shows 2 parsers being used. Could we have a case of conflicting parsers? (I know very little about how any of that works)

  1. .local/share/nvim/lazy/nvim-treesitter/parser
  2. /opt/homebrew/Cellar/neovim/0.10.0/lib/nvim/parser

nezudevv avatar Jun 13 '24 20:06 nezudevv

Closing this due to v3 release. It should work when http parser is installed properly. If something goes wrong, try uninstall and reinstall the tree-sitter-http parser.

Feel free to reopen this if it still breaks

boltlessengineer avatar Aug 23 '24 16:08 boltlessengineer