drccrd opened a new pull request, #4032:
URL: https://github.com/apache/incubator-kie-tools/pull/4032

   Closes: #4027 
   
   Saving a DRL file compiles its file group with the Drools engine on the 
project's own classpath and shows the compiler's errors in the editor.
   
   ### Behaviour
   
   - Trigger: `didSave`, skipped while the file has syntax errors; files that 
do not parse are left out of the compile wherever they sit. Scope: the file's 
group through the existing `WorkspaceSiblingResolver`; `DRL: Rebuild Workspace` 
(`drools/rebuildWorkspace`) compiles every DRL file the grouping layer knows 
(the client-enumerated workspace files, so `files.exclude` applies) and reports 
a start message and a summary that names the files with errors, also when it 
was skipped. One compile at a time; a save during a compile queues one more and 
the latest wins, a queued rebuild keeps its full scope, and a result whose 
buffer changed meanwhile is discarded.
   - Results are cached per file of the group and merged into the pull answer 
after the parser and lint diagnostics; the first edit of a file drops its 
result, so do a group change and `didClose`. Messages carry `source: drools`, 
the engine's line and column where present, and recovered ranges otherwise 
(quoted token, analysed expression, rule header). Follow-on messages that only 
restate an unresolved type are dropped when a root error is present.
   - A workspace without a usable engine gets no compile diagnostics and 
nothing else changes: the server needs `drools-compiler` and `drools-mvel` on 
the project classpath, the classic build's own requirement; `kie-api` alone, or 
`drools-engine` without `drools-mvel`, counts as no engine and is logged once. 
The compile also needs the project's own classes: a workspace with Java sources 
but no build output skips the compile and says so once, and a class still 
missing from the build is named in one warning on the saved file instead of the 
engine's generic "Rules compilation failed or interrupted". 
`drools.lsp.compile.onSave` (default on) turns the save trigger off; the 
command still works. It applies without a restart, pulled with the formatter 
options through `workspace/configuration`.
   - The server now advertises `TextDocumentSyncOptions` with save 
notifications instead of the bare `Full` kind, and the engine follows the 
classpath: it is rebuilt when the class index is, picking up `target/classes` 
directories created after startup.
   
   ### Notes for review
   
   - The server gains no engine dependency. A new module 
`drools-lsp-engine-bridge` is compiled against `kie-api` at provided scope and 
packaged into the server jar; at runtime its classes are defined inside a class 
loader whose parent is a `URLClassLoader` over the project's resolved classpath 
with the platform loader as parent. The server's own loader is deliberately not 
in that chain: it carries a `drools-drl-parser` and an ANTLR runtime for the 
editor features, and the project's must win inside the engine. Each build runs 
on a fresh thread so MVEL's thread-locals cannot pin a replaced loader; the 
previous loader is closed after the build in flight finishes; an engine that 
turns out unavailable closes its loader at once. The server jar stays at 7.8 MB.
   - Diagnostics come from the engine version the project uses; two machines 
with two engine versions may report differently, by design.
   - `WorkspaceSiblingResolver` gains a default `workspaceDrlFiles()` so the 
rebuild compiles the grouping layer's file set rather than walking the disk; 
the shipped resolver answers from the scan it already holds.
   - Tests run against the engine kie-tools pins for its own build, in test 
scope only: `drools-compiler`, `drools-mvel` and `drools-io`, the last named 
explicitly because `drools-completion` excludes it from its parser dependency 
and Maven keeps that pruned path for the test tree.
   
   ### Follow-ups, not attempted
   
   - The executable-model build: a project on `drools-engine` without 
`drools-mvel` gets no compile diagnostics today; 
`buildAll(ExecutableModelProject.class)` from the bridge would give those 
projects the compiler they use. Left out because it changes which compiler's 
messages users see.
   - `workspace/diagnostic` support, so a rebuild's errors in files that are 
not open reach the Problems panel instead of only the summary.
   - The engine loader is rebuilt whenever the class index is (after a Maven 
build or a `.java` edit), so the first save after such a change pays the engine 
warm-up again; a finer trigger is possible if that shows in practice.
   - The same typo can be reported by the unknown-type lint and by the engine; 
suppressing the engine's type-resolution message when a lint diagnostic covers 
the same range is a small follow-up.
   - A worker JVM instead of the in-process loader, if memory becomes a problem 
on large projects; the bridge serves both.
   
   Co-authored by [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to