I'm debugging in Visual Studio Code and I have a JSON object that I would like to copy as text to the clipboard.
Is this possible inside of Visual Studio Code?
I found two ways to do that, both of which are a bit hacky (in my eyes).
Use console.log
I think there will be a limit to the size of the string that this can output, but it was satisfactory for my requirements.
In the debug console, write console.log(JSON.stringify(yourJsonObject))
Copy the resulting output from the debug console. That can be a bit tedious for long strings, but a combination of mouse and keyboard (ctrl-shift-end) worked ok for me.
Use a watch (limited to 10'000 characters)
This method only works up to a limited size of the resulting json string (it looks like 10'000 characters).
Set a breakpoint in a reasonable location where your variable is in scope and start your app.
Go to the debug view, add a watch for a temporary variable, e.g. tmpJson
Get your breakpoint to hit.
In the debug console, write var tmpJson = JSON.stringify(yourJsonObject)
This will now have populated the watched variable tmpJson with the string representation of your json object
In the debug view, right click on the watched variable, click copy.
If the string is too long, it cuts it off with a message like the following:
...,"typeName":"rouParallel","toolAssembly":{"id":"ASKA800201","description":"CeonoglodaloD50R6z5","c... (length: 80365)"
But it would work for smaller objects. Maybe this helps some people.
It would be great to have this properly built-in with vscode.
There is an open issue regarding this: https://github.com/microsoft/vscode-java-debug/issues/624
Workaround :
Go to the VARIABLES panel and right click to show contextual menu on a variable
select Set Value
Ctrl+C
(tested on Java, not JavaScript)
I have an easy workaround to copy anything you want:
In the debug console, write JSON.stringify(yourJsonObject)
Copy the string without the double quotes " around the string
Open a browser, such as Chrome, open the inspecting tool, go on the console and write:
copy(JSON.parse("PASTE_THE_STRING_HERE"));
The object is now copy on your keyboard !
If you are debugging Python:
In the DEBUG CONSOLE type, for example:
import json
from pprint import pprint as pp
pp(json.dumps(outDetailsDict))
OUTPUT IS LIKE
{"": {"stn_ix": 43, "stn_name": "Historic Folsom Station (WB)", "name": "", },
...
The fastest way I found to do that on Visual Studio Code was
Adding a breakpoint where is located the object to copy
Right click on object and choose "Add to Watch"
From Watch sidebar, choose option "Copy Value" and it's all! 🎉
Note: this solution seems to work for longer values but not very long values. This answer suggests a 10,000 char limit and uses JSON.stringify(myvar) instead of just str(). On char limit, see also this comment below.
Tested in python debugger
Add the variable to Watch, but converted to string
str(myvar)
Right-click on the value of the watch, and select Copy Value
Now you should get the full value (but not for very long values. See note above).
(var name blurred out):
If you're in debug mode, you can copy any variable by writing copy() in the debug terminal.
This works with nested objects and also removes truncation and copies the complete value.
Tip: you can right click a variable, and click Copy as Expression and then paste that in the copy-function.
While the question presumably deals with JavaScript (JSON) based technologies, many people have posted Python-related posts in this thread. So I'll post a more specific answer for Python, although the reasoning can be extended with some tweaks to JavaScript-based technologies. 😊
Helper strategies for debugging with VSCode
Copying variable FULL VALUE (not truncated) to clipboard while debugging even for very long values and other additional strategies.
1 APPROACH: Access the "Run and Debug" screen and look for the "WATCH" area and double click inside it. Add something like str(<MY_VAR>) which should be the variable you want to find the value of during the debug process;
2 APPROACH: Access the "DEBUG CONSOLE" tab and in the footer (symbol ">") copy and paste the code below or another one of your choice...
def print_py_obj(py_obj, print_id="print_py_obj"):
"""Prints a Python object with its string, type, dir, dict, etc...
Args:
py_obj (Any): Any Python object;
print_id (Optional[str]): Some identifier.
"""
print(" " + str(print_id) + \
" DEBUG >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(" 0 STR >>>>>>>>>>>>>>>>>>>>>>>>")
print(str(py_obj))
print(" 0 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 1 TYPE >>>>>>>>>>>>>>>>>>>>>>>>")
print(type(py_obj))
print(" 1 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 2 DIR >>>>>>>>>>>>>>>>>>>>>>>>")
print(str(dir(py_obj)))
print(" 2 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" 3 DICT >>>>>>>>>>>>>>>>>>>>>>>>")
try:
print(vars(py_obj))
except Exception:
pass
print(" 3 <<<<<<<<<<<<<<<<<<<<<<<<")
print(" " + str(print_id) + \
" DEBUG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
print_py_obj(profit, "<MY_VAR_OPTIONAL_IDENTIFIER>")
NOTE: We may have a 10,000 character limitation for both approaches.
Thanks! 🤗🐧🐍
Yup ! That's very much possible
Select breakpoint near your json variable.Debug.
screnshot . Right click on json body and copy value.That's it.
On the selected breakpoint, go to the Debug Console and print(variable)
Related
I checked the box Use V8 as JavaScript engine.
The demo.txt could be:
"date": "2019-11-22T20:49:21"
"text": ""
"date": "2019-11-22T20:49:24"
"text": ""
I record the macros that replace \n\n by \n, then I save the macros as Delete redundant newlines.jsee.
document.selection.Replace("\\n\\n","\\n",eeReplaceAll | eeFindReplaceRegExp,0);
But, when I run the .jsee for the same demo.txt, here comes the V8 nesting issues occured warning.
enter image description here
enter image description here
By the way, this problem have not happen in the unchecked case.
What's wrong?
I don't know too much about the JavaScript, so I don't know how to upgrade(or fix) the macros recorded in the case of unchecking Use V8 as JavaScript engine option.
And another quetion, can I set breakpoints for macros files for which help me optimize the macros?
I assume that you are using EMEDITOR PROFESSIONAL. According to the manufacturer page EMEDITOR FREE V21.4 "Record and Run only, no scriptable macros". official website
Destruction to your second question, I use "alert" to stop the script at a certain position or to display a certain value of a variable at a position. Also the line "Redraw = false;" is commented out (//) for debugging.
e.g.
if (....){
....
alert("debug loop true")
}else{
...
alert("debug loop else")
}
To the first question, I think I read (can't find the article right now) that the Macro Recorder records in javascript as before (not V8). As you wrote, unchecking "Use V8 as JavaScript engine".
For a simple test, copy the line "alert(" Hello EmEditor")" to the clipboard and then select "Run Clipboard" from the macro menu. If successful, a small window will be displayed. In my environment it is also necessary that the saved script runs first through the following steps:
Menu Macro
Customize...
My Macros
Add (select Macro file)
This is necessary for security reasons.
Is VSCode able to display hex values for local variables in debug mode ? I have been searching for a way to make this happen but with no success.
I know this is an old thread, but it was at the top of my Google search so I thought I'd add some new information, which I found in the issues thread linked by Burt_Harris.
You can't seem to change the formatting of values displayed in the Locals pane or in tooltips, but you can force the formatting on variables in the Watch pane by appending ,x to the variable name.
Other formats exist, such as ,b for binary, ,o for octal. I believe it's based on the GDB display modifiers uses (e.g. display/x myVariable)
Suffixes used in VSCode's Watch pane:
It has been a while since last activity on this, but I found by looking through links from this thread on the Cortex-Debug github (Issues) a solution for me. From the (GDB) Debug Console use -exec set output-radix 16 for hex, set it to 10 for decimal.
I was looking for the same thing and ended up here, and I saw that the feature request has been denied at this time.
But then it hit me: In the watch window, you can add an expression, and Number have a toString method, where you can choose what radix (2-36) to convert the number to. And it works:
Instead of just watching value, watch value.toString(16) for hex.
I tried to add more methods to the Number prototype in my code (I wanted a grouped display), but unfortunately it is only shown as "[Object object]".
I know that this is not exactly what you where looking for, but it is something that works without any plugins.
This answer applies to GDB debugging.
For an active debug session, type the following in the debug console:
-exec set output-radix 16
To apply this every time the debugger runs, add text "set output-radix 16" in the "setupCommands" section of launch.json
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{ "text": "set output-radix 16" }
]
You can't currently, but there are feature requests outstanding for this. According to VSCode core developers, this needs to be implemented in the specific debugger extension for the environment you are debugging.
Links to known related debugger extension feature requests listed below:
Node.js
Python
Vote your preferences by adding thumbs-up to the feature request
Golang
As #some said, you can add an expression in the watch.
Here is the expression you would have to add to display a slice of bytes as a hex string:
call hex.EncodeToString(mySliceOfBytes)
actually you could open debug console and using hex() function to convert values
Using GDB, you can cast it to void*: (void*)var, and it will treat it as a pointer, and show it in hex.
I've been having this problem for some time and have never bothered to fix it since Eclipse has a horrible help system and I can't seem to find the right Google keywords to find what I need.
My problem is that when I refactor a class name, eclipse looks for all potential locations of that name and replaces them.
For instance, if I have a string inside a test case for the "list command" that says something like, "List - list all the users on a team", when I refactor the List.java class to something like UserListCommand.java, the expression inside the string also changes to "UserListCommand - list all the users on a team"
This is SOOO annoying! And like I said, Google is useless when you cannot even think of the right keywords to use.
Has anyone else had this problem and solved it?
Thanks in advance.
Eclipse calls this updating textual occurrences in comments and strings. I sometimes turn this on so javadoc gets updated correctly if I didn't properly link it. But it can be a pain because it sometimes replaces substrings that match.
I've only seen this when renaming classes or interfaces (methods don't seem to do this, at least not for me),
You need to open the Rename Dialog to stop eclipse from updating textual occurrences in comments and strings:
Highlight the type you want to rename, then either:
press Shift+Alt+R
Right click, then go to refactor->rename.. then instead of typing the new name, there should now be a yellow context popup menu under the class name to be changed which says "Enter new name, press Enter to refactor", notice that there is a down arrow to expand the menu. If you press that instead of enter a new name a new drop down menu appears, select Open Rename Dialog...
Once the Rename Dialog is open:
uncheck "update textual occurences in comments and strings (forces preview)" and "Update fully qualified names in non-Java text files (forces preview)"
Hope that helps
I guess I'm a quick typer because if I type the characters
ArrayList myArray;
myArray.size(
NetBeans auto complete puts the following in my editor
ArrayList myArray;
myArray.add(someVar);
Why? Because the auto completion doesn't have time to find and filter all the method names by the time I type '('. So it takes the the first one from the list it has created and filtered so far: "add". Grrrr!!!
I want to keep method name completion, but I don't want it to happen on '('. I haven't been able to find out how to fine tune this awesome feature to stop it from mangling my code.
I cannot reproduce you problem in NetBeans 7.1.2. Maybe I'm not typing fast enough...
Take a look at the Options to switch off some of the code completion options: Tools->Options, select the Editor section, then the Code Completion tab.
A.S. This is a comment but I don't have the rep.
I definitely experience this issue, and similar ones in other IDEs like Eclipse or Qt Creator - though I can't always be bothered figuring out how they happened. For example in Qt Creator I type:
size_t len = array.size();
and it becomes
size_t len = array.size(;)
because it didn't recognize quickly enough that I wanted to type over the closing ')'.
It is even more annoying when the editor doesn't allow overwriting or tab-jumping those braces as you have to press Right arrow.
In the Xcode editor, how do you set it up to see the structure variable list as you type the structure name and then the "." ??
In Visual C++ I can see the variable list after I hit the "." to any structure.
Thank you.
I believe you're talking about CodeSense. To get that window to pop up, all you need to do is hit the escape key. When you do this in the context of an object reference, you'll see all of the available fields/methods for that object.
Not sure what you're asking exactly but try to show stuff:
ctrl+space