microsoft / python-language-server

Microsoft Language Server for Python
Apache License 2.0
912 stars 133 forks source link

Variable scoping isn't respected (use-before-declaration allowed by language server) #1837

Open saqadri opened 4 years ago

saqadri commented 4 years ago

Environment data

Declare var = "Hello World" Go to line before declaration and try var.

Expected behaviour

var should not be recognized in autocomplete results by language server before var has been declared

Actual behaviour

var. provides completion results for var as a string. As you type va you get completion option for var, which should not be in scope.

Logs

Downloading https://pvsc.azureedge.net/python-language-server-beta/Python-Language-Server-osx-x64.0.4.127.nupkg...
Language server download complete
Unpacking archive... done
[Info  - 6:08:02 PM] Analysis cache path: /Users/saqadri/Library/Caches/Microsoft/Python Language Server
[Info  - 6:08:02 PM] Microsoft Python Language Server version 0.4.127.0
[Info  - 6:08:02 PM] Workspace root: /Users/saqadri/jupyter
[Info  - 6:08:03 PM] GetCurrentSearchPaths /usr/bin/python 
[Info  - 6:08:03 PM] Interpreter search paths:
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
[Info  - 6:08:03 PM]     /Library/Python/2.7/site-packages
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
[Info  - 6:08:03 PM]     /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
[Info  - 6:08:03 PM]     /opt/yum/lib/python2.7/site-packages
[Info  - 6:08:03 PM] User search paths:
[Info  - 6:08:04 PM] Initializing for /usr/bin/python
[Info  - 6:08:13 PM] Analysis caching mode: None.
[Info  - 6:09:02 PM] Analysis caching mode: None.
[Info  - 6:09:07 PM] Analysis caching mode: None.
[Info  - 4:38:18 PM] Analysis caching mode: None.
Code Action in file:///Users/saqadri/test.py at (0, 0) - (0, 0)
Analysis of test (User) queued. Dependencies: 
Analysis version 914 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.52 ms.
Analysis complete: 1 modules in 4.57 ms.
Analysis version 914 of 1 entries has been completed in 0.74 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 915 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.23 ms.
Analysis complete: 1 modules in 0.92 ms.
Analysis version 915 of 1 entries has been completed in 0.39 ms.
Completions in file:///Users/saqadri/test.py at (3, 1)
Analysis of test (User) queued. Dependencies: 
Analysis version 916 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.12 ms.
Analysis complete: 1 modules in 1.17 ms.
Analysis version 916 of 1 entries has been completed in 0.76 ms.
Code Action in file:///Users/saqadri/test.py at (3, 2) - (3, 2)
Analysis of test (User) queued. Dependencies: 
Analysis version 917 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.11 ms.
Analysis complete: 1 modules in 0.61 ms.
Analysis version 917 of 1 entries has been completed in 0.2 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 918 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.13 ms.
Analysis complete: 1 modules in 0.85 ms.
Analysis version 918 of 1 entries has been completed in 0.25 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 919 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.39 ms.
Analysis complete: 1 modules in 0.9 ms.
Analysis version 919 of 1 entries has been completed in 0.48 ms.
Analysis of test (User) queued. Dependencies: 
Completions in file:///Users/saqadri/test.py at (3, 4)
Analysis version 920 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.43 ms.
Analysis complete: 1 modules in 1.02 ms.
Analysis version 920 of 1 entries has been completed in 0.54 ms.
Code Action in file:///Users/saqadri/test.py at (3, 4) - (3, 4)
Code Action in file:///Users/saqadri/test.py at (0, 0) - (0, 0)
Code Action in file:///Users/saqadri/test.py at (0, 0) - (3, 0)
Code Action in file:///Users/saqadri/test.py at (0, 0) - (0, 0)
Code Action in file:///Users/saqadri/test.py at (1, 0) - (1, 0)
Code Action in file:///Users/saqadri/test.py at (1, 0) - (2, 0)
Code Action in file:///Users/saqadri/test.py at (1, 0) - (5, 0)
Code Action in file:///Users/saqadri/test.py at (1, 0) - (8, 0)
Code Action in file:///Users/saqadri/test.py at (1, 0) - (13, 0)
Code Action in file:///Users/saqadri/test.py at (3, 4) - (3, 4)
Analysis of test (User) queued. Dependencies: 
Analysis version 921 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.23 ms.
Analysis complete: 1 modules in 0.84 ms.
Analysis version 921 of 1 entries has been completed in 0.33 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 922 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.12 ms.
Analysis complete: 1 modules in 0.59 ms.
Analysis version 922 of 1 entries has been completed in 0.2 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 923 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.12 ms.
Analysis complete: 1 modules in 0.61 ms.
Analysis version 923 of 1 entries has been completed in 0.21 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 924 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.1 ms.
Analysis complete: 1 modules in 0.63 ms.
Analysis version 924 of 1 entries has been completed in 0.19 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 925 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.12 ms.
Analysis complete: 1 modules in 0.64 ms.
Analysis version 925 of 1 entries has been completed in 0.2 ms.
Completions in file:///Users/saqadri/test.py at (3, 1)
Analysis of test (User) queued. Dependencies: 
Analysis version 926 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.12 ms.
Analysis complete: 1 modules in 0.59 ms.
Analysis version 926 of 1 entries has been completed in 0.2 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 927 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.2 ms.
Analysis complete: 1 modules in 0.71 ms.
Analysis version 927 of 1 entries has been completed in 0.29 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 928 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.12 ms.
Analysis complete: 1 modules in 0.67 ms.
Analysis version 928 of 1 entries has been completed in 0.21 ms.
Analysis of test (User) queued. Dependencies: 
Completions in file:///Users/saqadri/test.py at (3, 5)
Analysis version 929 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.15 ms.
Analysis complete: 1 modules in 0.68 ms.
Analysis version 929 of 1 entries has been completed in 0.23 ms.
Code Action in file:///Users/saqadri/test.py at (3, 5) - (3, 5)
Analysis of test (User) queued. Dependencies: 
Analysis version 930 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.13 ms.
Analysis complete: 1 modules in 0.59 ms.
Analysis version 930 of 1 entries has been completed in 0.21 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 931 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.24 ms.
Analysis complete: 1 modules in 0.73 ms.
Analysis version 931 of 1 entries has been completed in 0.32 ms.
Analysis of test (User) queued. Dependencies: 
Analysis version 932 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.12 ms.
Analysis complete: 1 modules in 0.59 ms.
Analysis version 932 of 1 entries has been completed in 0.2 ms.
Code Action in file:///Users/saqadri/test.py at (3, 2) - (3, 2)
Analysis of test (User) queued. Dependencies: 
Analysis version 933 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.25 ms.
Analysis complete: 1 modules in 0.82 ms.
Analysis version 933 of 1 entries has been completed in 0.35 ms.
Completions in file:///Users/saqadri/test.py at (3, 3)
Code Action in file:///Users/saqadri/test.py at (3, 3) - (3, 3)
Analysis of test (User) queued. Dependencies: 
Completions in file:///Users/saqadri/test.py at (3, 4)
Analysis version 934 of 1 entries has started.
Analysis of test (User) on depth 0 completed in 0.27 ms.
Analysis complete: 1 modules in 0.82 ms.
Analysis version 934 of 1 entries has been completed in 0.36 ms.
Code Action in file:///Users/saqadri/test.py at (3, 4) - (3, 4)

Code Snippet / Additional lnformation

VariableScopingIssue


#Bad 
-->var.
var = "Hello world"

def foo():
    # Same issue in function scope
    --> s.
    s = "temp"
jakebailey commented 4 years ago

This is known; the LS doesn't do dataflow analysis to this extent and doesn't recognize ordering.

Jma353 commented 4 years ago

@jakebailey will this change in the future? Have users who have opted-in to the MSFT Python LS in the Python VS Code extension had feedback about this?

jakebailey commented 4 years ago

313, but it hasn't been as big of a problem from the feedback as you might have expected. This may change, but I can't quote a timeline.