rest-nvim / rest.nvim

A fast Neovim http client written in Lua
GNU General Public License v3.0
1.61k stars 142 forks source link

Unable to run after update #307

Closed skela closed 8 months ago

skela commented 8 months ago

Updated to the latest version today, but seem to be unable to get it working, even after updating my config.

This is what I have for my login.http file:

POST {{API}}/accounts/login HTTP/1.1
Content-Type: application/json

{
    "userName": "{{USERNAME}}",
    "password": "{{PASSWORD}}",
}

{%

local body = context.json_decode(context.result.body)
context.set_env("TOKEN", body.accessToken)

%}

After selecting my environment, I move the cursor to the POST API line, then run :Rest run , and it fails with some telescope errors. 2024-03-18_15-02 2024-03-18_15-02_1

NTBBloodbath commented 8 months ago

Hi, exactly which character of the method do you have the cursor on? I'm currently in college so I won't be able to help much right now

NTBBloodbath commented 8 months ago

Quick question: does your local installation have this commit? I don't seem to be able to reproduce it 🙁

skela commented 8 months ago

I typically have the cursor on the first character of the line that has the method + url in it, so in this case it would be on the P character. But ive tested it all along that 1st line, its complaining about the same thing regardless of where i have the cursor on that line.

yes the local checkout has that commit in it:

image

Been thinking, it could possibly be a telescope version issue? I havent pinned my telescope, what checkout of telescope are u running?

NTBBloodbath commented 8 months ago

That's weird as I'm unable to reproduce the error. Could you send your :InspectTree output in the http file? Just to rule out that there's no problem with the parser

skela commented 8 months ago

2024-03-19_08-46

NTBBloodbath commented 8 months ago

2024-03-19_08-46

Oh, there is a syntax error in the Lua scripting code, I think that could be the cause. Use --{% and --%} as the delimiters instead of {% and %} to fix the scripting to the new syntax (that change was necessary to avoid false errors with tree-sitter injected languages)

skela commented 8 months ago

Ah ok, i did notice that in yer docs, but i tried with and without that and it didnt seem to make a difference. If I change it to the way you described, it still fails, but with a different error. :InspectTree looks good though.

2024-03-19-171311_hyprshot

Seems like its complaining about my env variables, it might not be able to load them anymore. Used to in the previous versions.

For reference, i have all the http files + the env in a folder called api.

api/login.http api/environments/prod.http.env

Have tried to run it with my cwd 1 level above the api folder (which is my git root), but i get the same error if i cd into the api folder and try to run it from there.

skela commented 8 months ago

Figured it out. It seems rest.nvim is a bit more sensitive to json formatting in the payloads than it used to be. The trailing comma after the password value, caused something to fail somewhere. This used to work, but i suppose it never should have worked (because trailing comma in json isnt really valid).

image

All good, it works, thanks for your help (and yer very awesome plugin)!

NTBBloodbath commented 8 months ago

Oh woops, it seems like my vision might be failing since I hadn't noticed that trailing comma hah. And yeah, now rest.nvim is more strict about that since the JSON body is handled directly by the tree-sitter JSON parser, which we use to obviously parse it :p

Before, if I'm not mistaken, we also used Vimscript functions for JSON, now we use vim.json which is a JSON parser made in C and embedded in Neovim so that could also have affected the trailing commas being valid before.

Thank you very much for your time, a pleasure to have helped :)