AnWeber / httpbook

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://httpyac.github.io/
MIT License
57 stars 4 forks source link

Changing environment does not work after first call #99

Closed ncsibra closed 9 months ago

ncsibra commented 9 months ago

I'm using dotenv with multiple env files. Changing env in the text editor version of .http file works correctly.

In httpbook when I pick an env from the status bar, then send a request, then pick another env, the env will change based on the status bar text, but actually stays the previous one. If I just open VSCode, don't pick an env and send a request it fails with an error, because some variables only exists in env specific files and they're missing, then pick an env, send again and it still fails. I need to open the text editor version and change env from there to solve the issue. Based on this looks like it saved on first request sent and not after first picking an env.

AnWeber commented 9 months ago

If you don't follow your own rules:-) httpbook uses an API from the extension vscode-httpyac. So that this does not diverge I would have actually created an interface and when changes are made I have to check the other extension to see if it is still compatible. I was lazy. I created a breaking change without noticing it. It is easier to update httpbook to the new API and not revert the breaking change. That's why there is now a new v3.2.1.

ncsibra commented 9 months ago

@AnWeber Thanks for the fix, but looks like you only released httpbook without vscode-httpyac, so it still does not work for me.

patrickhuy commented 9 months ago

@AnWeber I just tried using httpbook for the first time, it looks very nice, but I can't get variables to work at all. I've defined variables in .httpyac.js the environment shows up but the httpbook says the variable is undefined. In the httpyac extension it seems to work fine. Would be great to get this fixed.

AnWeber commented 9 months ago

@ncsibra I still don't quite understand why I just had the "works, don't work" behavior, but yes there are cases where my fix didn't work. Once again, the cause of the problems was that the cells of the notebook for the extension are treated as own files. This made partly the cell as source for the environment and partly the notebook itself as source for the environment. I now actively set the cell as the environment source and with that it should work correctly and matches the display.

ncsibra commented 9 months ago

@AnWeber I'm not familiar with the extension code. I'm not a JS/TS developer, but my assumption based on the quick look at your commits is that it's because you're using setActiveEnvironment in httpbook from the httpyac extension.
You just made public that function in this commit but you did not release a new version from vscode-httpyac so setActiveEnvironment is not available for us.
In your environment, you probably just run both codes from the latest version and that's why it works for you. If I'm wrong, then I have no idea. :)

AnWeber commented 9 months ago

@ncsibra not exactly setActiveEnvironment is already definied since last release of vscode-httpyac I didn't want to make them explicitly public because I didn't think it was necessary. The commit only made it explicit public in the interface/ api, but it was already public in the implementation. The problem is that I now store the activeEnvironment of an HttpFile not directly at the object, but in a record within documentStore. This was unfortunately error prone in hindsight and since I don't really use httpbook I didn't notice it.

AnWeber commented 9 months ago

@ncsibra I would just publish the fix now. Maybe you can test it briefly right away.

@patrickhuy I think your problem could be similar. I first thought it had another cause, but my test just worked with the new version. Could you please also just test it with v3.2.2. Thank you.

ncsibra commented 9 months ago

Thanks, tested it and works for me. 👍

patrickhuy commented 9 months ago

@AnWeber can confirm also works for me. Thanks a lot! So far this appears to be a very great tool!