Skip to content

Commit 337b9a5

Browse files
committed
Use only currently loaded plugins when resolving script includes
1 parent 4f3848a commit 337b9a5

4 files changed

Lines changed: 61 additions & 10 deletions

File tree

src/main/java/nextflow/lsp/services/config/ConfigSpecVisitor.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import nextflow.config.ast.ConfigVisitorSupport;
2828
import nextflow.config.spec.SpecNode;
2929
import nextflow.lsp.spec.ConfigSpecFactory;
30+
import nextflow.lsp.spec.PluginRef;
3031
import nextflow.lsp.spec.PluginSpecCache;
3132
import nextflow.script.control.PhaseAware;
3233
import nextflow.script.control.Phases;
@@ -94,8 +95,8 @@ private SpecNode.Scope getPluginScopes(ConfigNode cn) {
9495
}
9596

9697
private Map<String, SpecNode> pluginConfigScopes(ConfigNode cn) {
97-
var entries = cn.getConfigStatements().stream()
98-
// get plugin refs from `plugins` block
98+
// get plugin refs from `plugins` block
99+
var refs = cn.getConfigStatements().stream()
99100
.map(stmt ->
100101
stmt instanceof ConfigApplyBlockNode node && "plugins".equals(node.name) ? node : null
101102
)
@@ -106,18 +107,26 @@ private Map<String, SpecNode> pluginConfigScopes(ConfigNode cn) {
106107
var firstArg = arguments.get(0);
107108
return firstArg instanceof ConstantExpression ce ? ce.getText() : null;
108109
})
109-
// fetch plugin specs from plugin registry
110110
.filter(ref -> ref != null)
111111
.map((ref) -> {
112112
var tokens = ref.split("@");
113113
var name = tokens[0];
114114
var version = tokens.length == 2 ? tokens[1] : null;
115-
return pluginSpecCache.get(name, version);
115+
return new PluginRef(name, version);
116116
})
117+
.toList();
118+
119+
// fetch plugin specs from plugin registry
120+
var entries = refs.stream()
121+
.map((ref) -> pluginSpecCache.get(ref.name(), ref.version()))
117122
.filter(spec -> spec != null)
118123
.map(spec -> spec.configScopes())
119124
.toList();
120125

126+
// set current versions in plugin spec cache
127+
pluginSpecCache.setCurrentVersions(refs);
128+
129+
// collect config scopes from plugin specs
121130
var result = new HashMap<String, SpecNode>();
122131
for( var entry : entries )
123132
result.putAll(entry);

src/main/java/nextflow/lsp/services/script/ResolvePluginIncludeVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void visitInclude(IncludeNode node) {
6262
if( !source.startsWith("plugin/") )
6363
return;
6464
var pluginName = source.split("/")[1];
65-
var spec = pluginSpecCache.get(pluginName, null);
65+
var spec = pluginSpecCache.getCurrent(pluginName);
6666
if( spec == null ) {
6767
addError("Plugin '" + pluginName + "' does not exist or is not specified in the configuration file", node);
6868
return;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2024-2025, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nextflow.lsp.spec;
17+
18+
public record PluginRef(
19+
String name,
20+
String version
21+
) {}

src/main/java/nextflow/lsp/spec/PluginSpecCache.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class PluginSpecCache {
4444

4545
private Map<PluginRef, PluginSpec> cache = new HashMap<>();
4646

47+
private List<PluginRef> currentVersions;
48+
4749
public PluginSpecCache(String registryUrl) {
4850
this.registryUri = URI.create(registryUrl);
4951
}
@@ -138,10 +140,29 @@ private static PluginSpec pluginSpec(Map release) {
138140
);
139141
}
140142

141-
}
143+
/**
144+
* Set the plugin versions currently specified by the config.
145+
*
146+
* @param currentVersions
147+
*/
148+
public void setCurrentVersions(List<PluginRef> currentVersions) {
149+
this.currentVersions = currentVersions;
150+
}
142151

152+
/**
153+
* Get the currently loaded spec for a plugin.
154+
*
155+
* @param name
156+
*/
157+
public PluginSpec getCurrent(String name) {
158+
if( currentVersions == null )
159+
return null;
160+
var ref = currentVersions.stream()
161+
.filter(r -> r.name().equals(name))
162+
.findFirst().orElse(null);
163+
if( ref == null )
164+
return null;
165+
return cache.get(ref);
166+
}
143167

144-
record PluginRef(
145-
String name,
146-
String version
147-
) {}
168+
}

0 commit comments

Comments
 (0)