-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy the formatted value from the Variables pane #63007
Comments
(Experimental duplicate detection) |
VS Code knows nothing about JavaScript or JSON. I suggest that you first create a (global) utility function that serialises an object into your format. Then you can use this function either in a watch expression, interactively in the REPL, or you can store the resulting string in additional variables so that it becomes available in the VARIABLES view of the debugger. |
Please ask your question on StackOverflow. We have a great community over there. They have already answered thousands of questions and are happy to answer yours as well. See also our issue reporting guidelines. Happy Coding! |
Hi @weinand, thanks for your reply! I don't know if it's accurate to say that VS Code knows nothing about JavaScript or JSON. The Debug window has a ton of features that are specifically for JavaScript, including the variables pane, call stack, breakpoints, and debug console. But do you mean that all of these features are provided by a separate plugin? If so, I would be happy to open an issue on the appropriate project that deals with JavaScript debugging. At the moment, the "Copy Value" feature is useless in the VS Code Variables pane. If someone copies an array with one element, they will get this string in their clipboard: JSON should suffice for most cases, because this is also valid JS syntax. So even if VS Code just called But actually I would like to propose that VS Code adds two new options to the right-click menu:
Example: const foo = {
a: [1, 2, 3],
b: function(a) { console.log(a) },
c: /asdf/
} Copy Value as JSON would call {"a":[1,2,3],"c":{}} (This is how Copy Value as JS would call Would it be possible to re-open this issue to discuss this new feature? Thanks! EDIT: I found the file where these new options should be added: https://github.com/Microsoft/vscode/blob/master/src/vs/workbench/parts/debug/electron-browser/electronDebugActions.ts |
@ndbroadbent the debugger UI (variables pane, call stack, breakpoints, watches, and debug console) lives in VS Code but is language agnostic. All data showing up in the UI comes from debug extensions. Filing an issue with the JavaScript debugger would not help because debug extensions do not directly participate in the "Copy Value" action offered by VS Code. So I agree that Adding "Copy as JSON" and "Copy as JS" actions make sense when the underlying debugger is JavaScript/Json related. But for C++ and most other languages their usefulness is questionable.
One option would be to implement @isidorn what are your thoughts about this? |
I've actually forked vscode and started seeing if I could get this to work. I've copied the So then I tried: return session.evaluate(`JSON.stringify(${this.value.evaluateName})`, frameId)` and it worked! I just need to strip the leading and trailing quotes from the string. But like you say, the debugger is used for multiple languages, and not just JavaScript. But actually if this |
Here is a prototype that is working for me, but doesn't know anything about the language: ndbroadbent@7d37fe0 |
Your prototype assumes that the debug extension's evaluate request understands JavaScript. This only works for node and chrome debugger extensions... |
Yes that's right, it's only a proof-of-concept to show that it's possible. It looks like it should work, but I'll probably need a lot of help to understand where to put the code and make it work for different languages (or just for JavaScript at the beginning.) And of course, only if other people think this is a useful core feature. Otherwise I can try to build it as an extension. |
I never said that a "Copy as JSON" action is "impossible" ;-) |
Oh yes I totally agree, haha I honestly didn't know if it would be possible at all. I was initially worried that VS Code and the JavaScript environment were totally separate, and that it was a one-way binding into the variables pane. E.g. I was worried that you could only copy what was already in there, but there was no way to actually execute any additional JavaScript. So just for my own sake, it was great to learn more about how it works. And I have to say I am extremely impressed with the Contributing to Code documentation and the setup instructions. For such an enormous project, I'm so impressed that I could just get it running and start debugging with only a few commands. Do you have any ideas for how this might work at the language level? For example, is there already a mechanism for language plugins to inject new commands and features into the Debug window? |
@isidorn could you please help @ndbroadbent |
First of all thanks for the feature request, however closing as a dup of #27950 Secondly, how to solve this:
hope this helps |
@isidorn Thanks for your help, and sorry for the duplicate issue! I might take a look at this some more and see if I can find a good solution. |
Maybe related to: #2163
I'm working on some tests for a library that modifies webpack configuration. I started the debugger to inspect the current webpack config, and now I'm struggling to copy/paste the existing rules so that I can use them as a test case.
I don't want to use
JSON.stringify
to get the string output because the JS object contains some regexes and they can't be serialized. I'm looking for an easy way to copy/paste the complete JavaScript Object, including all of the nested Objects and Arrays, but with JS syntax instead of JSON.I've tried right-clicking on
rules
. If I click "Copy Value" I just get the following string in my clipboard:If I click "Copy as Expression", I get:
Would it be possible to add something like "Copy Full Value"? Not sure how to name it.
Or is there a way I can serialize this into a string that can be copy/pasted? I also tried
webpackConfig.module.rules.toString()
, but I just get:The text was updated successfully, but these errors were encountered: