Skip to content

Commit ce41d70

Browse files
committed
Show record body when showing a named record type in a process hover
hint (close #157) Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 46ab32a commit ce41d70

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
import static nextflow.script.types.TypeCheckingUtils.*;
5959

6060
/**
61-
* Utility methods for retreiving text information for ast nodes.
61+
* Utility methods for retrieving text information for ast nodes.
6262
*
6363
* @author Ben Sherman <bentshermann@gmail.com>
6464
*/
@@ -213,6 +213,8 @@ private static void typedInput(Parameter input, Formatter fmt) {
213213
if( fmt.hasType(input) ) {
214214
fmt.append(": ");
215215
fmt.visitTypeAnnotation(input.getType());
216+
if( input.getType().redirect() instanceof RecordNode )
217+
namedRecordBody(input.getType(), fmt);
216218
}
217219
}
218220
}
@@ -250,6 +252,25 @@ private static void processTupleInput(TupleParameter tp, Formatter fmt) {
250252
fmt.append(">");
251253
}
252254

255+
private static void namedRecordBody(ClassNode type, Formatter fmt) {
256+
var fields = type.redirect().getFields();
257+
if( fields.isEmpty() )
258+
return;
259+
fmt.append(" {");
260+
fmt.appendNewLine();
261+
fmt.incIndent();
262+
for( var fn : fields ) {
263+
fmt.appendIndent();
264+
fmt.append(fn.getName());
265+
fmt.append(": ");
266+
fmt.append(TypesEx.getName(fn.getType()));
267+
fmt.appendNewLine();
268+
}
269+
fmt.decIndent();
270+
fmt.appendIndent();
271+
fmt.append('}');
272+
}
273+
253274
private static String processToLabel(ProcessNodeV1 node) {
254275
var fmt = new Formatter(new FormattingOptions(2, true));
255276
fmt.append("process ");

src/test/groovy/nextflow/lsp/services/script/ScriptHoverTest.groovy

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,50 @@ class ScriptHoverTest extends Specification {
8080
value.startsWith('```nextflow\nworkflow HELLO {')
8181
}
8282

83+
def 'should expand a named record type when hovering over a process' () {
84+
given:
85+
def service = getScriptService()
86+
def uri = getUri('main.nf')
87+
88+
when:
89+
open(service, uri, '''\
90+
nextflow.enable.types = true
91+
92+
record SamtoolsIndexInput {
93+
id: String
94+
input: Path
95+
}
96+
97+
process SAMTOOLS_INDEX {
98+
input:
99+
data: SamtoolsIndexInput
100+
101+
script:
102+
'samtools index'
103+
}
104+
105+
workflow {
106+
SAMTOOLS_INDEX( channel.empty() )
107+
}
108+
''')
109+
service.updateNow()
110+
def value = getHoverHint(service, uri, new Position(16, 4))
111+
then:
112+
value == '''\
113+
```nextflow
114+
process SAMTOOLS_INDEX {
115+
input:
116+
data: SamtoolsIndexInput {
117+
id: String
118+
input: Path
119+
}
120+
121+
output:
122+
<none>
123+
}
124+
```'''.stripIndent(true)
125+
}
126+
83127
def 'should return null when hovering over whitespace' () {
84128
given:
85129
def service = getScriptService()

0 commit comments

Comments
 (0)