Skip to content

Commit 89bac4b

Browse files
committed
lsp: Re-organise configuration options
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.
1 parent e10c565 commit 89bac4b

File tree

5 files changed

+308
-280
lines changed

5 files changed

+308
-280
lines changed

lib/esbonio/esbonio/server/features/sphinx_manager/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .client import SphinxClient
88
from .client_subprocess import make_subprocess_sphinx_client
99
from .config import SphinxConfig
10+
from .config import SubProcess
1011
from .manager import RestartSphinxParams
1112
from .manager import SphinxManager
1213

@@ -15,6 +16,7 @@
1516
"SphinxClient",
1617
"SphinxConfig",
1718
"SphinxManager",
19+
"SubProcess",
1820
]
1921

2022

lib/esbonio/esbonio/server/features/sphinx_manager/client_subprocess.py

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
import asyncio
66
import logging
7-
import os
87
import pathlib
9-
import subprocess
108
import sys
119
import typing
1210
from uuid import uuid4
@@ -80,10 +78,10 @@ def __init__(
8078
self._events = EventSource(self.logger)
8179
"""The sphinx client can emit events."""
8280

83-
self._startup_task: asyncio.Task | None = None
81+
self._startup_task: asyncio.Task[Any] | None = None
8482
"""The startup task."""
8583

86-
self._stderr_forwarder: asyncio.Task | None = None
84+
self._stderr_forwarder: asyncio.Task[Any] | None = None
8785
"""A task that forwards the server's stderr to the test process."""
8886

8987
def __repr__(self):
@@ -204,11 +202,10 @@ async def start(self) -> SphinxClient:
204202

205203
try:
206204
self._set_state(ClientState.Starting)
207-
command = get_start_command(self.config, self.logger)
208-
env = get_sphinx_env(self.config)
205+
sphinx = self.config.sphinx_command
209206

210-
self.logger.debug("Starting sphinx agent: %s", " ".join(command))
211-
await self.start_io(*command, env=env, cwd=self.config.cwd)
207+
self.logger.debug("Python command: %r", sphinx.command)
208+
await self.start_io(*sphinx.command, env=sphinx.env, cwd=sphinx.cwd)
212209

213210
params = types.CreateApplicationParams(
214211
command=self.config.build_command,
@@ -337,49 +334,3 @@ def _on_progress(params):
337334
logger.info("%s", params)
338335

339336
return client
340-
341-
342-
def get_sphinx_env(config: SphinxConfig) -> dict[str, str]:
343-
"""Return the set of environment variables to use with the Sphinx process."""
344-
345-
env = {
346-
"PYTHONUNBUFFERED": "1",
347-
"PYTHONPATH": os.pathsep.join([str(p) for p in config.python_path]),
348-
}
349-
for envname, value in os.environ.items():
350-
# Don't pass any vars we've explictly set.
351-
if envname in env:
352-
continue
353-
354-
env[envname] = value
355-
356-
return env
357-
358-
359-
def get_start_command(config: SphinxConfig, logger: logging.Logger):
360-
"""Return the command to use to start the sphinx agent."""
361-
362-
command = []
363-
364-
if len(config.python_command) == 0:
365-
raise ValueError("No python environment configured")
366-
367-
if config.enable_dev_tools:
368-
# Assumes that the user has `lsp-devtools` available on their PATH
369-
# TODO: Windows support
370-
result = subprocess.run(
371-
["command", "-v", "lsp-devtools"], # noqa: S607
372-
capture_output=True,
373-
check=False,
374-
)
375-
376-
if result.returncode == 0:
377-
lsp_devtools = result.stdout.decode("utf8").strip()
378-
command.extend([lsp_devtools, "agent", "--"])
379-
380-
else:
381-
stderr = result.stderr.decode("utf8").strip()
382-
logger.debug("Unable to locate lsp-devtools command\n%s", stderr)
383-
384-
command.extend([*config.python_command, "-m", "sphinx_agent"])
385-
return command

0 commit comments

Comments
 (0)