Giter Site home page Giter Site logo

Use of .httpyac.json about vscode-httpyac HOT 13 CLOSED

anweber avatar anweber commented on May 18, 2024
Use of .httpyac.json

from vscode-httpyac.

Comments (13)

AnWeber avatar AnWeber commented on May 18, 2024 1

rest-client does this with IntelliSense for variables

rest-client does this, but you should have seen how many times I have got an breakpoint/ interrupt while debugging on my NodeJS PR (674). One keypress in the http file and +10 rechecking of the variables

I understand your concern. I have included exactly the command for troubleshooting. I run the request, and on errors I can look what variables are defined. You want to check the variables before sending and that makes sense for critical requests. I just don't quite like the way it works yet. I would rather implement the solution via DebugAdapater, but I don't have the time. Until then I'll implement my own command validateVariables, which prepares the request, resolves all variables but doesn't send the actual request them.

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

Here you can find an example how the use of a .httpyac.json would look like.
But unfortunately there is a bug. Currently the settings from the file are loaded but not used. I didn't notice it because I use .env files myself.

from vscode-httpyac.

asherber avatar asherber commented on May 18, 2024

Thanks, I appreciate the correction on the format of the file, and I'll wait for the bug fix to hit the released version.

Can you please clarify where I should be able to put the file? Is it the same locations as for .env?

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

(As a side note, it would be nice if I could hover over variables in the .http file to see the resolved value, or an error if the variable can't be found. Currently, I have to submit the request and see the resulting error to suss out any problems.)

I've been thinking about this feature for a while, but I don't have an idea yet how to solve this without unreasonably high CPU and Memory consumption. The only way I can correctly determine all variables is to execute the request on every change in a http file.

  • Variables defined in Javascript. Scripts loaded by require can also set variables.
  • References to other responses, because here the return type is not known
  • Environment variables loaded from e.g. Spring Config Cloud or Hashicorp Vault, which are different depending on selected environment (maybe cachable?).

I do not want to include this function only so half ready. vscode-restclient tries to implement this feature and has as a consequence the performance problems.

As a solution I have currently built in that you can display the current variables (command httpyac.showVariables). I will wrap this soon in a TreeDataProvider. I am open for good ideas.

from vscode-httpyac.

asherber avatar asherber commented on May 18, 2024

Yes, I'm currently using rest-client but looking to switch because of all the goodies your extension offers. Intellisense evaluation of variables is one thing I do miss from rest-client; it lets me verify that I'm loading the correct values before I send the request. I understand that it's more complicated for your extension because of all the extra ways that variables can be set. 

How about something like a CodeLens link to display the variable values for the current request?

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

I will add a CodeLens link für the command httpyac.showVariables. I would have thought of CompletionItemProvider (better IntelliSense) as well, but just haven't gotten around to it yet.

from vscode-httpyac.

asherber avatar asherber commented on May 18, 2024

Vielen Dank!

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

Es war mir eine Freude:-)

I have provided the update. Can you please also test it and give feedback?

Can you please clarify where I should be able to put the file?

.httpyac.js or .env are searched the directory tree upwards (till root). First found location is used.

from vscode-httpyac.

asherber avatar asherber commented on May 18, 2024

Variable resolution with .httpyac.json seems to work as expected.

The 'show variables' link appears at the top of the file, and it doesn't take into account global variables in that file (or per-request variables). Is that the intent? I was picturing a link for each request, showing (as best as possible) everything in scope for that request.

'show variables' also opens an untitled document window, and then vscode prompts me to save when I close it.

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

showVariables just shows the current state of the variables. No code is executed during this process. You can simply execute the request and then view the variables.
An alternative would be to install httpyac on the command line and view the variables using {{debugger;}} (see docs).

I prevent the unexpected execution so explicitly, because I also create database entries in scripts, or combine writing services. However, in my cases I also have >80% of the variables in .env files and the remaining variables are generated in the same file, so it is easy for me to know the correct names. Do you dynamically create the variables in the NodeJs scripting part that it is difficult to know all the variable names present?

from vscode-httpyac.

asherber avatar asherber commented on May 18, 2024

I understand about the limitations -- variables could come from anywhere, and you don't want to run all of the associated scripts in order to generate those.

All of my variables are either in .httpyac.json or in the .http file itself. With the 'show variables' link at the top of the file, I would expect at least that variables from the global section of the file would be evaluated. Instead, it looks like only json/.env variables are evaluated.

I think it would also be more useful to have this link for each request, and then to include in evaluation the per-request variables.

My goal is to be able to determine, before running a request, the values assigned to variables. This helps in troubleshooting, because it lets me see if maybe I've screwed up the inheritance chain. rest-client does this with IntelliSense for variables; I understand that you don't want to do this because of the overhead.

from vscode-httpyac.

AnWeber avatar AnWeber commented on May 18, 2024

The command httpyac.validateVariables was rolled out with the new version.

from vscode-httpyac.

asherber avatar asherber commented on May 18, 2024

Looks great, thanks!

from vscode-httpyac.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.