Closed krassowski closed 10 months ago
It seems there is a mismatch between the state of the document (reflected in document.lines
) and the flake8 output. So when document.lines
is accessed in the line you referenced, the actual lines are different.
A possible solution could be to pass document.lines
to parse_output
, instead of document
, so that the latter method is called with the current document state.
Could you try that to see if it fixes the problem? Thanks!
It does. In particular, it seems that accessing document.lines
in a loop is a bad idea as it reads can read from disk at each access (if the private _source
is None):
In 1.8.0 (did not check earlier versions yet) when lines are deleted while flake8 lint is running, and the diagnostic would end out of range of current document, flake8 can error out:
The relevant line is:
https://github.com/python-lsp/python-lsp-server/blob/6c168d0f8ee2e59ec8438373bc2c1b33cb74cdfa/pylsp/plugins/flake8_lint.py#L215
To reproduce create a python file like:
This will generate "F821 undefined name 'variable'". Then proceed to removing the empty lines and observe the error. Note: