From 2ec2b98622abbcd2efb1d3123dc0a617ba937d4a Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Tue, 29 Oct 2024 09:35:38 +0100 Subject: [PATCH] Add warning for unused includes Signed-off-by: Ben Sherman --- .../lsp/services/script/VariableScopeVisitor.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/nextflow/lsp/services/script/VariableScopeVisitor.java b/src/main/groovy/nextflow/lsp/services/script/VariableScopeVisitor.java index ca89394d..a0da89dc 100644 --- a/src/main/groovy/nextflow/lsp/services/script/VariableScopeVisitor.java +++ b/src/main/groovy/nextflow/lsp/services/script/VariableScopeVisitor.java @@ -51,6 +51,7 @@ import nextflow.script.v2.FeatureFlagNode; import nextflow.script.v2.FunctionNode; import nextflow.script.v2.IncludeNode; +import nextflow.script.v2.IncludeVariable; import nextflow.script.v2.OutputNode; import nextflow.script.v2.ProcessNode; import nextflow.script.v2.ScriptNode; @@ -147,6 +148,7 @@ private void declareInclude(IncludeNode node) { if( otherInclude != null ) addError("`" + name + "` is already included", node, "First included here", (ASTNode) otherInclude); includes.put(name, module); + declaredVariables.add(module); } } @@ -176,8 +178,12 @@ public void visit() { // warn about any unused local variables for( var variable : declaredVariables ) { - if( variable instanceof ASTNode node && !variable.getName().startsWith("_") ) - sourceUnit.addWarning("Variable was declared but not used", node); + if( variable instanceof ASTNode node && !variable.getName().startsWith("_") ) { + var message = variable instanceof IncludeVariable + ? "Include was not used" + : "Variable was declared but not used"; + sourceUnit.addWarning(message, node); + } } } }