Add lib directory to classpath - #98
Conversation
d645d16 to
68e4145
Compare
Replace GroovyLibCache with the same approach used by Nextflow: add the `lib` directory (and any JARs in it) to the compiler classpath. nf-lang already compiles Groovy sources found on the classpath on demand, so the language server no longer needs to compile the lib directory itself. Groovy source files are resolved against the lib directory on every lookup instead of through the classpath, so that new files (or the lib directory itself) are picked up without restarting the server. Name resolution is guarded against a Groovy class in the lib directory that fails to compile -- nf-lang propagates the compilation error, which would otherwise abort the analysis and leave the file with no diagnostics. Signed-off-by: Ben Sherman <bentshermann@gmail.com>
68e4145 to
1eb5c82
Compare
|
Two nf-lang fixes this approach wants, recorded here since they live in the 1. Hover (and go-to-definition, completion) on lib classes
if( resolveFromClassResolver(type.getName()) != null )
return true;The var cn = resolveFromClassResolver(type.getName());
if( cn != null ) {
type.setRedirect(cn);
return true;
}Verified locally against a patched 2. A lib class with a syntax error swallows the script's diagnostics
The script then reports nothing -- not even |
Simplify lib directory support by using the same approach as Nextflow -- add the
libdirectory (and any JARs in it) to the compiler classpath.GroovyLibCacheis removed; nf-lang'sResolveVisitoralready compiles Groovy sources found on the classpath on demand, so the language server doesn't need to compile the lib directory itself.Rebased on the current
main(the original commit predates the compiler module moving to nf-lang).The hang
The original attempt hung with no error output. The cause was
ResolveVisitor.resolveFromClassResolver, which threwGroovyBugErrorwhen the class resolver returned aSourceUnitinstead of aClassNode-- exactly what happens when a.groovyfile is found on the classpath.LanguageService.update()had no try/catch at the time, so the error propagated into the debounce executor, where a scheduled task's exception is captured in an unreadFutureand silently dropped. The update thread died on the first reference to a lib class, diagnostics were never published, and nothing was logged.Both halves are fixed upstream: nf-lang now compiles the source unit via
GroovyCompiler, andupdate0()catchesThrowable.Two rough edges handled here
GroovyCompiler.compile()letsCompilationFailedExceptionescape, so a lib class with a syntax error -- normal while editing -- aborted the whole analysis pass and left the script with no diagnostics. Name resolution is now guarded per file. Arguably better fixed in nf-lang.GroovyClassLoaderfixes its classpath at construction, so a lib directory created after startup was never seen. Groovy sources are now resolved against the lib directory on each lookup via aGroovyResourceLoader. New JARs still require a restart.ScriptLibDirTestcovers resolution by simple and fully-qualified name, type annotations, live edits to lib classes, a lib class with a syntax error, a missing lib directory, and no workspace root.