nextflow-io / language-server

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

template variables misidentified as unused #57

Open d3v-null opened 3 weeks ago

d3v-null commented 3 weeks ago

Hey there, Huge thanks to you all for getting the language server working properly in the VSCode extension.

One recurring issue is that the linter thinks a process variable is not used, when it is used in a template.

I like to make my python template scripts reusable, so I use a pattern of injecting arguments into template like this as command line arguments, e.g. templates/foo.py

#!/usr/bin/env python
from argparse import ArgumentParser
import shlex

def get_parser() -> ArgumentParser:
    ...

argv = sys.argv
if len(sys.argv) == 1:
    # is being called directly from nextflow, use argv from parsing argstr
    argv = shlex.split("${argstr}")

args = get_parser().parse_args(argv)
...
process foo {
    input: tuple val(arg1), val(arg2)
    script:
    argstr = "--arg1=${arg1} --arg2=${arg2}" //noqa
    template "foo.py"
}

In this example, the linter has a problem with argstr, "Variable was declared but not used", despite it being used in the template.

I can think of three ways around this:

Thanks