From d2ef0d73597167484bb972654ab4cbf593baaa2d Mon Sep 17 00:00:00 2001 From: Aviad Shiber Date: Sat, 11 Apr 2026 23:37:40 +0300 Subject: [PATCH] fix: module-scoped data-dir to avoid loading stale monorepo index When jdtls starts scoped to a single module, use the module URI for the data-dir hash instead of the workspace root. This prevents loading a 2.5GB cached index from previous full-workspace sessions, which caused the initialize request to time out at 120s. Each module now gets its own small data-dir (~10-50MB), enabling fast cold starts (~10s) for on-demand module loading. Co-Authored-By: Claude Opus 4.6 (1M context) --- pyproject.toml | 2 +- src/java_functional_lsp/__init__.py | 2 +- src/java_functional_lsp/proxy.py | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c227c35..b64976c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "java-functional-lsp" -version = "0.7.7" +version = "0.7.8" description = "Java LSP server enforcing functional programming best practices — null safety, immutability, no exceptions" readme = "README.md" license = { text = "MIT" } diff --git a/src/java_functional_lsp/__init__.py b/src/java_functional_lsp/__init__.py index a016239..799f65f 100644 --- a/src/java_functional_lsp/__init__.py +++ b/src/java_functional_lsp/__init__.py @@ -1,3 +1,3 @@ """java-functional-lsp: A Java LSP server enforcing functional programming best practices.""" -__version__ = "0.7.7" +__version__ = "0.7.8" diff --git a/src/java_functional_lsp/proxy.py b/src/java_functional_lsp/proxy.py index 828e549..8c7f5f0 100644 --- a/src/java_functional_lsp/proxy.py +++ b/src/java_functional_lsp/proxy.py @@ -484,18 +484,22 @@ async def start(self, init_params: dict[str, Any], *, module_root_uri: str | Non """Start jdtls subprocess and initialize it. If *module_root_uri* is provided, jdtls is scoped to that module for - fast startup. The data-directory hash is always based on the original - workspace root (from init_params) so the index persists across restarts. + fast startup and the data-dir hash is based on the module URI (so each + module gets its own isolated index). Otherwise the workspace root is used. """ jdtls_path = shutil.which("jdtls") if not jdtls_path: return False - # Data-dir hash based on original workspace root (stable across module changes). + # Data-dir hash: use module URI when scoped so each module gets its own + # clean jdtls state. This avoids loading a 2.5GB monorepo index when only + # one module is needed. Without expansion, each session is module-scoped, + # so the data-dir should match that scope. original_root: str = init_params.get("rootUri") or init_params.get("rootPath") or str(Path.cwd()) self._original_root_uri = original_root - workspace_hash = hashlib.sha256(original_root.encode()).hexdigest()[:12] - data_dir = Path.home() / ".cache" / "jdtls-data" / workspace_hash + hash_source = module_root_uri or original_root + data_hash = hashlib.sha256(hash_source.encode()).hexdigest()[:12] + data_dir = Path.home() / ".cache" / "jdtls-data" / data_hash data_dir.mkdir(parents=True, exist_ok=True) # Deep copy to avoid mutating server._init_params.