swyddfa / esbonio

A language server for working with Sphinx projects.

Home Page:https://docs.esbon.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unhandled exception when resolving C++ class links as intersphinx links

dinomight opened this issue · comments

commented

I was generating C++ expression references to a class method and esbonio throws an unhandled exception whenever the document is opened. Here is the traceback I'm getting out of the output window in vscode:

Failed to handle request 4336 textDocument/documentLink partial_result_token=None work_done_token=None text_document=TextDocumentIdentifier(uri='file:///document.rst')
Traceback (most recent call last):
  File "venv\lib\site-packages\pygls\protocol.py", line 331, in _handle_request
    self._execute_request(msg_id, handler, params)
  File "venv\lib\site-packages\pygls\protocol.py", line 260, in _execute_request
    method_name, method_type, msg_id, handler(params))
  File "venv\lib\site-packages\esbonio\lsp\__init__.py", line 275, in on_document_link
    links += feature.document_link(context) or []
  File "venv\lib\site-packages\esbonio\lsp\roles.py", line 321, in document_link
    target, tooltip = provider.resolve_link(
  File "venv\lib\site-packages\esbonio\lsp\sphinx\domains.py", line 88, in resolve_link
    return self.resolve_intersphinx(name, domain, label)
  File "venv\lib\site-packages\esbonio\lsp\sphinx\domains.py", line 198, in resolve_intersphinx
    project, label = label.split(":")
ValueError: too many values to unpack (expected 2)
[Error - 9:12:52 PM] Request textDocument/documentLink failed.
  Message: ValueError: too many values to unpack (expected 2)
  Code: -32602 

I did a little bit of inspection on what's going on and it appears that if the label contains multiple colons, MyClass::MyFunc, it fails the split in domains.py. Not sure what the right fix is as it appears to be related to intersphinx link resolution. Perhaps the label is the wrong thing to split in this context and it's meant to be the domain or name instead? In my case, name is texpr and domain is cpp. I've never used any intersphinx links, so I'm not sure how the label plays a role in those kinds of references. Maybe esbonio can just inspect the domain before interpreting as a link?

  • python: 3.9.11
  • esbonio: 0.11.0
  • reStructuredText: 187.0.0
  • vscode: 1.66.2

Thanks for investigating, it definitiely helps! 😄

Intersphinx references generally look something like :ref:`project:thing-to-reference` with project:thing-to-reference becoming the value of label.

The intersphinx logic will need to be enhanced to handle the :: found in cpp references

commented

I've updated to 0.11.1 and wanted to verify that it's working on my end. Thanks for the quick fix!

Call it a coincidence 😄 I got the same error today.

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pygls/protocol.py", line 331, in _handle_request
self._execute_request(msg_id, handler, params)
File "/usr/local/lib/python3.8/dist-packages/pygls/protocol.py", line 260, in _execute_request
method_name, method_type, msg_id, handler(params))
File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/init.py", line 275, in on_document_link
links += feature.document_link(context) or []
File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/roles.py", line 321, in document_link
target, tooltip = provider.resolve_link(
File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/sphinx/domains.py", line 88, in resolve_link
return self.resolve_intersphinx(name, domain, label)
File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/sphinx/domains.py", line 198, in resolve_intersphinx
project, label = label.split(":")
ValueError: too many values to unpack (expected 2)
[Error - 17:50:25] Request textDocument/documentLink failed.
Message: ValueError: too many values to unpack (expected 2)
Code: -32602
{'traceback': [' File "/usr/local/lib/python3.8/dist-packages/pygls/protocol.py", line 331, in _handle_request\n self._execute_request(msg_id, handler, params)\n', ' File "/usr/local/lib/python3.8/dist-packages/pygls/protocol.py", line 260, in _execute_request\n method_name, method_type, msg_id, handler(params))\n', ' File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/init.py", line 275, in on_document_link\n links += feature.document_link(context) or []\n', ' File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/roles.py", line 321, in document_link\n target, tooltip = provider.resolve_link(\n', ' File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/sphinx/domains.py", line 88, in resolve_link\n return self.resolve_intersphinx(name, domain, label)\n', ' File "/usr/local/lib/python3.8/dist-packages/esbonio/lsp/sphinx/domains.py", line 198, in resolve_intersphinx\n project, label = label.split(":")\n']}

I am using doxylink and with it I will have the following syntax in rst.

:project:`namespace::class`

With 0.11.1 it works fine. Thanks for the quick fix!