Skip to content

Commit 15df9df

Browse files
committed
Fix hover hint for namespace functions
1 parent e2723c3 commit 15df9df

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/main/java/nextflow/lsp/ast/ASTNodeStringUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import nextflow.script.dsl.Description;
3030
import nextflow.script.dsl.DslScope;
3131
import nextflow.script.dsl.FeatureFlag;
32+
import nextflow.script.dsl.Namespace;
3233
import nextflow.script.dsl.Operator;
3334
import nextflow.script.dsl.OutputDsl;
3435
import nextflow.script.dsl.ProcessDsl;
@@ -199,11 +200,7 @@ private static String methodToLabel(MethodNode node) {
199200
if( node instanceof FunctionNode ) {
200201
builder.append("def ");
201202
}
202-
else if( node.isStatic() ) {
203-
builder.append(Types.getName(node.getDeclaringClass()));
204-
builder.append('.');
205-
}
206-
else if( Logger.isDebugEnabled() || !isDslFunction(node) ) {
203+
else if( Logger.isDebugEnabled() || (!isDslFunction(node) && !isNamespaceFunction(node)) ) {
207204
builder.append(Types.getName(node.getDeclaringClass()));
208205
builder.append(' ');
209206
}
@@ -222,6 +219,10 @@ private static boolean isDslFunction(MethodNode mn) {
222219
return mn.getDeclaringClass().implementsInterface(ClassHelper.makeCached(DslScope.class));
223220
}
224221

222+
private static boolean isNamespaceFunction(MethodNode mn) {
223+
return mn.getDeclaringClass().implementsInterface(ClassHelper.makeCached(Namespace.class));
224+
}
225+
225226
private static String methodTypeLabel(MethodNode mn) {
226227
if( mn instanceof FunctionNode )
227228
return null;

src/test/groovy/nextflow/lsp/ast/ASTNodeStringUtilsTest.groovy

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import nextflow.script.ast.ProcessNode
2323
import nextflow.script.ast.WorkflowNode
2424
import nextflow.script.dsl.FeatureFlagDsl
2525
import nextflow.script.dsl.ProcessDsl
26-
import nextflow.script.types.Channel
26+
import nextflow.script.dsl.ScriptDsl
27+
import nextflow.script.namespaces.ChannelNamespace
28+
import nextflow.script.types.shim.Iterable
2729
import org.codehaus.groovy.ast.ClassHelper
2830
import org.codehaus.groovy.ast.ClassNode
2931
import org.codehaus.groovy.ast.Parameter
@@ -40,6 +42,7 @@ class ASTNodeStringUtilsTest extends Specification {
4042
when:
4143
def classNode = Mock(ClassNode) {
4244
isEnum() >> false
45+
isResolved() >> true
4346
getNameWithoutPackage() >> 'Channel'
4447
}
4548
then:
@@ -48,6 +51,7 @@ class ASTNodeStringUtilsTest extends Specification {
4851
when:
4952
def enumNode = Mock(ClassNode) {
5053
isEnum() >> true
54+
isResolved() >> true
5155
getNameWithoutPackage() >> 'SequenceTypes'
5256
getGroovydoc() >> Mock(Groovydoc) {
5357
isPresent() >> true
@@ -160,16 +164,36 @@ class ASTNodeStringUtilsTest extends Specification {
160164

161165
def 'should get the label and docs for a built-in function' () {
162166
when:
163-
def node = new ClassNode(Channel.class).getDeclaredMethods('of').first()
167+
def node = new ClassNode(ScriptDsl.class).getDeclaredMethods('env').first()
164168
then:
165-
ASTNodeStringUtils.getLabel(node) == 'Channel.of(arg0...: E) -> Channel<E>'
169+
ASTNodeStringUtils.getLabel(node) == 'env(arg0: String) -> String'
170+
ASTNodeStringUtils.getDocumentation(node) == '''
171+
Get the value of an environment variable from the launch environment.
172+
'''.stripIndent(true).trim()
173+
}
174+
175+
def 'should get the label and docs for a namespace function' () {
176+
when:
177+
def node = new ClassNode(ChannelNamespace.class).getDeclaredMethods('of').first()
178+
then:
179+
ASTNodeStringUtils.getLabel(node) == 'of(arg0...: E) -> Channel<E>'
166180
ASTNodeStringUtils.getDocumentation(node) == '''
167181
Create a channel that emits each argument.
168182
169183
[Read more](https://nextflow.io/docs/latest/reference/channel.html#of)
170184
'''.stripIndent(true).trim()
171185
}
172186

187+
def 'should get the label and docs for a method' () {
188+
when:
189+
def node = new ClassNode(Iterable.class).getDeclaredMethods('collect').first()
190+
then:
191+
ASTNodeStringUtils.getLabel(node) == 'Iterable collect(arg0: (E) -> R) -> Iterable<R>'
192+
ASTNodeStringUtils.getDocumentation(node) == '''
193+
Returns a new iterable with each element transformed by the given closure.
194+
'''.stripIndent(true).trim()
195+
}
196+
173197
def 'should get the label and docs for a process directive' () {
174198
when:
175199
def node = new ClassNode(ProcessDsl.DirectiveDsl.class).getDeclaredMethods('executor').first()

0 commit comments

Comments
 (0)