Skip to content

Conversation

@alcarney
Copy link
Member

Configuration changes

This PR removes the following options

  • esbonio.sphinx.envPassthrough: For ages now, the language server passes through all environment variables to the sphinx process so this option has no use.

  • esbonio.sphinx.pythonPath: I think the original intent behind this option was to allow you to override the version of the sphinx agent. However, the better way to do this is just use a different version of esbonio.

  • esbonio.sphinx.cwd: Use esbonio.sphinx.pythonCommand.cwd.

  • esbonio.sphinx.fallbackEnv: This was a hack to allow the VSCode extension to provide a default environment in the absence of any user configuration.

    From now on, clients should set esbonio.sphinx.pythonCommand in the initializationOptions they send.

This PR also converts esbonio.sphinx.pythonCommand from a simple list to an object in its own right.

  • esbonio.sphinx.pythonCommand.command: This list of strings from the original esbonio.sphinx.pythonCommand.
  • esbonio.sphinx.pythonCommand.env: A dictionary allowing you to add/override environment variables passed to the sphinx process. Closes Add ability to set envrionment variables for the sphinx process #469
  • esbonio.sphinx.pythonCommand.cwd: A string allowing you to change the directory in which the sphinx process is launched.

Now 95% of the time, the simple list of strings was sufficient so if the server is given a list of strings for esbonio.sphinx.pythonCommand it will be automatically converted to the object representation.

Behaviour changes

Rather than do nothing, assume the user knows what they are doing and
re-use the environment the language server itself is written in.
@alcarney alcarney force-pushed the reorg-sphinx-conf branch 3 times, most recently from 6fa098f to 0e4b4cf Compare September 12, 2025 13:26
This makes the server's initializationOptions the lowest priority
setting, allowing for them to be used as fallback options specified by
the client
This commit removes the following options

- ``esbonio.sphinx.envPassthrough``: For ages now, the language server
  passes through all environment variables to the sphinx process so
  this option has no use.

- ``esbonio.sphinx.pythonPath``: I think the original intent behind
  this option was to allow you to override the version of the sphinx
  agent.

  However, the better way to do this is just use a different version
  of ``esbonio``.

- ``esbonio.sphinx.cwd``: Use ``esbonio.sphinx.pythonCommand.cwd``.

- ``esbonio.sphinx.fallbackEnv``: This was a hack to allow the VSCode
  extension to provide a default environment in the absence of any
  user configuration.

  From now on, clients should set ``esbonio.sphinx.pythonCommand`` in
  the initializationOptions they send.

This commit also converts ``esbonio.sphinx.pythonCommand`` from a
simple list to an object in its own right.

  - ``esbonio.sphinx.pythonCommand.command``: This list of strings
    from the original ``esbonio.sphinx.pythonCommand.``

  - ``esbonio.sphinx.pythonCommand.env``: A dictionary allowing you to
    add/override environment variables passed to the sphinx process.

  - ``esbonio.sphinx.pythonCommand.cwd``: A string allowing you to
    change the directory in which the sphinx process is launched.

Now 95% of the time, the simple list of strings was sufficient so if
the server is given a list of strings for
``esbonio.sphinx.pythonCommand`` it will be automatically converted to
the object representation.
This batch of changes has unearthed a bunch of interesting timing issues
during server start up.

I was seeing an issue where the `esbonio.sphinx.pythonCommand`
configuration was not being applied *only* in the case where I had one
or more `*.rst` files open before restarting the server.

I eventually realised that this was due to the `textDocument/didOpen`
notification handlers winning the race with the `initialized`
notification handler and creating a `SphinxConfig` configuration
subscription **before** the additional structure hooks in the
`SphinxManager` could be registered.

This meant the promotion of `list[str]` values to `SubProcess` values
was not happening for these early subscriptions.

More broadly, this probably points to a need to reconsider the startup
sequence at some point, but running this code during `initialize`
(during which time other messages are forbidden) should be enough to
paper over the issue for now.
Related to the previous commit, the server was declaring itself ready
before all the `initialized` handlers of the features were processed.

This commit therefore attempts to be more correct by delaying the
resolution of the `ready` future until after the execution of these
handlers. However, the previous commit also demonstrates how this
already insufficient to ensure correct behaviour as other
requests/notifications are free to be serviced concurrently with
`initialized`.

The "obvious" fix for this would be to move all setup code into the
`initialize` handler, but there is at least one situation where this
cannot be done and that is the configuration system. Initializing the
configuration system involves making `workspace/configuration` requests
to the client - which are forbidden until after the `initialize` result
has been sent!

As I write this, perhaps the other "obvious" solution is to have all of
the message handlers in `esbonio/server/setup.py` consult the state of
the `ready` future before proceeding... but for some reason (I can't quite
articulate why) that doesn't feel like an ideal solution...
@alcarney alcarney marked this pull request as ready for review September 21, 2025 17:42
@alcarney alcarney force-pushed the reorg-sphinx-conf branch 12 times, most recently from 29bf5f3 to a353139 Compare September 21, 2025 19:25
@alcarney alcarney merged commit 3092eb2 into swyddfa:develop Sep 21, 2025
33 of 35 checks passed
@alcarney alcarney deleted the reorg-sphinx-conf branch September 21, 2025 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fallbackEnv outside of vscode Add ability to set envrionment variables for the sphinx process

1 participant