krasa / GrepConsole

IntelliJ plugin - https://plugins.jetbrains.com/plugin/7125
Apache License 2.0
440 stars 57 forks source link

Source links do not work for remote debugging #144

Open OriginalBitFlipper opened 5 years ago

OriginalBitFlipper commented 5 years ago

Hi,

I'm using PyCharm on Windows 10 and remote debug into a Linux VM. So in this case there are mapped paths between where the Python scripts are locally and where they are located remotely (IOW, Windows style paths locally and Unix style paths remotely), e.g:

Path Mapping: C:\projects\foo -> /home/user/projects/foo

When an exception is thrown, you will see something in the console like this:

    Traceback (most recent call last):
      File "/home/user/projects/foo/bar.py", line 123, in MyFunction

In the original output console, the "/home/user/projects/foo/bar.py" path will be a link, and clicking on it will take you to the corresponding source file, even though the file is located on Windows and the real path is "C:\projects\foo\bar.py".

However in the Grep Console, the source file will not be shown as a link, so one cannot click on it to go to the line where the exception occurred.

Interestingly, if I explicitly print a source line but use the Windows path style, it shows up as a link in Grep Console, e.g.:

   print('   File "C:\\projects\\foo\\bar.py", line 123, in MyFunction')

The above is shown as a link in the Grep Console output and is clickable.

[edit] Note the file must actually exist locally for it to be shown as a link.

So it seems Grep Console only treats Windows style paths on Windows as links, while PyCharm treats both Windows and Unix style paths as links.

I'm not sure who is responsible for displaying a source file as a link in Grep Console. If it is the Grep Console plugin itself then maybe if it simply displays anything within quotes after "File" that looks like either a Windows or a Unix file path as a link to the file, PyCharm will probably do the mapping to the local Windows file automatically when it is clicked, not sure.

PyCharm 2019.1.1 (Professional Edition) Build #PY-191.6605.12, built on April 3, 2019 JRE: 11.0.2+9-b159.34 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0

krasa commented 5 years ago

I found the thing that does it https://github.com/JetBrains/intellij-community/blob/master/python/src/com/jetbrains/python/run/PyRemoteTracebackFilter.java#L28

The solution would be do some dirty hacks and check if the original console has one, and then add it to the grep console. Probably doable.

OriginalBitFlipper commented 5 years ago

Interesting. It's certainly not a critical issue but definitely a very-nice-to-have feature when doing remote debugging + Grep Console.

Thanks for taking a look!