Skip to content

Commit 6bc41c5

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

File tree

5 files changed

+70
-11
lines changed

5 files changed

+70
-11
lines changed

modules/language-server/src/main/java/nextflow/lsp/NextflowLanguageServer.java

Lines changed: 13 additions & 5 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,24 +445,24 @@ 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.completion.extended");
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.completion.maxItems");
454-
var paranoidWarnings = JsonUtils.getBoolean(params.getSettings(), "nextflow.paranoidWarnings");
455-
if( paranoidWarnings != null && configuration.paranoidWarnings() != paranoidWarnings )
456-
shouldInitialize = true;
457458

458459
configuration = new LanguageServerConfiguration(
460+
errorReportingMode != null ? errorReportingMode : configuration.errorReportingMode(),
459461
excludePatterns,
460462
extendedCompletion != null ? extendedCompletion : configuration.extendedCompletion(),
461463
harshilAlignment != null ? harshilAlignment : configuration.harshilAlignment(),
462464
maheshForm != null ? maheshForm : configuration.maheshForm(),
463-
maxCompletionItems != null ? maxCompletionItems : configuration.maxCompletionItems(),
464-
paranoidWarnings != null ? paranoidWarnings : configuration.paranoidWarnings()
465+
maxCompletionItems != null ? maxCompletionItems : configuration.maxCompletionItems()
465466
);
466467

467468
if( shouldInitialize ) {
@@ -487,6 +488,13 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
487488
}
488489
}
489490

491+
private ErrorReportingMode errorReportingMode(DidChangeConfigurationParams params) {
492+
var string = JsonUtils.getString(params.getSettings(), "nextflow.errorReportingMode");
493+
if( string == null )
494+
return null;
495+
return ErrorReportingMode.valueOf(string.toUpperCase());
496+
}
497+
490498
private void progressCreate(String token) {
491499
client.createProgress(new WorkDoneProgressCreateParams(Either.forLeft(token)));
492500
}
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.FutureWarning;
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 FutureWarning )
34+
return this == PARANOID;
35+
return compareTo(WARNINGS) >= 0;
36+
}
37+
}

modules/language-server/src/main/java/nextflow/lsp/services/LanguageServerConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
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,
26-
int maxCompletionItems,
27-
boolean paranoidWarnings
27+
int maxCompletionItems
2828
) {
2929

3030
public static LanguageServerConfiguration defaults() {
3131
return new LanguageServerConfiguration(
32+
ErrorReportingMode.WARNINGS,
3233
Collections.emptyList(),
3334
false,
3435
false,
3536
false,
36-
100,
37-
false
37+
100
3838
);
3939
}
4040
}

modules/language-server/src/main/java/nextflow/lsp/services/LanguageService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import nextflow.lsp.util.LanguageServerUtils;
4242
import nextflow.lsp.util.Logger;
4343
import nextflow.lsp.util.Positions;
44-
import nextflow.script.control.FutureWarning;
4544
import nextflow.script.control.RelatedInformationAware;
4645
import nextflow.script.formatter.FormattingOptions;
4746
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
@@ -382,6 +381,9 @@ protected void publishDiagnostics(Set<URI> changedUris) {
382381
changedUris.forEach((uri) -> {
383382
var diagnostics = new ArrayList<Diagnostic>();
384383
for( var error : astCache.getErrors(uri) ) {
384+
if( !configuration.errorReportingMode().isRelevant(error) )
385+
continue;
386+
385387
var message = error.getOriginalMessage();
386388
var range = LanguageServerUtils.errorToRange(error);
387389
if( range == null ) {
@@ -396,7 +398,7 @@ protected void publishDiagnostics(Set<URI> changedUris) {
396398
}
397399

398400
for( var warning : astCache.getWarnings(uri) ) {
399-
if( !configuration.paranoidWarnings() && warning instanceof FutureWarning )
401+
if( !configuration.errorReportingMode().isRelevant(warning) )
400402
continue;
401403

402404
var message = warning.getMessage();

modules/language-server/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)