From df58b81222c7b7b21808b301369cc699be2ec93b Mon Sep 17 00:00:00 2001 From: Alex Carney Date: Mon, 21 Oct 2024 20:41:54 +0100 Subject: [PATCH] lsp: Fix `${defaultBuildDir}` variable expansion --- lib/esbonio/changes/918.fix.md | 2 ++ lib/esbonio/esbonio/sphinx_agent/config.py | 2 +- .../tests/sphinx-agent/test_sa_unit.py | 31 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lib/esbonio/changes/918.fix.md diff --git a/lib/esbonio/changes/918.fix.md b/lib/esbonio/changes/918.fix.md new file mode 100644 index 000000000..d22178279 --- /dev/null +++ b/lib/esbonio/changes/918.fix.md @@ -0,0 +1,2 @@ +The language server no longer escapes `.` characters in filepaths when expanding the `${defaultBuildDir}` variable +resulting in weird filepaths diff --git a/lib/esbonio/esbonio/sphinx_agent/config.py b/lib/esbonio/esbonio/sphinx_agent/config.py index 687c4f3ed..a65a64bba 100644 --- a/lib/esbonio/esbonio/sphinx_agent/config.py +++ b/lib/esbonio/esbonio/sphinx_agent/config.py @@ -165,7 +165,7 @@ def to_application_args(self, context: dict[str, Any]) -> dict[str, Any]: continue replacement = self.resolve_config_variable(match.group(1), context) - result = VARIABLE.sub(re.escape(replacement), value) + result = VARIABLE.sub(replacement.replace("\\", r"\\"), value) setattr(self, name, result) diff --git a/lib/esbonio/tests/sphinx-agent/test_sa_unit.py b/lib/esbonio/tests/sphinx-agent/test_sa_unit.py index 7d965ce2a..fec13ea9e 100644 --- a/lib/esbonio/tests/sphinx-agent/test_sa_unit.py +++ b/lib/esbonio/tests/sphinx-agent/test_sa_unit.py @@ -473,6 +473,21 @@ def test_cli_arg_handling(args: list[str], expected: dict[str, Any]): "cacheDir": os.sep + os.sep.join(["path", "to", "cache"]), }, ), + ( + ["-M", "html", "src", "${defaultBuildDir}"], + application_args( + srcdir="src", + confdir="src", + outdir=os.sep + os.path.join("path", "to", ".cache", "", "html"), + doctreedir=( + os.sep + os.path.join("path", "to", ".cache", "", "doctrees") + ), + buildername="html", + ), + { + "cacheDir": os.sep + os.sep.join(["path", "to", ".cache"]), + }, + ), ( ["-b", "html", "src", "${defaultBuildDir}"], application_args( @@ -488,6 +503,22 @@ def test_cli_arg_handling(args: list[str], expected: dict[str, Any]): "cacheDir": os.sep + os.sep.join(["path", "to", "cache"]), }, ), + ( + ["-b", "html", "src", "${defaultBuildDir}"], + application_args( + srcdir="src", + confdir="src", + outdir=os.sep + os.sep.join(["path", "to", ".cache", ""]), + doctreedir=( + os.sep + + os.path.join("path", "to", ".cache", r"", ".doctrees") + ), + buildername="html", + ), + { + "cacheDir": os.sep + os.sep.join(["path", "to", ".cache"]), + }, + ), ], ) def test_cli_default_build_dir(