pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

The parseTreeUtils.findNodeByOffset function returns an incorrect node when using binary search

Open trinhanhngoc opened this issue 10 months ago • 1 comments

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()

image

If I comment the x19 = 19 statement, the override method code completion works as expected.

image

VS Code extension or command-line VS Code extension 1.1.359

trinhanhngoc avatar Apr 18 '24 15:04 trinhanhngoc

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

erictraut avatar Apr 18 '24 16:04 erictraut

This issue has been fixed in prerelease version 2024.6.102, which we've just released. You can find the changelog here: CHANGELOG.md

rchiodo avatar Jun 25 '24 21:06 rchiodo