You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are attempting to use the codemirror-languageserver npm package as a client for a remote instance of the python-lsp-server. For the most part, we have been successful and the plugin seamlessly supports autocompletions, linting and syntax checking. Our progress can be found in the demo-project folder of our testing repo.
However, we are struggling to get a simple formatting request to successfully return on a button press. Since the codemirror package has no functionality supporting this, we are just directly sending a formatting request via a websocket following the Microsoft LSP standards. Unfortunately, we're getting a AttributeError: 'NoneType' object has no attribute 'get_document' in response. We are getting the same response for the textDocument/rangeFormatting method as well. Any help would be greatly appreciated, and I'll keep this issue updated as I continue to investigate too. Really, I'm just trying to determine if this is a bug or we are incorrectly using the API. Thanks so much!
We tried defining workspace folders in the init configuration with no luck
Looking at the pylsp/python_lsp.py file containing the lines of code causing the error, it seems like the self._match_uri_to_workspace(doc_uri) call is returning a NoneType and then cause the error that is returned. This is confusing me for a couple of reasoning
Looking at the full error log, the docUri parameter is defined
We've successfully used this document as the target of other LSP methods via the codemirror plugin such as textDocument/didChange (see log below), so I'm unsure why the formatting methods specifically are failing
I spun up a dev instance of the python-lsp-server to see if custom logging would help shed light on the issue.
Logging self.workspaces at the end of m_initialize gives 2024-06-04 12:41:11,980 EDT - DEBUG - pylsp.python_lsp - Workspaces: {'file:///home/': <pylsp.workspace.Workspace object at 0x7fc4801644f0>} meaning the workspace is seemingly correctly defined on initialization
However, logging self.workspaces after a m_text_document__formatting call gives 2024-06-04 12:47:47,012 EDT - INFO - pylsp.python_lsp - workspaces {} meaning that either there are two instances of PythonLSPServer or somehow the workspaces attribute is getting overridden
I'm very confused, I feel like I have to be missing something obvious here
Relevant Code Snippets
Below are the relevant code snippets and error messages
Initial Config via Codemirror Language Server Client
Hey @ElliotRoe, thanks for reporting. Quick question because I didn't see it mentioned in your message: did you send a didOpen request before sending the formatting one?
If the document was not added to the workspace, that could be the cause of your error.
Hi @ccordoba12 ! Thanks for your response. Looking through the code, the codemirror language server client plugin does send a textDocument/didOpen request upon codemirror component initialization (see their code here). This was also confirmed via logs as I found a successful didOpen notification and several didChange notifications before the above error's timestamp. I included a sample of both occurring before the error timestamp in the logs below.
Sorry, I don't know what happens. It seems either the document is not registered in the workspace or the initial workspace is not registered as expected.
Summary
We are attempting to use the codemirror-languageserver npm package as a client for a remote instance of the python-lsp-server. For the most part, we have been successful and the plugin seamlessly supports autocompletions, linting and syntax checking. Our progress can be found in the demo-project folder of our testing repo.
However, we are struggling to get a simple formatting request to successfully return on a button press. Since the codemirror package has no functionality supporting this, we are just directly sending a formatting request via a websocket following the Microsoft LSP standards. Unfortunately, we're getting a
AttributeError: 'NoneType' object has no attribute 'get_document'
in response. We are getting the same response for thetextDocument/rangeFormatting
method as well. Any help would be greatly appreciated, and I'll keep this issue updated as I continue to investigate too. Really, I'm just trying to determine if this is a bug or we are incorrectly using the API. Thanks so much!Investigation (so far)
pylsp/python_lsp.py
file containing the lines of code causing the error, it seems like the self._match_uri_to_workspace(doc_uri) call is returning a NoneType and then cause the error that is returned. This is confusing me for a couple of reasoningtextDocument/didChange
(see log below), so I'm unsure why the formatting methods specifically are failingself.workspaces
at the end ofm_initialize
gives2024-06-04 12:41:11,980 EDT - DEBUG - pylsp.python_lsp - Workspaces: {'file:///home/': <pylsp.workspace.Workspace object at 0x7fc4801644f0>}
meaning the workspace is seemingly correctly defined on initializationself.workspaces
after am_text_document__formatting
call gives2024-06-04 12:47:47,012 EDT - INFO - pylsp.python_lsp - workspaces {}
meaning that either there are two instances ofPythonLSPServer
or somehow the workspaces attribute is getting overriddenRelevant Code Snippets
Below are the relevant code snippets and error messages
Initial Config via Codemirror Language Server Client
JSON Request
Full Logs of
AttributeError: 'NoneType' object has no attribute 'get_document'
Error MessageSuccessful
textDocument/didChange
method logThe text was updated successfully, but these errors were encountered: