Handlers and the language server

The nextflow manual instructs us to define handlers like…

workflow.onComplete {
    println "Pipeline completed at: $workflow.complete"
    println "Execution status: ${ workflow.success ? 'OK' : 'failed' }"
}

https://nextflow.io/docs/latest/notifications.html#workflow-handlers

This has worked well but I’d also like to use the language server. Handlers defined in this manner make the language server very sad.

[{
	"resource": "/Users/jkern/workspaces/scarlet/main.nf",
	"owner": "_generated_diagnostic_collection_name_#5",
	"severity": 8,
	"message": "Statements cannot be mixed with script declarations -- move statements into a process or workflow",
	"source": "nextflow",
	"startLineNumber": 1032,
	"startColumn": 1,
	"endLineNumber": 1050,
	"endColumn": 2
}]

If I move this inside the workflow block, the error goes away. Unfortunately, so does the functionality.

I am using this language server…
Identifier - nextflow.nextflow
Version - 1.0.4
Last Updated - 2025-01-21, 17:17:30

What is a good way to define these handlers in a language server compliant way?

-jk

In reality there are several ways to define the workflow handler. For now you can use this form to satisfy the language server:

workflow {
    // ...

    workflow.onComplete = {
        println "Pipeline completed at: $workflow.complete"
        println "Execution status: ${ workflow.success ? 'OK' : 'failed' }"
    }
}

We are working on a better syntax for these handlers as a more permanent solution.

Thanks Ben. Works like a charm. I thought I only needed to say onComplete since I was already in the worklfow block.

-jk

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.