25
25
import java .util .Optional ;
26
26
import java .util .concurrent .CompletableFuture ;
27
27
28
- import com .google .gson .JsonElement ;
29
- import com .google .gson .JsonObject ;
30
- import com .google .gson .JsonPrimitive ;
31
28
import nextflow .lsp .file .PathUtils ;
29
+ import nextflow .lsp .util .JsonUtils ;
32
30
import nextflow .lsp .util .Logger ;
33
31
import nextflow .lsp .services .LanguageServerConfiguration ;
34
32
import nextflow .lsp .services .LanguageService ;
@@ -318,7 +316,7 @@ public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completio
318
316
var service = getLanguageService (uri );
319
317
if ( service == null )
320
318
return Either .forLeft (Collections .emptyList ());
321
- return service .completion (params , configuration .extendedCompletion ());
319
+ return service .completion (params , configuration .maxCompletionItems (), configuration . extendedCompletion ());
322
320
});
323
321
}
324
322
@@ -442,17 +440,18 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
442
440
443
441
var shouldInitialize = false ;
444
442
445
- var debug = getJsonBoolean (params .getSettings (), "nextflow.debug" );
443
+ var debug = JsonUtils . getBoolean (params .getSettings (), "nextflow.debug" );
446
444
if ( debug != null )
447
445
Logger .setDebugEnabled (debug );
448
446
449
- var excludePatterns = getJsonStringArray (params .getSettings (), "nextflow.files.exclude" );
447
+ var excludePatterns = JsonUtils . getStringArray (params .getSettings (), "nextflow.files.exclude" );
450
448
if ( !DefaultGroovyMethods .equals (configuration .excludePatterns (), excludePatterns ) )
451
449
shouldInitialize = true ;
452
- var extendedCompletion = getJsonBoolean (params .getSettings (), "nextflow.completion.extended" );
453
- var harshilAlignment = getJsonBoolean (params .getSettings (), "nextflow.formatting.harshilAlignment" );
454
- var maheshForm = getJsonBoolean (params .getSettings (), "nextflow.formatting.maheshForm" );
455
- var paranoidWarnings = getJsonBoolean (params .getSettings (), "nextflow.paranoidWarnings" );
450
+ var extendedCompletion = JsonUtils .getBoolean (params .getSettings (), "nextflow.completion.extended" );
451
+ var harshilAlignment = JsonUtils .getBoolean (params .getSettings (), "nextflow.formatting.harshilAlignment" );
452
+ var maheshForm = JsonUtils .getBoolean (params .getSettings (), "nextflow.formatting.maheshForm" );
453
+ var maxCompletionItems = JsonUtils .getInteger (params .getSettings (), "nextflow.completion.maxItems" );
454
+ var paranoidWarnings = JsonUtils .getBoolean (params .getSettings (), "nextflow.paranoidWarnings" );
456
455
if ( paranoidWarnings != null && configuration .paranoidWarnings () != paranoidWarnings )
457
456
shouldInitialize = true ;
458
457
@@ -461,6 +460,7 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
461
460
extendedCompletion != null ? extendedCompletion : configuration .extendedCompletion (),
462
461
harshilAlignment != null ? harshilAlignment : configuration .harshilAlignment (),
463
462
maheshForm != null ? maheshForm : configuration .maheshForm (),
463
+ maxCompletionItems != null ? maxCompletionItems : configuration .maxCompletionItems (),
464
464
paranoidWarnings != null ? paranoidWarnings : configuration .paranoidWarnings ()
465
465
);
466
466
@@ -558,7 +558,7 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
558
558
var arguments = params .getArguments ();
559
559
if ( !"nextflow.server.previewDag" .equals (command ) || arguments .size () != 2 )
560
560
return null ;
561
- var uri = getJsonString (arguments .get (0 ));
561
+ var uri = JsonUtils . getString (arguments .get (0 ));
562
562
log .debug (String .format ("textDocument/executeCommand %s %s" , command , arguments .toString ()));
563
563
var service = getLanguageService (uri );
564
564
if ( service == null )
@@ -567,10 +567,6 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) {
567
567
});
568
568
}
569
569
570
- private String getJsonString (Object json ) {
571
- return json instanceof JsonPrimitive jp ? jp .getAsString () : null ;
572
- }
573
-
574
570
@ Override
575
571
public CompletableFuture <Either <List <? extends SymbolInformation >, List <? extends WorkspaceSymbol >>> symbol (WorkspaceSymbolParams params ) {
576
572
return CompletableFutures .computeAsync ((cancelChecker ) -> {
@@ -633,49 +629,4 @@ private LanguageService getLanguageService0(String uri, Map<String, LanguageServ
633
629
return service ;
634
630
}
635
631
636
- private List <String > getJsonStringArray (Object json , String path ) {
637
- var value = getJsonElement (json , path );
638
- if ( value == null || !value .isJsonArray () )
639
- return null ;
640
- var result = new ArrayList <String >();
641
- for ( var el : value .getAsJsonArray () ) {
642
- try {
643
- result .add (el .getAsJsonPrimitive ().getAsString ());
644
- }
645
- catch ( AssertionError e ) {
646
- continue ;
647
- }
648
- }
649
- return result ;
650
- }
651
-
652
- private Boolean getJsonBoolean (Object json , String path ) {
653
- var value = getJsonElement (json , path );
654
- if ( value == null || !value .isJsonPrimitive () )
655
- return null ;
656
- var result = value .getAsJsonPrimitive ();
657
- if ( !result .isBoolean () )
658
- return null ;
659
- return result .getAsBoolean ();
660
- }
661
-
662
- private JsonElement getJsonElement (Object json , String path ) {
663
- if ( !(json instanceof JsonObject ) )
664
- return null ;
665
-
666
- JsonObject object = (JsonObject ) json ;
667
- var names = path .split ("\\ ." );
668
- for ( int i = 0 ; i < names .length - 1 ; i ++ ) {
669
- var scope = names [i ];
670
- if ( !object .has (scope ) || !object .get (scope ).isJsonObject () )
671
- return null ;
672
- object = object .get (scope ).getAsJsonObject ();
673
- }
674
-
675
- var property = names [names .length - 1 ];
676
- if ( !object .has (property ) )
677
- return null ;
678
- return object .get (property );
679
- }
680
-
681
632
}
0 commit comments