Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Debug console: \n not shown as new line (NumPy ndarray) #1432

Closed
DonJayamanne opened this issue May 17, 2019 · 10 comments
Closed

Debug console: \n not shown as new line (NumPy ndarray) #1432

DonJayamanne opened this issue May 17, 2019 · 10 comments
Labels

Comments

@DonJayamanne
Copy link
Contributor

@yzhang-gh commented on Fri May 17 2019

Copied from microsoft/vscode#73845

Environment data

  • VS Code version: 1.34.0
  • Extension version (available under the Extensions sidebar): 2019.4.12954
  • OS and version: Windows 10 build18898
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.1
  • Relevant/affected Python packages and their versions: NumPy

Expected behaviour

When evaluating a NumPy ndarray in the debug console, the \n should become a new line.

>>> import numpy as np
>>> a = np.arange(15).reshape(3, 5)
>>> a
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])

Actual behaviour

image

Steps to reproduce:

  1. Start a debug session
  2. Type import numpy as np
  3. Type np.random.rand(5, 5)
@int19h
Copy link
Contributor

int19h commented May 18, 2019

This happens for any object that has repr() with newlines (and also tabs).

But this is a VSCode bug . When we send the variable value back, it's a JSON string literal, and \n in that literal is an escape character that must be deserialized as newline. For some reason, VSCode replaces any such newlines with a literal sequence \n after deserialization. It also does the same for \t, but not for e.g. \f. For example, this:

class Foo(object):
    def __repr__(self):
        return 'foo\tbar\nbaz\fblah'
foo = Foo()

produces this in the log:

{
    "name": "foo",
    "value": "foo\tbar\nbaz\fbah",
    "type": "Foo",
    "evaluateName": "foo",
    "variablesReference": 7
},

which is correct, but it is then rendered like so in Variables:

image

Given the difference in treatment, this is likely intentional.

@yzhang-gh
Copy link

But this is a VSCode bug ...

cc @isidorn

@isidorn
Copy link

isidorn commented May 23, 2019

Yeah this is intentional, we use \n and \t in the variables view to save on space. If you think this is wrong please file a new feature request against vscode and argue for your case. Thanks

@fabioz
Copy link
Contributor

fabioz commented May 23, 2019

@isidorn the issue happens in the debug console, not in the variables view (it makes sense in the variables view for me as the space is really limited but seems strange in the debug console where the user is evaluating probably because he couldn't see very well in the variables view).

The issue was already reported to VSCode (microsoft/vscode#73845) and was moved here because it was marked as caused-by-extension, but as that doesn't seem to be the case. I'll add more info to that issue and close this one as it doesn't seem to be caused by the extension.

@fabioz fabioz closed this as completed May 23, 2019
@yzhang-gh
Copy link

Thank you all!

@rbu
Copy link

rbu commented Nov 3, 2019

@isidorn @yzhang-gh @int19h The issue on vscode (microsoft/vscode#73845) was closed as out of scope and was refered back to this extension. Could you reopen this bug as a consequence?

The current state makes the debug console unusable for any multiline strings (such as tabluar data). I see the space optimization point for the Variables view, but the console should use the horizontal space it has available (like any other terminal).

To give you an example, I'm trying to make sense of this "table".
image

@int19h int19h reopened this Nov 3, 2019
@fabioz
Copy link
Contributor

fabioz commented Nov 4, 2019

Well, as it stands, the only way I can see here would be not returning a frameReference and just print the result instead (i.e.: when the user does np.random.rand(5, 5), instead of returning the variable we'd return nothing and would print it instead).

-- note that right now the workaround is doing the print yourself:

i.e.: Instead of doing:

np.random.rand(5, 5)

you can do:

print(np.random.rand(5, 5))

the downside is that it won't be expandable/collapsible, but without the change in microsoft/vscode#73845, the extension is powerless to decide how it wants variableReferences to be shown in the debug console (see my comment at microsoft/vscode#73845 (comment)).

@int19h
Copy link
Contributor

int19h commented Nov 4, 2019

We need changes from VSCode to fix this properly, and we'll ask for them. But until then, it still manifests as a product bug in the debugger, so we'll track that here.

@luabud
Copy link
Member

luabud commented Jan 22, 2020

Upstream issue: microsoft/vscode#89114

@ychechik
Copy link

@luabud This is now solved upstream: microsoft/vscode#73845 (comment)

@int19h int19h closed this as completed Apr 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

9 participants