microsoft / python-language-server Goto Github PK
View Code? Open in Web Editor NEWMicrosoft Language Server for Python
License: Apache License 2.0
Microsoft Language Server for Python
License: Apache License 2.0
microsoft/PTVS#4286
Steps:
try this code:
s = sum(i for i in [0,1])
hover over s
Expected: s: int
Actual: s: generator[int]
Curious thing is that the type of sum(i for i in [0,1]) does not seem to be inferred at all on its own.
In the VS Code Python extension we are sending a textDocument/documentSymbol
request and using the result to position code lenses. The data we get back is mostly correct. However, the "kind" (i.e. VS Code's SymbolKind) is consistently off by one. For example, using the following Python code:
import unittest
class SpamTests(unittest.TestCase):
def test_all(self):
self.assertTrue(False)
I got the following JSON response from the language server (formatted for clarity):
[{
"name":"SpamTests",
"detail":"SpamTests",
"kind":5,
"deprecated":false,
"range":{
"start":{"line":2,"character":6},
"end":{"line":2,"character":15}
},
"selectionRange":{
"start":{"line":2,"character":6},
"end":{"line":2,"character":15}
},
"children":[{
"name":"test_all",
"detail":"test_all",
"kind":12,
"deprecated":false,
"range":{
"start":{"line":3,"character":4},
"end":{"line":4,"character":30}
},
"selectionRange":{
"start":{"line":3,"character":4},
"end":{"line":4,"character":30}
},
"children":[{
"name":"self",
"detail":"self",
"kind":13,
"deprecated":false,
"range":{
"start":{"line":3,"character":17},
"end":{"line":3,"character":21}
},
"selectionRange":{
"start":{"line":3,"character":17},
"end":{"line":3,"character":21}
},
"children":[],
"_functionKind":""
}],
"_functionKind":"function"
},
{
"name":"assertTrue",
"detail":"assertTrue",
"kind":13,
"deprecated":false,
"range":{
"start":{"line":0,"character":0},
"end":{"line":0,"character":0}
},
"selectionRange":{
"start":{"line":0,"character":0},
"end":{"line":0,"character":0}
},
"children":[],
"_functionKind":""
}],
"_functionKind":"class"
}]
Each of the "kind"
fields is 1 more than it should be:
SpamTests
-> 5; should be 4 (SymbolKind.Class
)
test_all
-> 12; should be 11 (SymbolKind.Function
)
self
-> 13; should be 12 (SymbolKind.Variable
)
assertTrue
-> 13; should be 12 (SymbolKind.Variable
)
FWIW, the Jedi-related code in the Python extension gets it right.
Remove current doc formatting and borrow code from VS Code Python extension that formats documents via third party formatters.
It doesn't add any useful information, and it shows up in places where it probably shouldn't. May as well just show "function" for all of them.
Otherwise, we should make sure it only appears on builtin functions.
This case is similar to microsoft/vscode-python#1072
Intellisense/pylint do not offer autocompletion for a member variable inherited from a base class and shows it as a problem: E1101:Class 'Question' has no 'objects' member
The code runs exactly as intended without errors.
I am actually following the Django tutorial from the official site.
The object's member should be shown in intellisense and it shouldn't log it as a problem
It happens when following the tutorial from djangoproject.org:
https://docs.djangoproject.com/en/2.0/intro/tutorial03/
in section: Write views that actually do something:
from django.http import HttpResponse
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
output = ', '.join([q.question_text for q in latest_question_list])
return HttpResponse(output)
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
Everything runs ok. there is actually nothing in output.
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
)
System check identified no issues (0 silenced).
July 28, 2018 - 10:47:36
Django version 2.0.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[28/Jul/2018 10:47:43] "GET /polls/ HTTP/1.1" 200 11
Output from 'Problems'
{
"resource": "/c:/Users/Ramon Leon/Documents/DjangoProjects/mysite/polls/views.py",
"owner": "python",
"code": "E1101",
"severity": 8,
"message": "E1101:Class 'Question' has no 'objects' member",
"source": "pylint",
"startLineNumber": 9,
"startColumn": 28,
"endLineNumber": 9,
"endColumn": 28
}
Actual work: microsoft/PTVS#4980
Implementation can be borrowed from
https://github.com/Microsoft/vscode-python/blob/master/src/client/formatters/lineFormatter.ts
translate to C#
change it to use LS tokenizer
augment with knowledge of the AST where appropriate (such as checking if = is inside function arguments)
See also microsoft/vscode-python#1799
Contains unexpected reference abc.py, (0, 0) - (0, 0), Definition
Identify undeclared variables, find what module might have them, offer to insert import statement.
Let's say I have pkg
and pkg.subpkg
, both packages. I also have pkg.mod
and pkg.subpkg.submod
, both modules. If I do from .. import mod
from within pkg.subpkg.submode
I get asked which package to resolve to -- pkg/__init__.py
or pkg/mod.py
-- even though pkg.__init__
is empty. I would expect the lack of ambiguity to not ask me which package to resolve to.
Attached are the test files I was using.
pkg.zip
In VS Code
Document outline never populates even if you edit the file. Close and reopen file - now it works.
https://github.com/scikit-learn/scikit-learn takes 2 hours to analyze
microsoft/vscode-python#2430
This can be done via AST rather than by waiting for analysis to complete
The tooltip applies text formatting to the displayed code, e.g. wrapping text in underscores italicizes it.
The tooltip shows the code as it is written in the source.
self
, with underscores in its nameError in Python Extension - Error: command 'completion/itemSelected' already exists
No Errors.
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
Starting Microsoft Python language server.
[Error - 1:46:13 PM] Server initialization failed.
Error: command 'completion/itemSelected' already exists
at e.registerCommand (c:\Program Files\Microsoft VS Code Insiders\resources\app\out\vs\workbench\node\extensionHostProcess.js:689:906)
at Object.registerCommand (c:\Program Files\Microsoft VS Code Insiders\resources\app\out\vs\workbench\node\extensionHostProcess.js:762:949)
at ExecuteCommandFeature.register (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\client.js:1501:53)
at ExecuteCommandFeature.initialize (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\client.js:1491:14)
at LanguageClient.initializeFeatures (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\client.js:2168:21)
at connection.initialize.then (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\client.js:1888:18)
at <anonymous>
Initializing for C:\ProgramData\Anaconda3\python.exe
Initializing for C:\ProgramData\Anaconda3\python.exe
[Error - 1:46:20 PM] System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.PythonTools.Interpreter.Ast.AstPythonInterpreter.ImportModule(String name)
at Microsoft.PythonTools.Analysis.ModuleTable.TryImport(String name, ModuleReference& res)
at Microsoft.PythonTools.Analysis.Analyzer.DDG.TryImportModule(String modName, Boolean forceAbsolute, ModuleReference& moduleRef, IReadOnlyList`1& remainingParts)
at Microsoft.PythonTools.Analysis.Analyzer.DDG.Walk(FromImportStatement node)
at Microsoft.PythonTools.Parsing.Ast.FromImportStatement.Walk(PythonWalker walker)
at Microsoft.PythonTools.Analysis.Analyzer.DDG.Walk(SuiteStatement node)
at Microsoft.PythonTools.Parsing.Ast.SuiteStatement.Walk(PythonWalker walker)
at Microsoft.PythonTools.Parsing.Ast.PythonAst.Walk(PythonWalker walker)
at Microsoft.PythonTools.Analysis.AnalysisUnit.AnalyzeWorker(DDG ddg, CancellationToken cancel)
at Microsoft.PythonTools.Analysis.Analyzer.DDG.Analyze(Deque`1 queue, CancellationToken cancel, Action`1 reportQueueSize, Int32 reportQueueInterval)
at Microsoft.PythonTools.Analysis.PythonAnalyzer.AnalyzeQueuedEntries(CancellationToken cancel)
at Microsoft.PythonTools.Intellisense.AnalysisQueue.GroupAnalysis.Analyze(CancellationToken cancel)
at Microsoft.PythonTools.Intellisense.AnalysisQueue.HandleAnalyzable(IAnalyzable item, AnalysisPriority priority, CancellationToken cancellationToken)
at Microsoft.PythonTools.Intellisense.AnalysisQueue.ConsumerLoop()
Reloading modules...
Reloading modules...
Unhandled Exception: System.ObjectDisposedException: PriorityProducerConsumer`1 instance is disposed
Object name: 'PriorityProducerConsumer`1'.
at Microsoft.PythonTools.Analysis.Infrastructure.DisposeToken.ThrowIfDisposed()
at Microsoft.PythonTools.Analysis.Infrastructure.PriorityProducerConsumer`1.Produce(T value, Int32 priority)
at Microsoft.PythonTools.Intellisense.AnalysisQueue.Enqueue(IAnalyzable item, AnalysisPriority priority)
at Microsoft.PythonTools.Analysis.LanguageServer.Server.ReloadModulesAsync(CancellationToken token)
at Microsoft.PythonTools.Analysis.Infrastructure.TaskExtensions.DoNotWait(Task task)
at Microsoft.Python.LanguageServer.Implementation.LanguageServer.<DidChangeConfiguration>b__29_0()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.ThreadPoolWorkQueue.Dispatch()
[Info - 1:46:22 PM] Connection to server got closed. Server will restart.
[Error - 1:46:22 PM] Request textDocument/documentSymbol failed.
Error: Connection got disposed.
at Object.dispose (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\main.js:825:25)
at Object.dispose (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\client.js:57:35)
at LanguageClient.handleConnectionClosed (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\client.js:2036:42)
at LanguageClient.handleConnectionClosed (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\main.js:127:15)
at closeHandler (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-languageclient\lib\client.js:2023:18)
at CallbackList.invoke (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\events.js:71:39)
at Emitter.fire (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\events.js:135:36)
at closeHandler (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\main.js:221:26)
at CallbackList.invoke (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\events.js:71:39)
at Emitter.fire (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\events.js:135:36)
at StreamMessageReader.AbstractMessageReader.fireClose (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\messageReader.js:135:27)
at Socket.<anonymous> (C:\Users\dojayama.REDMOND\.vscode-insiders\extensions\pythonVSCode\node_modules\vscode-jsonrpc\lib\messageReader.js:188:62)
at emitOne (events.js:101:20)
at Socket.emit (events.js:191:7)
at Pipe._handle.close [as _onclose] (net.js:510:12)
Initializing for C:\ProgramData\Anaconda3\python.exe
Reloading modules...
Reloading modules...
Reloading modules...
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
)
XXX
In the VS Code Python extension we are sending a textDocument/documentSymbol
request and using the result to position code lenses. The data we get back is mostly correct. However, some symbols are missing.
For example, using the following Python code:
import unittest
class SpamTests(unittest.TestCase):
def test_all(self):
self.assertTrue(False)
I got the following JSON response from the language server (formatted for clarity):
[{
"name":"SpamTests",
"detail":"SpamTests",
"kind":5,
"deprecated":false,
"range":{
"start":{"line":2,"character":6},
"end":{"line":2,"character":15}
},
"selectionRange":{
"start":{"line":2,"character":6},
"end":{"line":2,"character":15}
},
"children":[{
"name":"test_all",
"detail":"test_all",
"kind":12,
"deprecated":false,
"range":{
"start":{"line":3,"character":4},
"end":{"line":4,"character":30}
},
"selectionRange":{
"start":{"line":3,"character":4},
"end":{"line":4,"character":30}
},
"children":[{
"name":"self",
"detail":"self",
"kind":13,
"deprecated":false,
"range":{
"start":{"line":3,"character":17},
"end":{"line":3,"character":21}
},
"selectionRange":{
"start":{"line":3,"character":17},
"end":{"line":3,"character":21}
},
"children":[],
"_functionKind":""
}],
"_functionKind":"function"
},
{
"name":"assertTrue",
"detail":"assertTrue",
"kind":13,
"deprecated":false,
"range":{
"start":{"line":0,"character":0},
"end":{"line":0,"character":0}
},
"selectionRange":{
"start":{"line":0,"character":0},
"end":{"line":0,"character":0}
},
"children":[],
"_functionKind":""
}],
"_functionKind":"class"
}]
The symbol for the "unittest" module is missing.
You already have function signatures because you autocomplete them. So take it a step further and show that following code would raiseTypeError
.
def f(foo):
pass
f(bar='some') # Note that 'bar' is not a valid part of the signature.
https://www.python.org/dev/peps/pep-0484/
https://www.python.org/dev/peps/pep-0526/
PEP_526_style: str = "hello world"
captain: str # Note: no initial value!
PEP_484_style = SOMETHING # type: str
PEP_484_style.
PEP_526_style.upper()
captain.upper()
Type declaration is not recognized as string.
Jedi
Related: microsoft/PTVS#3674
Looks like we are only looking into variables in a single file. We are not inspecting all files that may be referencing types from the file the user is is working with. I.e. FindReferences request comes with specific URI but we don't look into other files.
The functionality provided by autoComplete.addBrackets
is not available when using the new analysis engine.
Note: This is a documented feature.
I've also created an issue to track the usage of this feature #1770.
Here's some screenshots:
Note that in both screenshots, the hover popup only shows the Class docstring.
Note: If there is no class docstring, the hover popup has no docstring info.
Hover popup would include constructor docstring. This is how e.g., IPython behaves.
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 17:14:51)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import test
In [2]: test.TestClass?
Init signature: test.TestClass(my_param)
Docstring: Class docstring
Init docstring: Constructor docstring
File: ~/Code/test/test.py
Type: type
N/A
Thanks for the work on the great extension.
microsoft/PTVS#731
microsoft/vscode-python#2377
from collections import namedtuple
RequestStartLine = namedtuple("RequestStartLine", "method path version".split())
start_line = RequestStartLine("GET", "/query", "HTTP/1.1")
print(start_line)
start_line. # <- no suggestion
This needs new specializations
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.