diff --git a/docs/source/settings.rst b/docs/source/settings.rst index 6d7f83f..e0b544a 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -18,7 +18,9 @@ Settings .. py:data:: lua_ls_backend :type: str - Controls which lua analyzer is used. Can be either ``"emmylua"`` or ``"luals"``. + Controls which lua analyzer is used. Can be either ``"emmylua"``, ``"luals"``, or ``"disable"``. + When set to ``"disable"``, no Lua files are analyzed, all language server related settings + are ignored, and :doc:`autodoc` does not work. .. py:data:: lua_ls_auto_install :type: bool diff --git a/sphinx_lua_ls/__init__.py b/sphinx_lua_ls/__init__.py index 390682f..5ba45de 100644 --- a/sphinx_lua_ls/__init__.py +++ b/sphinx_lua_ls/__init__.py @@ -33,6 +33,9 @@ def run_lua_ls(app: sphinx.application.Sphinx): domain: sphinx_lua_ls.domain.LuaDomain = app.env.get_domain("lua") # type: ignore + if domain.config.backend == "disable": + return + root_dir = domain.config.project_root project_directories = domain.config.project_directories if project_directories is None: @@ -130,6 +133,12 @@ def run_apidoc( app: sphinx.application.Sphinx, ): domain = _t.cast(sphinx_lua_ls.domain.LuaDomain, app.env.get_domain("lua")) + if domain.config.backend == "disable": + logger.warning( + "apidoc requested, but the language server backend is disabled", + type="lua-ls", + ) + return cwd = pathlib.Path.cwd() for name, params in domain.config.apidoc_roots.items(): try: diff --git a/sphinx_lua_ls/autodoc.py b/sphinx_lua_ls/autodoc.py index 3aef9eb..2d50240 100644 --- a/sphinx_lua_ls/autodoc.py +++ b/sphinx_lua_ls/autodoc.py @@ -1069,6 +1069,10 @@ class AutoObjectDirective(AutodocUtilsMixin): doctype_override: str | None = None def run(self): + if self.lua_domain.config.backend == "disable": + raise self.error( + "autoobject requested but the Lua language server is disabled" + ) self.prepare_options() signatures: list[str] = [] diff --git a/sphinx_lua_ls/config.py b/sphinx_lua_ls/config.py index 9af1d77..a072c1b 100644 --- a/sphinx_lua_ls/config.py +++ b/sphinx_lua_ls/config.py @@ -20,7 +20,7 @@ @dataclass class LuaDomainConfig: project_root: pathlib.Path - backend: _t.Literal["emmylua", "luals"] = "luals" + backend: _t.Literal["emmylua", "luals", "disable"] = "luals" project_directories: list[pathlib.Path] | None = None auto_install: bool = True auto_install_location: pathlib.Path | None = None @@ -188,9 +188,11 @@ def set_options(app: sphinx.application.Sphinx): if config["lua_ls_backend"] is not None: domain_config.backend = _t.cast( - _t.Literal["emmylua", "luals"], + _t.Literal["emmylua", "luals", "disable"], _str_choices( - "lua_ls_backend", config["lua_ls_backend"], ["luals", "emmylua"] + "lua_ls_backend", + config["lua_ls_backend"], + ["luals", "emmylua", "disable"], ), ) else: