swyddfa / esbonio

A language server for working with Sphinx projects.
https://docs.esbon.io/
124 stars 21 forks source link

Preview loses position on each save #440

Closed alcarney closed 5 months ago

alcarney commented 1 year ago

As raised in #425

alcarney commented 1 year ago

This seems to be due to limitations in <iframe> elements.

iframes seem to cache their content quite aggressively and as far as I can tell the only way to get them to reload reliably from "outside" is to modify the url - which forces the browser to start from scratch, losing the place on the page.

To fix this, I think the preview server is going to have to get smarter so we can trigger reloads from "inside" the iframe

alcarney commented 5 months ago

I believe this is now resolved in the pre-release version (v0.91.0+)

davbeek commented 5 months ago

When I open esbonio in the normal release version, everything works fine. When I switch to the pre-release version, I get, see below. I am on Python 3.12, sphinx 7.2.6, esbonio 0.92.1. Sorry about the long output, don't have time to properly hide it under a button as this is a very busy period for me. Restarting VSCode or switching to other files does not help. I only obscured my username in the output.

Settings:

    "esbonio.server.enabled": true,
    // "esbonio.server.logLevel": "debug",
    // "esbonio.server.logLevel": "error",
    "esbonio.server.logLevel": "info",
    "esbonio.sphinx.buildCommand": [
        "sphinx-build",
        "-M",
        "html",
        ".",
        "_build"
    ],
[client] Starting Language Server
[esbonio] Initialising esbonio v1.0.0b1
[esbonio] Language client: Visual Studio Code 1.86.2
Running Sphinx v7.2.6
Unable to deserialize message
  + Exception Group Traceback (most recent call last):
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 335, in _deserialize_message
  |     return self._converter.structure(data, response_type)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/cattrs/converters.py", line 332, in structure
  |     return self._structure_func.dispatch(cl)(obj, cl)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse>", line 20, in structure_CreateApplicationResponse
  |     if errors: raise __c_cve('While structuring ' + 'CreateApplicationResponse', errors, __cl)
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | cattrs.errors.ClassValidationError: While structuring CreateApplicationResponse (1 sub-exception)
  +-+---------------- 1 ----------------
    | Exception Group Traceback (most recent call last):
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse>", line 10, in structure_CreateApplicationResponse
    |     res['result'] = __c_structure_result(o['result'], __c_type_result)
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo>", line 39, in structure_SphinxInfo
    |     if errors: raise __c_cve('While structuring ' + 'SphinxInfo', errors, __cl)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | cattrs.errors.ClassValidationError: While structuring SphinxInfo (1 sub-exception)
    | Structuring class CreateApplicationResponse @ attribute result
    +-+---------------- 1 ----------------
      | Traceback (most recent call last):
      |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo>", line 35, in structure_SphinxInfo
      |     res['dbpath'] = __c_structure_dbpath(o['dbpath'])
      |                                           ~^^^^^^^^^^
      | KeyError: 'dbpath'
      | Structuring class SphinxInfo @ attribute dbpath
      +------------------------------------

Error receiving data
  + Exception Group Traceback (most recent call last):
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 335, in _deserialize_message
  |     return self._converter.structure(data, response_type)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/cattrs/converters.py", line 332, in structure
  |     return self._structure_func.dispatch(cl)(obj, cl)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse>", line 20, in structure_CreateApplicationResponse
  |     if errors: raise __c_cve('While structuring ' + 'CreateApplicationResponse', errors, __cl)
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | cattrs.errors.ClassValidationError: While structuring CreateApplicationResponse (1 sub-exception)
  +-+---------------- 1 ----------------
    | Exception Group Traceback (most recent call last):
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse>", line 10, in structure_CreateApplicationResponse
    |     res['result'] = __c_structure_result(o['result'], __c_type_result)
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo>", line 39, in structure_SphinxInfo
    |     if errors: raise __c_cve('While structuring ' + 'SphinxInfo', errors, __cl)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | cattrs.errors.ClassValidationError: While structuring SphinxInfo (1 sub-exception)
    | Structuring class CreateApplicationResponse @ attribute result
    +-+---------------- 1 ----------------
      | Traceback (most recent call last):
      |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo>", line 35, in structure_SphinxInfo
      |     res['dbpath'] = __c_structure_dbpath(o['dbpath'])
      |                                           ~^^^^^^^^^^
      | KeyError: 'dbpath'
      | Structuring class SphinxInfo @ attribute dbpath
      +------------------------------------

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 443, in data_received
    self._data_received(data)
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 475, in _data_received
    json.loads(
  File "/Users/xxxxxx/miniconda3/lib/python3.12/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/miniconda3/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/miniconda3/lib/python3.12/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 344, in _deserialize_message
    raise JsonRpcInvalidParams() from exc
pygls.exceptions.JsonRpcInvalidParams: Invalid Params
loading pickled environment...
done
Exception in callback JsonRPCProtocol._execute_notification_callback(<Task cancell...anager.py:80>>)
handle: <Handle JsonRPCProtocol._execute_notification_callback(<Task cancell...anager.py:80>>)>
Traceback (most recent call last):
  File "/Users/xxxxxx/miniconda3/lib/python3.12/asyncio/events.py", line 84, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 157, in _execute_notification_callback
    if future.exception():
       ^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/feature_manager.py", line 81, in wrapped
    return await f(server, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/esbonio/server/setup.py", line 76, in on_document_open
    await call_features(ls, "document_open", params)
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/esbonio/server/setup.py", line 257, in call_features
    await result
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/esbonio/server/features/sphinx_manager/manager.py", line 73, in document_open
    await self.get_client(uri)
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/esbonio/server/features/sphinx_manager/manager.py", line 164, in get_client
    return await self._client_creating
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/esbonio/server/features/sphinx_manager/manager.py", line 195, in _create_client
    sphinx_info = await client.create_application(resolved)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/esbonio/server/features/sphinx_manager/client_subprocess.py", line 188, in create_application
    sphinx_info = await self.protocol.send_request_async("sphinx/createApp", params)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError
Running Sphinx v7.2.6
loading pickled environment...
done
Unable to deserialize message
  + Exception Group Traceback (most recent call last):
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 335, in _deserialize_message
  |     return self._converter.structure(data, response_type)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/cattrs/converters.py", line 332, in structure
  |     return self._structure_func.dispatch(cl)(obj, cl)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse-2>", line 20, in structure_CreateApplicationResponse
  |     if errors: raise __c_cve('While structuring ' + 'CreateApplicationResponse', errors, __cl)
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | cattrs.errors.ClassValidationError: While structuring CreateApplicationResponse (1 sub-exception)
  +-+---------------- 1 ----------------
    | Exception Group Traceback (most recent call last):
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse-2>", line 10, in structure_CreateApplicationResponse
    |     res['result'] = __c_structure_result(o['result'], __c_type_result)
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo-2>", line 39, in structure_SphinxInfo
    |     if errors: raise __c_cve('While structuring ' + 'SphinxInfo', errors, __cl)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | cattrs.errors.ClassValidationError: While structuring SphinxInfo (1 sub-exception)
    | Structuring class CreateApplicationResponse @ attribute result
    +-+---------------- 1 ----------------
      | Traceback (most recent call last):
      |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo-2>", line 35, in structure_SphinxInfo
      |     res['dbpath'] = __c_structure_dbpath(o['dbpath'])
      |                                           ~^^^^^^^^^^
      | KeyError: 'dbpath'
      | Structuring class SphinxInfo @ attribute dbpath
      +------------------------------------

Error receiving data
  + Exception Group Traceback (most recent call last):
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 335, in _deserialize_message
  |     return self._converter.structure(data, response_type)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/cattrs/converters.py", line 332, in structure
  |     return self._structure_func.dispatch(cl)(obj, cl)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse-2>", line 20, in structure_CreateApplicationResponse
  |     if errors: raise __c_cve('While structuring ' + 'CreateApplicationResponse', errors, __cl)
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  | cattrs.errors.ClassValidationError: While structuring CreateApplicationResponse (1 sub-exception)
  +-+---------------- 1 ----------------
    | Exception Group Traceback (most recent call last):
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.CreateApplicationResponse-2>", line 10, in structure_CreateApplicationResponse
    |     res['result'] = __c_structure_result(o['result'], __c_type_result)
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo-2>", line 39, in structure_SphinxInfo
    |     if errors: raise __c_cve('While structuring ' + 'SphinxInfo', errors, __cl)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | cattrs.errors.ClassValidationError: While structuring SphinxInfo (1 sub-exception)
    | Structuring class CreateApplicationResponse @ attribute result
    +-+---------------- 1 ----------------
      | Traceback (most recent call last):
      |   File "<cattrs generated structure esbonio.sphinx_agent.types.SphinxInfo-2>", line 35, in structure_SphinxInfo
      |     res['dbpath'] = __c_structure_dbpath(o['dbpath'])
      |                                           ~^^^^^^^^^^
      | KeyError: 'dbpath'
      | Structuring class SphinxInfo @ attribute dbpath
      +------------------------------------

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 443, in data_received
    self._data_received(data)
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 475, in _data_received
    json.loads(
  File "/Users/xxxxxx/miniconda3/lib/python3.12/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/miniconda3/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/miniconda3/lib/python3.12/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxxxxx/.vscode/extensions/swyddfa.esbonio-0.92.1/bundled/libs/pygls/protocol/json_rpc.py", line 344, in _deserialize_message
    raise JsonRpcInvalidParams() from exc
pygls.exceptions.JsonRpcInvalidParams: Invalid Params
alcarney commented 5 months ago

No worries, thanks for taking the time to report this!

It looks like the Sphinx process isn't sending all the info the server is looking for... though I can't think why that might be, will have to investigate!