pylance-release
pylance-release copied to clipboard
The parseTreeUtils.findNodeByOffset function returns an incorrect node when using binary search
Describe the bug
While debugging an issue related to the method override completion feature in the completion provider, I discovered an issue where the parseTreeUtils.findNodeByOffset
function returns an incorrect node when using binary search.
https://github.com/microsoft/pyright/blob/a8399d3933a635b4b88dff2291d991509e2edf6f/packages/pyright-internal/src/languageService/completionProvider.ts#L1062
https://github.com/microsoft/pyright/blob/a8399d3933a635b4b88dff2291d991509e2edf6f/packages/pyright-internal/src/analyzer/parseTreeUtils.ts#L102-L111
Code or Screenshots
class A:
def read(self): pass
class B(A):
x1 = 1
x2 = 2
x3 = 3
x4 = 4
x5 = 5
x6 = 6
x7 = 7
x8 = 8
x9 = 9
x10 = 10
x11 = 11
x12 = 12
x13 = 13
x14 = 14
x15 = 15
x16 = 16
x17 = 17
x18 = 18
x19 = 19
def r
# note: an empty line in the end of the file
Expected: code completion for the override method read()
Actual: no code completion for read()
If I comment the x19 = 19
statement, the override method code completion works as expected.
VS Code extension or command-line VS Code extension 1.1.359
Since this is related to language server features, I'd appreciate it if the pylance team could take this issue. Feel free to transfer to pylance-release and prioritize as you see fit. @debonte, @rchiodo
This issue has been fixed in prerelease version 2024.6.102, which we've just released. You can find the changelog here: CHANGELOG.md