-
Notifications
You must be signed in to change notification settings - Fork 299
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
Line numbers in errors in the interactive window don't match the editor #3309
Comments
Ignore ThisSuggestion
from IPython.core.interactiveshell import InteractiveShell
from functools import wraps
import traceback
import sys
def change_function(func):
@wraps(func)
def showtraceback(*args, **kwargs):
# extract exception type, value and traceback
etype, evalue, tb = sys.exc_info()
orig_value = func(*args, **kwargs)
if issubclass(etype, Exception):
# Do something with the original exception, such as
# Printing it to stderr enclosed within a special delimiter (hardcoded GUID)
# When we get the output from jupyter we'll strip text between those delimiters and extract stack trace, error message, etc and other info from there to display in monaco.
# Everything we need is in `etype, evalue, tb`
return orig_value
return showtraceback
InteractiveShell.showtraceback = change_function(InteractiveShell.showtraceback)
InteractiveShell.showsyntaxerror = change_function....(InteractiveShell.showsyntaxerror) |
Ignore ThisI think this issue might as well display errors returned by the language server.
|
Moving back to backlog for discussions @IanMatthewHuff @rchiodo @DavidKutu |
Actually my proposed solution is completely wrong. |
I wish I had seen microsoft/vscode-python#9984 four hours ago :) Anyway, I got annoyed enough at this to start digging, and came up with a hack "solution" by prepending newlines:
before and after: before, wrong line number:
after, correct line number:
In the course of doing that and digging through IPython code, I noticed that another solution would be to use an AST transformer -- assuming the line number offset could somehow be communicated, it would walk the top-level nodes of IPython's parsed code and adjust the line number. Is that something you folks have considered? (a possible reason not to do that is IIUC edit: just to round this out, I tried the AST transformer solution, and while it works, the problem is that the cached code which IPython refers to when generating tracebacks does not of course have the correct offset applied (so the traceback still points to wrong or blank lines). Another, similar option is an input transformer, with the following patch:
And then:
|
Validated |
Cause an error, it will point to the error in the cell, but the line number doesn't match the original code.
The text was updated successfully, but these errors were encountered: