Skip to content

fix: import missing in-repo Maven modules so cross-group symbols resolve (#110) - #114

Merged
aviadshiber merged 3 commits into
mainfrom
fix/110-part-b-dependency-modules
Sep 29, 2026
Merged

aviadshiber merged 3 commits into
mainfrom
fix/110-part-b-dependency-modules

Conversation

@aviadshiber

Copy link
Copy Markdown
Owner

Stacked on #113 (PR A). Please review and merge #113 first; this PR's base is fix/110-part-a-scope-and-logging.

Why

jdtls imports only the Maven group of the opened file. When a module in that group depends on a reactor module in another group, m2e looks it up in the local repository at ${revision} (for example TABOOLA-DEFAULT-VERSION). That version is never published, so the module is missing, and every symbol from it becomes a false error: "cannot be resolved", "is undefined for the type", or "The hierarchy of the type X is inconsistent".

Spike S1 (real jdtls 1.61) showed two things:

  • When the missing module is added later as a workspace folder, jdtls fixes the dependent's classpath within about 0.1 s.
  • jdtls never republishes diagnostics for documents that are already open. A java.project.refreshDiagnostics call clears them.

Change

  • reactor.py builds the index that maps groupId:artifactId to a module directory. Only modules reachable through <modules> are included, with all profiles unioned.
    • Every module must resolve inside the reactor root. Symlinked poms are skipped, and symlink loops terminate.
    • Poms over 1 MB, or with <!DOCTYPE/<!ENTITY, are rejected before XML parsing.
    • groupId is inherited from <parent>. Coordinates containing ${ are skipped.
    • A GA declared by two directories is dropped and logged once. Aggregator poms are never resolved, so a pom-type dependency cannot pull in a whole group.
    • The walk stops at 5000 poms or 10 s. The index is built lazily, once per session, in an executor (single flight).
    • The same module parses m2e's [Offline / ]Missing artifact g:a:type[:classifier]:version.
  • dependency_modules.py reacts to Error diagnostics on a pom.xml. Each missing GA that is in the index and not yet covered by an imported folder becomes a candidate.
    • Candidates are batched into one didChangeWorkspaceFolders add, debounced 500 ms. Added modules report their own missing dependencies the same way, so rounds chain.
    • These folders live in their own registry, outside modules and _expanded_groups.
    • A session budget caps them: default 60, set by JAVA_FUNCTIONAL_LSP_DEPENDENCY_MODULES or jdtls.dependencyModules. 0 disables it, and values are clamped to 200. When the budget runs out, a WARNING lists the GAs left unresolved.
    • When a group expansion covers a dependency folder, that folder is removed in the same event and never re-added. Removal does not refund the budget.
  • Refresh. Two events trigger it: language/eventNotification with eventType 100 (ClasspathUpdated), and a pom.xml whose missing-artifact errors clear. The proxy then sends workspace/executeCommand java.project.refreshDiagnostics [uri, "thisFile", false] for each .java file the client has open under that project, debounced per project. The resulting publishes go through the Stale diagnostics lag behind edits (imports/signature changes report false errors until recompile) #109 hold unchanged.
  • Other changes. The version is now 0.14.0. The README gets a new section covering how it works, configuration, limits (budget, undetected stale local installs, Maven only, index bounds) and troubleshooting.

Testing

  • New e2e test (tests/test_e2e_dependency_modules.py) runs the real server and real jdtls.
    • The fixture has root/{groupA/common, groupB/it} with ${revision}. The client root is root, and jdtls is scoped to groupB.
    • The local repository is isolated: it holds only Maven's plugins, never com.example. It runs offline and is passed through settings.xml in initializationOptions.
    • The server process and jdtls get a temporary HOME and -Duser.home, so ~/.m2 and ~/.cache are never touched.
    • The test skips cleanly without jdtls, Java 21+, or Maven for the one-time priming.
  • Fail before, on PR A's head e75bb070:
    E   AssertionError: cross-group symbols still unresolved: ['The import com.example.common cannot be resolved', 'BaseIntegrationTest cannot be resolved to a type', 'The method cleanCaches() is undefined for the type MyIntegrationTest', 'sut cannot be resolved or is not a field']
    1 failed in 63.47s
    
  • Pass after: 1 passed in 4.07s. The proxy log from that run:
    jdtls: pom.xml errors changed for groupB/it/pom.xml: 1 error(s): Offline / Missing artifact com.example:common:jar:X-DEFAULT
    jdtls: reactor index of root: 5 modules from 5 poms
    jdtls: importing 1 dependency module(s) (1/60 used): com.example:common (groupA/common)
    jdtls: pom.xml errors changed for groupB/it/pom.xml: 0 error(s)
    jdtls: classpath of it updated, refreshing 1 open file(s)
    
    The e2e test guards the import path. In this run the module was added before jdtls's first semantic pass, so that first publish was already clean. The refresh did fire, as the last log line shows, but the e2e test does not assert it. The unit tests cover the refresh trigger.
  • New unit tests (tests/test_reactor.py, tests/test_dependency_modules.py) cover:
    • the index: malicious DOCTYPE/ENTITY poms, an oversized pom, symlinks pointing outside the root, a symlinked pom, a symlink loop, a module path escaping the root, duplicate GAs, profile modules, inherited and overridden groupId, aggregators, and the pom-count and time bounds;
    • the parser, with and without the prefix, plus test-jar coordinates;
    • the budget: env, config, clamping, and invalid values;
    • batching and single flight, dedupe with group expansion in both orders, never re-adding a folder, and the budget-exhaustion WARNING;
    • the refresh debounce and the open-file filter;
    • proxy wiring: eventNotification, pom diagnostics, the executeCommand payload, and group-event removal.
  • Gates: uv run ruff check ., uv run ruff format --check ., uv run mypy src, and uv run pytest -q all pass: 973 passed, 1 pre-existing skip, and the e2e tests ran against local jdtls.

Fixes #110

🤖 Generated with Claude Code

@aviadshiber
aviadshiber force-pushed the fix/110-part-b-dependency-modules branch from 02d8743 to 3a40ed3 Compare September 29, 2026 11:43
@aviadshiber
aviadshiber marked this pull request as ready for review September 29, 2026 13:07
aviadsTaboola and others added 3 commits September 29, 2026 17:42
…lve (#110)

jdtls imports only the opened file's Maven group. A dependency on a reactor
module in another group is resolved by m2e from the local repository at
${revision}, where it is usually missing, so every symbol from it is a false
"cannot be resolved" / "undefined for the type" error.

- reactor.py: GA -> module dir index of the modules reachable through
  <modules> (profiles unioned), contained in the reactor root, no symlinked
  poms, DOCTYPE/ENTITY and >1 MB poms rejected, inherited groupId,
  duplicate GAs dropped, bounded to 5000 poms / 10 s; "Missing artifact"
  parser (optional "Offline / " prefix).
- dependency_modules.py: on a pom.xml "Missing artifact" error for an
  in-repo, uncovered module, add its folder via one debounced, batched
  didChangeWorkspaceFolders; separate registry; session budget (default 60,
  JAVA_FUNCTIONAL_LSP_DEPENDENCY_MODULES or jdtls.dependencyModules, 0
  disables, max 200) with a WARNING listing unresolved GAs; a group
  expansion removes the dependency folders it covers in the same event and
  they are never re-added.
- On language/eventNotification 100 (ClasspathUpdated) or when a pom's
  missing-artifact errors clear, send java.project.refreshDiagnostics for
  each open .java file under that project (debounced per project); the
  results go through the #109 hold unchanged.
- e2e regression test on a two-group ${revision} reactor with an isolated,
  primed, offline local repository; it fails on PR A's head.
- Version 0.14.0; README section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A missing pom-type dependency on a group or the reactor root would add
its whole subtree as one folder, bypassing the group cap. The index now
records aggregators (poms with <modules>) and never resolves them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Compare dependency-module folders and imported/group folders resolved, so a
  client root reached through a symlink still retires and dedupes them.
- Keep flushing while candidates arrive during an in-flight send.
- Reject DOCTYPE/ENTITY declarations at the expat level too (UTF-16 poms), and
  tolerate poms in encodings expat refuses instead of aborting the index.
- Ignore coordinates outside Maven's character set, so no raw pom text is logged.
- Tests: symlinked-root cases, send race, UTF-16 poms, guard log assertions,
  positive controls for negative assertions, e2e log check of the import path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aviadshiber
aviadshiber force-pushed the fix/110-part-b-dependency-modules branch from 3a40ed3 to 1cc6880 Compare September 29, 2026 14:42
@aviadshiber
aviadshiber changed the base branch from fix/110-part-a-scope-and-logging to main September 29, 2026 14:42
@aviadshiber
aviadshiber merged commit 51177db into main Sep 29, 2026
14 checks passed
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.

False 'cannot be resolved' / 'hierarchy is inconsistent' for inherited symbols when a module is treated as a non-project file

2 participants