nextflow-io / language-server

The Nextflow language server
Apache License 2.0
9 stars 0 forks source link

Improve errors when mixing statements and script declarations #39

Closed bentsherman closed 1 month ago

bentsherman commented 1 month ago

Close #36

This PR allows statements and script declarations to be mixed in the parser, reporting the statements as errors in the ast builder.

The problem now is with cases like the following:

process foo {
    input: path x
    input: path y
    """
    echo "FOO1: ${x}; ${y}"
    """
}

workflow bar {
    flow1()
    flow2()
    ch1 = flow1.out.result
    ch2 = flow2.out.result
    emit: ch1.mix(ch2)
}

Both definitions are invalid (process has two input sections, workflow has no "main" label), but the language server will not report any error because they are parsed as invalid declarations in a code snippet. These are just some examples but there are many more.

I think I can handle this case by highlighting them only if there are no statements, because then the mixing of statements / declarations is not the issue. But then all definitions would be highlighted, even the valid ones.

I think I can handle that by trying to parse them explicitly, and highlighting them only if they fail to parse as a process / workflow. (then they will just look like function calls).