@@ -345,7 +345,9 @@ export function getAutocompleteSuggestions(
345
345
insertTextMode : InsertTextMode . adjustIndentation ,
346
346
insertTextFormat : InsertTextFormat . Snippet ,
347
347
command : SuggestionCommand ,
348
- detail : String ( argDef . type ) ,
348
+ labelDetails : {
349
+ detail : ' ' + String ( argDef . type ) ,
350
+ } ,
349
351
documentation : argDef . description ?? undefined ,
350
352
kind : CompletionItemKind . Variable ,
351
353
type : argDef . type ,
@@ -526,6 +528,27 @@ const getInputInsertText = (
526
528
return getInsertText ( prefix , type , fallback ) ;
527
529
} ;
528
530
531
+ /**
532
+ * generates a TextSnippet for a field with possible required arguments
533
+ * that dynamically adjusts to the number of required arguments
534
+ * @param field
535
+ * @returns
536
+ */
537
+ const getFieldInsertText = ( field : GraphQLField < null , null > ) => {
538
+ const requiredArgs = field . args . filter ( arg =>
539
+ arg . type . toString ( ) . endsWith ( '!' ) ,
540
+ ) ;
541
+ if ( ! requiredArgs . length ) {
542
+ return ;
543
+ }
544
+ return (
545
+ field . name +
546
+ `(${ requiredArgs . map (
547
+ ( arg , i ) => `${ arg . name } : $${ i + 1 } ` ,
548
+ ) } ) ${ getInsertText ( '' , field . type , '\n' ) } `
549
+ ) ;
550
+ } ;
551
+
529
552
// /**
530
553
// * Choose carefully when to insert the `insertText`!
531
554
// * @param field
@@ -591,10 +614,6 @@ function getSuggestionsForExtensionDefinitions(token: ContextToken) {
591
614
return hintList ( token , typeSystemCompletionItems ) ;
592
615
}
593
616
594
- // const getFieldInsertText = (field: GraphQLField<null, null>) => {
595
- // return field.name + '($1) {\n\n \n}';
596
- // };
597
-
598
617
function getSuggestionsForFieldNames (
599
618
token : ContextToken ,
600
619
typeInfo : AllTypeInfo ,
@@ -617,6 +636,7 @@ function getSuggestionsForFieldNames(
617
636
if ( parentType === options ?. schema ?. getQueryType ( ) ) {
618
637
fields . push ( SchemaMetaFieldDef , TypeMetaFieldDef ) ;
619
638
}
639
+
620
640
return hintList (
621
641
token ,
622
642
fields . map < CompletionItem > ( ( field , index ) => {
@@ -632,51 +652,34 @@ function getSuggestionsForFieldNames(
632
652
deprecationReason : field . deprecationReason ,
633
653
kind : CompletionItemKind . Field ,
634
654
labelDetails : {
635
- detail : field . type . toString ( ) . endsWith ( '!' ) ? 'NonNull' : undefined ,
636
- description : field . description ?? undefined ,
655
+ detail : ' ' + field . type . toString ( ) ,
637
656
} ,
638
657
type : field . type ,
639
658
} ;
659
+ if ( options ?. fillLeafsOnComplete ) {
660
+ // const hasArgs =
661
+ // // token.state.needsAdvance &&
662
+ // // @ts -expect-error
663
+ // parentType?._fields[field?.name];
664
+
665
+ suggestion . insertText = getFieldInsertText ( field ) ;
666
+
667
+ // eslint-disable-next-line logical-assignment-operators
668
+ if ( ! suggestion . insertText ) {
669
+ suggestion . insertText = getInsertText (
670
+ field . name ,
671
+ field . type ,
672
+ // if we are replacing a field with arguments, we don't want the extra line
673
+ field . name + ( token . state . needsAdvance ? '' : '\n' ) ,
674
+ ) ;
675
+ }
640
676
641
- // const hasArgs =
642
- // token.state.needsAdvance &&
643
- // // @ts -expect-error
644
- // parentType?._fields[field?.name];
645
-
646
- // if (!hasArgs) {
647
- // suggestion.insertText = getInsertText(
648
- // field.name,
649
- // field.type,
650
- // field.name + '\n',
651
- // );
652
- // }
653
-
654
- // const requiredArgs = field.args.filter(arg =>
655
- // arg.type.toString().endsWith('!'),
656
- // );
657
- // if (
658
- // hasArgs &&
659
- // requiredArgs.length &&
660
- // !argDefs?.find(d => requiredArgs.find(a => d.name === a.name))
661
- // ) {
662
- // suggestion.insertText = getFieldInsertText(field);
663
- // }
664
-
665
- // if (suggestion.insertText) {
666
- // suggestion.insertTextFormat = InsertTextFormat.Snippet;
667
- // suggestion.insertTextMode = InsertTextMode.adjustIndentation;
668
- // suggestion.command = SuggestionCommand;
669
- // }
670
-
671
- // if (options?.fillLeafsOnComplete) {
672
- // // TODO: fillLeafs capability
673
- // const insertText = getInsertText(field);
674
- // if (insertText) {
675
- // suggestion.insertText = field.name + insertText;
676
- // suggestion.insertTextFormat = InsertTextFormat.Snippet;
677
- // suggestion.command = SuggestionCommand;
678
- // }
679
- // }
677
+ if ( suggestion . insertText ) {
678
+ suggestion . insertTextFormat = InsertTextFormat . Snippet ;
679
+ suggestion . insertTextMode = InsertTextMode . adjustIndentation ;
680
+ suggestion . command = SuggestionCommand ;
681
+ }
682
+ }
680
683
681
684
return suggestion ;
682
685
} ) ,
0 commit comments