diff --git a/modules/compiler/src/main/java/script/control/ResolveVisitor.java b/modules/compiler/src/main/java/script/control/ResolveVisitor.java index 1ac6747..8dd2ca2 100644 --- a/modules/compiler/src/main/java/script/control/ResolveVisitor.java +++ b/modules/compiler/src/main/java/script/control/ResolveVisitor.java @@ -139,6 +139,8 @@ protected boolean resolve(ClassNode type) { return true; if( resolveFromModule(type) ) return true; + if( resolveFromLibImports(type) ) + return true; if( !type.hasPackageName() && resolveFromDefaultImports(type) ) return true; return resolveFromClassResolver(type.getName()) != null; @@ -178,18 +180,22 @@ protected boolean resolveFromModule(ClassNode type) { return false; } - protected boolean resolveFromDefaultImports(ClassNode type) { - // resolve from script imports - var typeName = type.getName(); - for( var cn : Types.TYPES ) { - if( typeName.equals(cn.getNameWithoutPackage()) || typeName.equals(cn.getName()) ) { + protected boolean resolveFromLibImports(ClassNode type) { + var name = type.getName(); + for( var cn : libClasses ) { + if( name.equals(cn.getName()) ) { type.setRedirect(cn); return true; } } - // resolve from lib directory - for( var cn : libClasses ) { - if( typeName.equals(cn.getNameWithoutPackage()) || typeName.equals(cn.getName()) ) { + return false; + } + + protected boolean resolveFromDefaultImports(ClassNode type) { + // resolve from script imports + var typeName = type.getName(); + for( var cn : Types.TYPES ) { + if( typeName.equals(cn.getNameWithoutPackage()) ) { type.setRedirect(cn); return true; } diff --git a/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptAstCache.java b/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptAstCache.java index d7c75cb..e3346d4 100644 --- a/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptAstCache.java +++ b/modules/language-server/src/main/java/nextflow/lsp/services/script/ScriptAstCache.java @@ -205,6 +205,17 @@ private List getLibClasses() { var moduleNode = sourceUnit.getAST(); if( moduleNode == null ) return; + var packageName = libDir + .relativize(Path.of(uri).getParent()) + .toString() + .replaceAll("/", "."); + moduleNode.setPackageName(packageName); + for( var cn : moduleNode.getClasses() ) { + var className = packageName.isEmpty() + ? cn.getNameWithoutPackage() + : packageName + "." + cn.getNameWithoutPackage(); + cn.setName(className); + } result.addAll(moduleNode.getClasses()); var entry = libCache.get(uri);