Closed eranif closed 4 years ago
Does this client declare its capabilities? Namely the one for workspace/configuration
? The LS will wait for initialized
notification, then issue a workspace/configuration
request back to get the user's configuration before preceding (if the client supports it). If the client declares it can support the call but is actually hanging, then we'll hang too.
Thanks. There was a bug in this LSP specifically (I am still understanding why) that the Initialized
notification was never sent. I fixed that and I got some progress. The server now response to CodeLite's textDocument/didOpen
message, however, it responded with 4 error messages + assertion and terminated.
The 4 messages are:
{"jsonrpc":"2.0","method":"window/showMessage","params":{"type":1,"message":"Interpreter does not exist; analysis will not be available."}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Interpreter search paths:"}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"User search paths:"}}
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":1,"message":"Unable continue, no builtins module content."}}
then immediately after these, I get this message:
{"jsonrpc":"2.0","method":"telemetry/event","params":{"EventName":"python_language_server/rpc.exception","Properties":{"name":"InvalidOperationException","stackTrace":" at Microsoft.Python.Analysis.Modules.BuiltinsPythonModule.LoadContent() in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\BuiltinsPythonModule.cs:line 80\r\n at Microsoft.Python.Analysis.Modules.PythonModule.SetOrLoadContent(String content) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\PythonModule.cs:line 510\r\n at Microsoft.Python.Analysis.Modules.PythonModule.InitializeContent(String content, Int32 version) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\PythonModule.cs:line 500\r\n at Microsoft.Python.Analysis.Modules.PythonModule..ctor(ModuleCreationOptions creationOptions, IServiceContainer services) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\PythonModule.cs:line 113\r\n at Microsoft.Python.Analysis.Modules.PythonModule..ctor(String moduleName, String filePath, ModuleType moduleType, IPythonModule stub, Boolean isTypeshed, IServiceContainer services) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\PythonModule.cs:line 80\r\n at Microsoft.Python.Analysis.Modules.CompiledPythonModule..ctor(String moduleName, ModuleType moduleType, String filePath, IPythonModule stub, Boolean isTypeshed, IServiceContainer services) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\CompiledPythonModule.cs:line 30\r\n at Microsoft.Python.Analysis.Modules.BuiltinsPythonModule..ctor(String moduleName, String filePath, IServiceContainer services) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\BuiltinsPythonModule.cs:line 43\r\n at Microsoft.Python.Analysis.Modules.Resolution.MainModuleResolution.CreateBuiltinsModule(IServiceContainer services, IPythonInterpreter interpreter, IStubCache stubCache) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\Resolution\\MainModuleResolution.cs:line 240\r\n at Microsoft.Python.Analysis.Modules.Resolution.MainModuleResolution.ReloadAsync(CancellationToken cancellationToken) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Modules\\Resolution\\MainModuleResolution.cs:line 228\r\n at Microsoft.Python.Analysis.Analyzer.PythonInterpreter.InitializeAsync(String root, IServiceManager sm, String typeshedPath, ImmutableArray`1 userConfiguredPaths, CancellationToken cancellationToken) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Analyzer\\PythonInterpreter.cs:line 61\r\n at Microsoft.Python.Analysis.Analyzer.PythonInterpreter.CreateAsync(InterpreterConfiguration configuration, String root, IServiceManager sm, String typeshedPath, ImmutableArray`1 userConfiguredPaths, CancellationToken cancellationToken) in C:\\src\\mspyls\\src\\Analysis\\Ast\\Impl\\Analyzer\\PythonInterpreter.cs:line 73\r\n at Microsoft.Python.LanguageServer.Implementation.Server.InitializedAsync(InitializedParams params, CancellationToken cancellationToken, IReadOnlyList`1 userConfiguredPaths) in C:\\src\\mspyls\\src\\LanguageServer\\Impl\\Implementation\\Server.cs:line 167\r\n at Microsoft.Python.LanguageServer.Implementation.LanguageServer.Initialized(JToken token, CancellationToken cancellationToken) in C:\\src\\mspyls\\src\\LanguageServer\\Impl\\LanguageServer.Lifetime.cs:line 59","method":"initialized","plsVersion":"1.0.0.0-debug"},"Measurements":{}}}
And here is the stacktrace in a human readable format:
at Microsoft.Python.Analysis.Modules.BuiltinsPythonModule.LoadContent() in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\BuiltinsPythonModule.cs:line 80
at Microsoft.Python.Analysis.Modules.PythonModule.SetOrLoadContent(String content) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\PythonModule.cs:line 510
at Microsoft.Python.Analysis.Modules.PythonModule.InitializeContent(String content, Int32 version) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\PythonModule.cs:line 500
at Microsoft.Python.Analysis.Modules.PythonModule..ctor(ModuleCreationOptions creationOptions, IServiceContainer services) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\PythonModule.cs:line 113
at Microsoft.Python.Analysis.Modules.PythonModule..ctor(String moduleName, String filePath, ModuleType moduleType, IPythonModule stub, Boolean isTypeshed, IServiceContainer services) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\PythonModule.cs:line 80
at Microsoft.Python.Analysis.Modules.CompiledPythonModule..ctor(String moduleName, ModuleType moduleType, String filePath, IPythonModule stub, Boolean isTypeshed, IServiceContainer services) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\CompiledPythonModule.cs:line 30
at Microsoft.Python.Analysis.Modules.BuiltinsPythonModule..ctor(String moduleName, String filePath, IServiceContainer services) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\BuiltinsPythonModule.cs:line 43
at Microsoft.Python.Analysis.Modules.Resolution.MainModuleResolution.CreateBuiltinsModule(IServiceContainer services, IPythonInterpreter interpreter, IStubCache stubCache) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\Resolution\MainModuleResolution.cs:line 240
at Microsoft.Python.Analysis.Modules.Resolution.MainModuleResolution.ReloadAsync(CancellationToken cancellationToken) in C:\src\mspyls\src\Analysis\Ast\Impl\Modules\Resolution\MainModuleResolution.cs:line 228
at Microsoft.Python.Analysis.Analyzer.PythonInterpreter.InitializeAsync(String root, IServiceManager sm, String typeshedPath, ImmutableArray`1 userConfiguredPaths, CancellationToken cancellationToken) in C:\src\mspyls\src\Analysis\Ast\Impl\Analyzer\PythonInterpreter.cs:line 61
at Microsoft.Python.Analysis.Analyzer.PythonInterpreter.CreateAsync(InterpreterConfiguration configuration, String root, IServiceManager sm, String typeshedPath, ImmutableArray`1 userConfiguredPaths, CancellationToken cancellationToken) in C:\src\mspyls\src\Analysis\Ast\Impl\Analyzer\PythonInterpreter.cs:line 73
at Microsoft.Python.LanguageServer.Implementation.Server.InitializedAsync(InitializedParams params, CancellationToken cancellationToken, IReadOnlyList`1 userConfiguredPaths) in C:\src\mspyls\src\LanguageServer\Impl\Implementation\Server.cs:line 167
at Microsoft.Python.LanguageServer.Implementation.LanguageServer.Initialized(JToken token, CancellationToken cancellationToken) in C:\src\mspyls\src\LanguageServer\Impl\LanguageServer.Lifetime.cs:line 59
[02:36:27:735 DBG] [Main] Process terminated. Assertion failed.
at Microsoft.Python.LanguageServer.Implementation.LanguageServer.DidOpenTextDocument(JToken token, CancellationToken cancellationToken) in C:\src\mspyls\src\LanguageServer\Impl\LanguageServer.cs:line 123
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecuteFromThreadPool(Thread threadPoolThread)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Any ideas? Thanks
You must specify path to Python executable. Have a look at https://github.com/microsoft/vscode-python/blob/master/src/client/activation/languageServer/analysisOptions.ts
The first four are logging, the fifth is the standard LSP telemetry notification which we use to gather stack traces on major RPC errors.
This means the initialization options aren't being set correctly, as it's trying to execute python but failing. The path may be wrong, and the version number is not exactly semver (i.e. it's 3.8
versus 3.8.1
or similar) which can all break things.
Note that you can send no initialization options and it will use the python in PATH, but that may not be desired.
So I took the advise of @jakebailey and fixed my PATH
environment variable to include the location of my python.exe, restarted the LSP and it is now showing different messages.
Here is the log from CodeLite's log file (in DEBUG mode). In short:
C:\python38-64\python.exe
syntax error
Questions:
initializationOptions
is defined as any
- a wildcardLog:
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"No interpreter specified, using Python from PATH."}}
[22:52:23:726 DBG] [Main] received telemetry/log message:
[22:52:23:726 DBG] [Main] {
"type": 3,
"message": "No interpreter specified, using Python from PATH."
}
[22:52:23:758 DBG] [Main] [MS python LSP] Content-Length: 129
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"GetCurrentSearchPaths C:\\python38-64\\python.exe "}}
[22:52:23:759 DBG] [Main] received telemetry/log message:
[22:52:23:759 DBG] [Main] {
"type": 3,
"message": "GetCurrentSearchPaths C:\\python38-64\\python.exe "
}
[22:52:23:835 DBG] [Main] [MS python LSP] Content-Length: 104
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Interpreter search paths:"}}Content-Length: 104
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":" c:\\python38-64\\dlls"}}Content-Length: 103
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":" c:\\python38-64\\lib"}}Content-Length: 98
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":" c:\\python38-64"}}Content-Length: 118
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":" c:\\python38-64\\lib\\site-packages"}}Content-Length: 97
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"User search paths:"}}
[22:52:23:836 DBG] [Main] received telemetry/log message:
[22:52:23:837 DBG] [Main] {
"type": 3,
"message": "Interpreter search paths:"
}
[22:52:23:837 DBG] [Main] received telemetry/log message:
[22:52:23:838 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64\\dlls"
}
[22:52:23:838 DBG] [Main] received telemetry/log message:
[22:52:23:839 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64\\lib"
}
[22:52:23:840 DBG] [Main] received telemetry/log message:
[22:52:23:840 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64"
}
[22:52:23:841 DBG] [Main] received telemetry/log message:
[22:52:23:841 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64\\lib\\site-packages"
}
[22:52:23:842 DBG] [Main] received telemetry/log message:
[22:52:23:842 DBG] [Main] {
"type": 3,
"message": "User search paths:"
}
[22:52:24:341 DBG] [Main] [MS python LSP] Content-Length: 123
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Initializing for C:\\python38-64\\python.exe"}}
[22:52:24:342 DBG] [Main] received telemetry/log message:
[22:52:24:342 DBG] [Main] {
"type": 3,
"message": "Initializing for C:\\python38-64\\python.exe"
}
[22:52:24:363 DBG] [Main] Process terminated. Assertion failed.
at Microsoft.Python.LanguageServer.Implementation.LanguageServer.DidOpenTextDocument(JToken token, CancellationToken cancellationToken) in C:\src\mspyls\src\LanguageServer\Impl\LanguageServer.cs:line 123
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecuteFromThreadPool(Thread threadPoolThread)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
You may want to set breakpoints and debug your sequence of initialization.
@123 is Debug.Assert(_initialized);
this means LS never received Initialized
from the host app. You can attach .NET debugger to it, such as VS on Windows (there is free Community edition) or VS Code on Linux/Mac as described in https://github.com/microsoft/python-language-server/blob/master/CONTRIBUTING.md
In Program.cs
you can uncomment // #define WAIT_FOR_DEBUGGER
so LS will wait for the debugger attach.
Here is the log from the client side. Reading it, it follows all RFC steps as described in this document: https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#initialize
window/logMessage
messages initialize
request and list all its capabilitiesInitializedNotification
initialize
request since it is still initializing itself (there is list of telemetry messages coming in after the initialize
response is arrived from the server[13:49:40:783 DBG] [Main] [MS Python] Sending initialize request...
[13:49:40:784 DBG] [Main] LSPNetworkSTDIO:
Content-Length: 220
{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"processId":2196,"rootUri":"file:///C:/Users/Eran/Desktop","capabilities":{"textDocument":{"completion":{"completionItem":{"documentationFormat":["plaintext"]}}}}}}
[13:49:41:134 DBG] [Main] [MS Python] Client still initializing
[13:49:41:135 DBG] [Main] [MS Python] {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Analysis cache path: C:\\Users\\Eran\\AppData\\Local\\Microsoft\\Python Language Server"}}
[13:49:41:145 DBG] [Main] [MS Python] Client still initializing
[13:49:41:146 DBG] [Main] [MS Python] {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Microsoft Python Language Server version 1.0.0.0"}}
[13:49:41:146 DBG] [Main] [MS Python] Client still initializing
[13:49:41:147 DBG] [Main] [MS Python] {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Workspace root: C:\\Users\\Eran\\Desktop"}}
[13:49:41:167 DBG] [Main] [MS Python] {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"textDocumentSync":{"openClose":true,"change":2,"willSave":false,"willSaveWaitUntil":false},"hoverProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":["."]},"signatureHelpProvider":{"triggerCharacters":["(",",",")"]},"definitionProvider":true,"referencesProvider":true,"documentHighlightProvider":true,"documentSymbolProvider":true,"workspaceSymbolProvider":true,"codeActionProvider":{"codeActionKinds":["quickfix","refactor"]},"documentFormattingProvider":false,"documentRangeFormattingProvider":false,"documentOnTypeFormattingProvider":{"firstTriggerCharacter":"\n","moreTriggerCharacter":[";",":"]},"renameProvider":true,"declarationProvider":true}}}
[13:49:41:168 DBG] [Main] [MS Python] Sending InitializedNotification
[13:49:41:168 DBG] [Main] LSPNetworkSTDIO:
Content-Length: 52
{"jsonrpc":"2.0","method":"initialized","params":{}}
[13:49:41:169 DBG] [Main] [MS Python] initialization completed
After the client decides that the initialization phase is over, I can still see this in the log:
[13:49:41:233 DBG] [Main] received telemetry/log message:
[13:49:41:234 DBG] [Main] {
"type": 3,
"message": "No interpreter specified, using Python from PATH."
}
[13:49:41:244 DBG] [Main] received telemetry/log message:
[13:49:41:245 DBG] [Main] {
"type": 3,
"message": "GetCurrentSearchPaths C:\\python38-64\\python.exe "
}
[13:49:41:321 DBG] [Main] received telemetry/log message:
[13:49:41:322 DBG] [Main] {
"type": 3,
"message": "Interpreter search paths:"
}
[13:49:41:322 DBG] [Main] received telemetry/log message:
[13:49:41:323 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64\\dlls"
}
[13:49:41:323 DBG] [Main] received telemetry/log message:
[13:49:41:324 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64\\lib"
}
[13:49:41:324 DBG] [Main] received telemetry/log message:
[13:49:41:325 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64"
}
[13:49:41:325 DBG] [Main] received telemetry/log message:
[13:49:41:326 DBG] [Main] {
"type": 3,
"message": " c:\\python38-64\\lib\\site-packages"
}
[13:49:41:327 DBG] [Main] received telemetry/log message:
[13:49:41:327 DBG] [Main] {
"type": 3,
"message": "User search paths:"
}
[13:49:41:684 DBG] [Main] received telemetry/log message:
[13:49:41:685 DBG] [Main] {
"type": 3,
"message": "Initializing for C:\\python38-64\\python.exe"
}
Just out of curisosity, you mentioned this:
this means LS never received Initialized from the host app
Who is this "host app" that you are referring to? is this the client (i.e CodeLite IDE) ? or... are you just a wrapper for something else?
The client IDE.
Try using actual debugger rather than log traces. In VS its Debug | Attach to Process
-> pick dotnet.exe
. JSON RPC is async so some messages may appear out of order, but that's why LS has prioritizer which queues messages and routes them in order so say, open file does not come until LS gets initialized
from the client. You can set breakpoints in [JsonRpcMethod("initialized")]
and [JsonRpcMethod("initialize")]
and check what happens.
Also, yes, initialize
yields and does not block. However, initialized
should block until task started in initialize
completes. See source in LanguageServer.Lifetime.cs
.
I tried that (had to register an account to install visual studio...) I was able to debug dotnet process, however, no symbols were found. I tried to point VS to the .pdb file (Microsoft.Python.LanguageServer.pdb with no luck) Any hints - this is my first time debugging dotnet process...
You need to a) have solution open and b) copy pdb along with dll. Please follow steps in https://github.com/microsoft/python-language-server/blob/master/CONTRIBUTING.md
https://github.com/microsoft/python-language-server/blob/master/CONTRIBUTING.md Visual Studio:
NET Core Cross Platform Development
option on.PLS.sln
solution in src
.Program.cs
uncomment // #define WAIT_FOR_DEBUGGER
so LS will wait for the debugger to attach.Microsoft.Python.LanguageServer
project.output/bin/Debug
to whatever folder you run it from.output/bin/Debug
Debug | Attach To Process
Thanks for the assistance.
I managed to load the SLN in VS2019 Community addition (turns out I had it installed on my machine). It did some upgrade and then I started to build the Microsoft.Python.LanguageServer
I got some errors:
The feature 'async streams' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version
I googled that and it seems that I need to enable something in the project settings.
Attempting to right click the project and then select 'properties' -> resulted in an error:
An error occurred trying to load the page.
Could not load file or assembly 'Microsoft.VSDesigner, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Any hints?
I am trying to downgrade my .NET to 2.2 (as suggested in one of the links). The other links you posted, offers .NET 3.1
EDIT: No luck. it now complains about version too old.
LS is on 3.1
Thanks, I reverted back to 3.1. Trying to fix the 'preview' error messages I get. I am now installing an update to the VS 2019 Hopefully it will fix the 'unable to open project settings' bug as reported here: https://developercommunity.visualstudio.com/content/problem/460020/project-properties-build-page-blank.html
I now able to build it inside VS.. Moving on to the debugging part :)
I did the following:
define WAIT_FOR_DEBUGGER
dotnet exec Microsoft.Python.LanguageServer.dll
and the working directory is set to C:\src\mspyls\output\bin\Debug
- the application is launched successfullyCtrl-Alt-P
(Attach to process) -> choose dotnet.exe
, debugger is attached. However, no symbols are found. I doubled check and the .pdb
exists with the same file name right next to the .dll
file see attached image.Did I miss anything?
Also, can I start mspyls and using tcp instead of stdin/stdout? (other LSPs do offer this option). If this would be available, I could start the LSP from within VS without needing the hacks of WAIT_FOR_DEBUGGER
Check that during Attach Attach To
is set to CoreCLR.
I did, still no luck. I think I am gonna close this issue and I will stick to the other python LSP that works for me. thanks for the assistance
Hi,
I am trying to integrate this LSP into CodeLite IDE LSP plugin I have built the binary from sources, no problems here.
I configured CodeLite to start the executeable and it seems that the initialization requests goes as expected.
In CodeLite's log I see this:
Request:
And then the LSP replies with 4 messages (3 events and 1 reply):
and finally the response itself for the initialize request:
At this point CodeLite's LSP plugin marks this server as "initialization completed"
From here on, the LSP server stops to respond: In the IDE, I am doing the following:
Note that CodeLite's plugin is mature and is working successfully with various servers, such as
clangd
other python LSP servers & JAVA server and multiple others.Any advise on how to debug this issue? adding somekind of verbosity to the LSP server?
Thanks