Skip to content

Commit 09bff6b

Browse files
committed
Replace paranoidWarnings with errorReportingMode
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent c812f6b commit 09bff6b

File tree

5 files changed

+67
-8
lines changed

5 files changed

+67
-8
lines changed

src/main/java/nextflow/lsp/NextflowLanguageServer.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import nextflow.lsp.file.PathUtils;
2929
import nextflow.lsp.util.JsonUtils;
3030
import nextflow.lsp.util.Logger;
31+
import nextflow.lsp.services.ErrorReportingMode;
3132
import nextflow.lsp.services.LanguageServerConfiguration;
3233
import nextflow.lsp.services.LanguageService;
3334
import nextflow.lsp.services.SemanticTokensVisitor;
@@ -444,27 +445,27 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
444445
if( debug != null )
445446
Logger.setDebugEnabled(debug);
446447

448+
var errorReportingMode = errorReportingMode(params);
449+
if( errorReportingMode != null && configuration.errorReportingMode() != errorReportingMode )
450+
shouldInitialize = true;
447451
var excludePatterns = JsonUtils.getStringArray(params.getSettings(), "nextflow.files.exclude");
448452
if( !DefaultGroovyMethods.equals(configuration.excludePatterns(), excludePatterns) )
449453
shouldInitialize = true;
450454
var extendedCompletion = JsonUtils.getBoolean(params.getSettings(), "nextflow.extendedCompletion");
451455
var harshilAlignment = JsonUtils.getBoolean(params.getSettings(), "nextflow.formatting.harshilAlignment");
452456
var maheshForm = JsonUtils.getBoolean(params.getSettings(), "nextflow.formatting.maheshForm");
453457
var maxCompletionItems = JsonUtils.getInteger(params.getSettings(), "nextflow.maxCompletionItems");
454-
var paranoidWarnings = JsonUtils.getBoolean(params.getSettings(), "nextflow.paranoidWarnings");
455-
if( paranoidWarnings != null && configuration.paranoidWarnings() != paranoidWarnings )
456-
shouldInitialize = true;
457458
var typeChecking = JsonUtils.getBoolean(params.getSettings(), "nextflow.typeChecking");
458459
if( typeChecking != null && configuration.typeChecking() != typeChecking )
459460
shouldInitialize = true;
460461

461462
configuration = new LanguageServerConfiguration(
463+
errorReportingMode != null ? errorReportingMode : configuration.errorReportingMode(),
462464
excludePatterns,
463465
extendedCompletion != null ? extendedCompletion : configuration.extendedCompletion(),
464466
harshilAlignment != null ? harshilAlignment : configuration.harshilAlignment(),
465467
maheshForm != null ? maheshForm : configuration.maheshForm(),
466468
maxCompletionItems != null ? maxCompletionItems : configuration.maxCompletionItems(),
467-
paranoidWarnings != null ? paranoidWarnings : configuration.paranoidWarnings(),
468469
typeChecking != null ? typeChecking : configuration.typeChecking()
469470
);
470471

@@ -491,6 +492,13 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
491492
}
492493
}
493494

495+
private ErrorReportingMode errorReportingMode(DidChangeConfigurationParams params) {
496+
var string = JsonUtils.getString(params.getSettings(), "nextflow.errorReportingMode");
497+
if( string == null )
498+
return null;
499+
return ErrorReportingMode.valueOf(string.toUpperCase());
500+
}
501+
494502
private void progressCreate(String token) {
495503
client.createProgress(new WorkDoneProgressCreateParams(Either.forLeft(token)));
496504
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2024-2025, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package nextflow.lsp.services;
17+
18+
import nextflow.script.control.ParanoidWarning;
19+
import org.codehaus.groovy.control.messages.WarningMessage;
20+
import org.codehaus.groovy.syntax.SyntaxException;
21+
22+
public enum ErrorReportingMode {
23+
OFF,
24+
ERRORS,
25+
WARNINGS,
26+
PARANOID;
27+
28+
public boolean isRelevant(SyntaxException error) {
29+
return this != OFF;
30+
}
31+
32+
public boolean isRelevant(WarningMessage warning) {
33+
if( warning instanceof ParanoidWarning )
34+
return this == PARANOID;
35+
return compareTo(WARNINGS) >= 0;
36+
}
37+
}

src/main/java/nextflow/lsp/services/LanguageServerConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919
import java.util.List;
2020

2121
public record LanguageServerConfiguration(
22+
ErrorReportingMode errorReportingMode,
2223
List<String> excludePatterns,
2324
boolean extendedCompletion,
2425
boolean harshilAlignment,
2526
boolean maheshForm,
2627
int maxCompletionItems,
27-
boolean paranoidWarnings,
2828
boolean typeChecking
2929
) {
3030

3131
public static LanguageServerConfiguration defaults() {
3232
return new LanguageServerConfiguration(
33+
ErrorReportingMode.WARNINGS,
3334
Collections.emptyList(),
3435
true,
3536
false,
3637
false,
3738
100,
38-
false,
3939
false
4040
);
4141
}

src/main/java/nextflow/lsp/services/LanguageService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import nextflow.lsp.util.LanguageServerUtils;
4141
import nextflow.lsp.util.Logger;
4242
import nextflow.lsp.util.Positions;
43-
import nextflow.script.control.ParanoidWarning;
4443
import nextflow.script.control.RelatedInformationAware;
4544
import nextflow.script.formatter.FormattingOptions;
4645
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
@@ -381,6 +380,9 @@ protected void publishDiagnostics(Set<URI> changedUris) {
381380
changedUris.forEach((uri) -> {
382381
var diagnostics = new ArrayList<Diagnostic>();
383382
for( var error : astCache.getErrors(uri) ) {
383+
if( !configuration.errorReportingMode().isRelevant(error) )
384+
continue;
385+
384386
var message = error.getOriginalMessage();
385387
var range = LanguageServerUtils.errorToRange(error);
386388
if( range == null ) {
@@ -395,7 +397,7 @@ protected void publishDiagnostics(Set<URI> changedUris) {
395397
}
396398

397399
for( var warning : astCache.getWarnings(uri) ) {
398-
if( !configuration.paranoidWarnings() && warning instanceof ParanoidWarning )
400+
if( !configuration.errorReportingMode().isRelevant(warning) )
399401
continue;
400402

401403
var message = warning.getMessage();

src/main/java/nextflow/lsp/util/JsonUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public static Integer getInteger(Object json, String path) {
6868
}
6969
}
7070

71+
public static String getString(Object json, String path) {
72+
var value = getObjectPath(json, path);
73+
if( value == null )
74+
return null;
75+
try {
76+
return value.getAsString();
77+
}
78+
catch( ClassCastException e ) {
79+
return null;
80+
}
81+
}
82+
7183
public static String getString(Object json) {
7284
return json instanceof JsonPrimitive jp ? jp.getAsString() : null;
7385
}

0 commit comments

Comments
 (0)