Skip to content

Commit 0bab7cb

Browse files
committed
fix cm5 hint bug
1 parent 798d782 commit 0bab7cb

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

packages/codemirror-graphql/src/__tests__/hint-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,8 @@ describe('graphql-hint', () => {
975975
description:
976976
'The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.',
977977
},
978-
{ text: 'TestEnum' },
979-
{ text: 'TestInput' },
978+
{ text: 'TestEnum', description: '' },
979+
{ text: 'TestInput', description: '' },
980980
{
981981
text: '__TypeKind',
982982
description:
@@ -1022,8 +1022,8 @@ describe('graphql-hint', () => {
10221022
description:
10231023
'The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) input value will be accepted as an ID.',
10241024
},
1025-
{ text: 'TestEnum' },
1026-
{ text: 'TestInput' },
1025+
{ text: 'TestEnum', description: '' },
1026+
{ text: 'TestInput', description: '' },
10271027
{
10281028
text: '__TypeKind',
10291029
description:

packages/graphql-language-service/src/interface/__tests__/getAutocompleteSuggestions-test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe('getAutocompleteSuggestions', () => {
118118
if (suggestion.command && !options?.ignoreInsert) {
119119
response.command = suggestion.command;
120120
}
121-
if (suggestion.documentation) {
121+
if (suggestion.documentation?.length) {
122122
response.documentation = suggestion.documentation;
123123
}
124124
if (suggestion.labelDetails && !options?.ignoreInsert) {
@@ -531,6 +531,7 @@ describe('getAutocompleteSuggestions', () => {
531531
{
532532
label: 'Foo',
533533
detail: 'Human',
534+
documentation: 'fragment Foo on Human',
534535
labelDetails: { detail: 'fragment Foo on Human' },
535536
},
536537
]);
@@ -543,6 +544,8 @@ describe('getAutocompleteSuggestions', () => {
543544
{
544545
label: 'Foo',
545546
detail: 'Human',
547+
documentation: 'fragment Foo on Human',
548+
546549
labelDetails: { detail: 'fragment Foo on Human' },
547550
},
548551
]);
@@ -557,6 +560,8 @@ describe('getAutocompleteSuggestions', () => {
557560
{
558561
label: 'Foo',
559562
detail: 'Human',
563+
documentation: 'fragment Foo on Human',
564+
560565
labelDetails: { detail: 'fragment Foo on Human' },
561566
},
562567
]);
@@ -582,11 +587,13 @@ describe('getAutocompleteSuggestions', () => {
582587
{
583588
label: 'CharacterDetails',
584589
detail: 'Human',
590+
documentation: 'fragment CharacterDetails on Human',
585591
labelDetails: { detail: 'fragment CharacterDetails on Human' },
586592
},
587593
{
588594
label: 'CharacterDetails2',
589595
detail: 'Human',
596+
documentation: 'fragment CharacterDetails2 on Human',
590597
labelDetails: { detail: 'fragment CharacterDetails2 on Human' },
591598
},
592599
]);

packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ export function getAutocompleteSuggestions(
447447
kind: CompletionItemKind.Function,
448448
insertText: options?.fillLeafsOnComplete
449449
? type.name + '\n'
450-
: undefined,
450+
: type.name,
451451
insertTextMode: InsertTextMode.adjustIndentation,
452452
})),
453453
);
@@ -462,7 +462,7 @@ export function getAutocompleteSuggestions(
462462
kind: CompletionItemKind.Function,
463463
insertText: options?.fillLeafsOnComplete
464464
? type.name + '\n$1'
465-
: undefined,
465+
: type.name,
466466
insertTextMode: InsertTextMode.adjustIndentation,
467467
insertTextFormat: InsertTextFormat.Snippet,
468468
})),
@@ -486,9 +486,9 @@ export function getAutocompleteSuggestions(
486486
if (kind === RuleKinds.DIRECTIVE) {
487487
return getSuggestionsForDirective(token, state, schema, kind);
488488
}
489-
// if (kind === RuleKinds.DIRECTIVE_DEF) {
490-
// return getSuggestionsForDirectiveArguments(token, state, schema, kind);
491-
// }
489+
if (kind === RuleKinds.DIRECTIVE_DEF) {
490+
return getSuggestionsForDirectiveArguments(token, state, schema, kind);
491+
}
492492

493493
return [];
494494
}
@@ -844,7 +844,7 @@ function getSuggestionsForImplements(
844844
kind: CompletionItemKind.Interface,
845845
type,
846846
} as CompletionItem;
847-
if (type?.description && type.description.length) {
847+
if (type?.description) {
848848
result.documentation = type.description;
849849
}
850850
// TODO: should we report what an interface implements in CompletionItem.detail?
@@ -898,7 +898,7 @@ function getSuggestionsForFragmentTypeConditions(
898898
const namedType = getNamedType(type);
899899
return {
900900
label: String(type),
901-
documentation: namedType?.description as string | undefined,
901+
documentation: (namedType?.description as string | undefined) || '',
902902
kind: CompletionItemKind.Field,
903903
};
904904
}),
@@ -949,6 +949,7 @@ function getSuggestionsForFragmentSpread(
949949
relevantFrags.map(frag => ({
950950
label: frag.name.value,
951951
detail: String(typeMap[frag.typeCondition.name.value]),
952+
documentation: `fragment ${frag.name.value} on ${frag.typeCondition.name.value}`,
952953
labelDetails: {
953954
detail: `fragment ${frag.name.value} on ${frag.typeCondition.name.value}`,
954955
},
@@ -1069,7 +1070,7 @@ function getSuggestionsForVariableDefinition(
10691070
// TODO: couldn't get Exclude<> working here
10701071
inputTypes.map((type: GraphQLNamedType) => ({
10711072
label: type.name,
1072-
documentation: type?.description?.length ? type.description : undefined,
1073+
documentation: type?.description || '',
10731074
kind: CompletionItemKind.Variable,
10741075
})),
10751076
);
@@ -1089,9 +1090,7 @@ function getSuggestionsForDirective(
10891090
token,
10901091
directives.map(directive => ({
10911092
label: directive.name,
1092-
documentation: directive?.description?.length
1093-
? directive.description
1094-
: undefined,
1093+
documentation: directive?.description || '',
10951094
kind: CompletionItemKind.Function,
10961095
})),
10971096
);
@@ -1101,22 +1100,22 @@ function getSuggestionsForDirective(
11011100

11021101
// I thought this added functionality somewhere, but I couldn't write any tests
11031102
// to execute it. I think it's handled as Arguments
1104-
// function getSuggestionsForDirectiveArguments(
1105-
// token: ContextToken,
1106-
// state: State,
1107-
// schema: GraphQLSchema,
1108-
// _kind: string,
1109-
// ): Array<CompletionItem> {
1110-
// const directive = schema.getDirectives().find(d => d.name === state.name);
1111-
// return hintList(
1112-
// token,
1113-
// directive?.args.map(arg => ({
1114-
// label: arg.name,
1115-
// documentation: arg.description || '',
1116-
// kind: CompletionItemKind.Field,
1117-
// })) || [],
1118-
// );
1119-
// }
1103+
function getSuggestionsForDirectiveArguments(
1104+
token: ContextToken,
1105+
state: State,
1106+
schema: GraphQLSchema,
1107+
_kind: string,
1108+
): Array<CompletionItem> {
1109+
const directive = schema.getDirectives().find(d => d.name === state.name);
1110+
return hintList(
1111+
token,
1112+
directive?.args.map(arg => ({
1113+
label: arg.name,
1114+
documentation: arg.description || '',
1115+
kind: CompletionItemKind.Field,
1116+
})) || [],
1117+
);
1118+
}
11201119

11211120
export function getTokenAtPosition(
11221121
queryText: string,

0 commit comments

Comments
 (0)