graphql-language-service-interface
Advanced tools
Comparing version 2.9.5 to 2.9.6-canary-b5aba87e.0
import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql'; | ||
import { CompletionItem, AllTypeInfo, IPosition } from 'graphql-language-service-types'; | ||
import { CharacterStream, ContextToken, State, ContextTokenForCodeMirror } from 'graphql-language-service-parser'; | ||
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>; | ||
export declare type AutocompleteSuggestionOptions = { | ||
fillLeafsOnComplete?: boolean; | ||
schema?: GraphQLSchema; | ||
}; | ||
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string, options?: AutocompleteSuggestionOptions): Array<CompletionItem>; | ||
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, token: ContextToken): CompletionItem[]; | ||
@@ -6,0 +10,0 @@ export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>; |
@@ -9,2 +9,3 @@ "use strict"; | ||
const autocompleteUtils_1 = require("./autocompleteUtils"); | ||
const graphql_language_service_utils_1 = require("graphql-language-service-utils"); | ||
const collectFragmentDefs = (op) => { | ||
@@ -23,4 +24,5 @@ const externalFragments = []; | ||
}; | ||
function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs) { | ||
function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) { | ||
var _a; | ||
const opts = Object.assign(Object.assign({}, options), { schema }); | ||
const token = contextToken || getTokenAtPosition(queryText, cursor); | ||
@@ -51,3 +53,3 @@ const state = token.state.kind === 'Invalid' ? token.state.prevState : token.state; | ||
kind === graphql_language_service_parser_1.RuleKinds.ALIASED_FIELD) { | ||
return getSuggestionsForFieldNames(token, typeInfo, schema); | ||
return getSuggestionsForFieldNames(token, typeInfo, opts); | ||
} | ||
@@ -131,3 +133,37 @@ if (kind === graphql_language_service_parser_1.RuleKinds.ARGUMENTS || | ||
exports.getAutocompleteSuggestions = getAutocompleteSuggestions; | ||
function getSuggestionsForFieldNames(token, typeInfo, schema) { | ||
const insertSuffix = ` {\n $1\n}`; | ||
const appendInsertText = (field, type, options) => { | ||
if (options === null || options === void 0 ? void 0 : options.fillLeafsOnComplete) { | ||
const selectionSet = graphql_language_service_utils_1.buildSelectionSet(field, type, graphql_language_service_utils_1.defaultGetDefaultFieldNames, options.schema); | ||
if (selectionSet) { | ||
return ` ${graphql_1.print(selectionSet)}`; | ||
} | ||
} | ||
return insertSuffix; | ||
}; | ||
const getInsertText = (field, options) => { | ||
var _a; | ||
const type = field.type; | ||
if (graphql_2.isCompositeType(type)) { | ||
return appendInsertText(field, type, options); | ||
} | ||
if (graphql_1.isListType(type)) { | ||
if ('ofType' in type) { | ||
return appendInsertText(field, type === null || type === void 0 ? void 0 : type.ofType, options); | ||
} | ||
} | ||
if (graphql_1.isNonNullType(type)) { | ||
if ('ofType' in type) { | ||
if (graphql_1.isObjectType(type.ofType)) { | ||
return appendInsertText(field, type.ofType, options); | ||
} | ||
if (graphql_1.isListType(type.ofType)) { | ||
return appendInsertText(field, (_a = type === null || type === void 0 ? void 0 : type.ofType) === null || _a === void 0 ? void 0 : _a.ofType, options); | ||
} | ||
} | ||
} | ||
return null; | ||
}; | ||
function getSuggestionsForFieldNames(token, typeInfo, options) { | ||
var _a; | ||
if (typeInfo.parentType) { | ||
@@ -142,3 +178,3 @@ const parentType = typeInfo.parentType; | ||
} | ||
if (parentType === schema.getQueryType()) { | ||
if (parentType === ((_a = options === null || options === void 0 ? void 0 : options.schema) === null || _a === void 0 ? void 0 : _a.getQueryType())) { | ||
fields.push(graphql_2.SchemaMetaFieldDef, graphql_2.TypeMetaFieldDef); | ||
@@ -148,5 +184,9 @@ } | ||
var _a; | ||
return ({ | ||
if (field.name === 'securityAdvisories') { | ||
console.log(field); | ||
} | ||
const suggestion = { | ||
sortText: String(index) + field.name, | ||
label: field.name, | ||
insertTextFormat: vscode_languageserver_types_1.InsertTextFormat.Snippet, | ||
detail: String(field.type), | ||
@@ -159,3 +199,8 @@ documentation: (_a = field.description) !== null && _a !== void 0 ? _a : undefined, | ||
type: field.type, | ||
}); | ||
}; | ||
const insertText = getInsertText(field, options); | ||
if (insertText) { | ||
suggestion.insertText = field.name + insertText; | ||
} | ||
return suggestion; | ||
})); | ||
@@ -358,6 +403,6 @@ } | ||
if (!definitions[variableName]) { | ||
const label = token.string === '$' ? variableName : '$' + variableName; | ||
definitions[variableName] = { | ||
detail: variableType.toString(), | ||
label, | ||
insertText: token.string === '$' ? variableName : '$' + variableName, | ||
label: variableName, | ||
type: variableType, | ||
@@ -364,0 +409,0 @@ kind: vscode_languageserver_types_1.CompletionItemKind.Variable, |
@@ -7,2 +7,3 @@ import { DocumentNode, FragmentSpreadNode, NamedTypeNode } from 'graphql'; | ||
import { DefinitionQueryResult } from './getDefinition'; | ||
import { AutocompleteSuggestionOptions } from '.'; | ||
export declare class GraphQLLanguageService { | ||
@@ -14,3 +15,3 @@ _graphQLCache: GraphQLCache; | ||
getDiagnostics(query: string, uri: Uri, isRelayCompatMode?: boolean): Promise<Array<Diagnostic>>; | ||
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri): Promise<Array<CompletionItem>>; | ||
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri, options?: AutocompleteSuggestionOptions): Promise<Array<CompletionItem>>; | ||
getHoverInformation(query: string, position: IPosition, filePath: Uri, options?: HoverConfig): Promise<Hover['contents']>; | ||
@@ -17,0 +18,0 @@ getDefinition(query: string, position: IPosition, filePath: Uri): Promise<DefinitionQueryResult | null>; |
@@ -124,3 +124,3 @@ "use strict"; | ||
} | ||
getAutocompleteSuggestions(query, position, filePath) { | ||
getAutocompleteSuggestions(query, position, filePath, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -132,3 +132,3 @@ const projectConfig = this.getConfigForURI(filePath); | ||
if (schema) { | ||
return getAutocompleteSuggestions_1.getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo); | ||
return getAutocompleteSuggestions_1.getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo, options); | ||
} | ||
@@ -135,0 +135,0 @@ return []; |
@@ -6,4 +6,4 @@ export * from './autocompleteUtils'; | ||
export { getOutline } from './getOutline'; | ||
export { getHoverInformation } from './getHoverInformation'; | ||
export { getHoverInformation, HoverConfig } from './getHoverInformation'; | ||
export * from './GraphQLLanguageService'; | ||
//# sourceMappingURL=index.d.ts.map |
import { FragmentDefinitionNode, GraphQLDirective, GraphQLSchema } from 'graphql'; | ||
import { CompletionItem, AllTypeInfo, IPosition } from 'graphql-language-service-types'; | ||
import { CharacterStream, ContextToken, State, ContextTokenForCodeMirror } from 'graphql-language-service-parser'; | ||
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string): Array<CompletionItem>; | ||
export declare type AutocompleteSuggestionOptions = { | ||
fillLeafsOnComplete?: boolean; | ||
schema?: GraphQLSchema; | ||
}; | ||
export declare function getAutocompleteSuggestions(schema: GraphQLSchema, queryText: string, cursor: IPosition, contextToken?: ContextTokenForCodeMirror, fragmentDefs?: FragmentDefinitionNode[] | string, options?: AutocompleteSuggestionOptions): Array<CompletionItem>; | ||
export declare function getVariableCompletions(queryText: string, schema: GraphQLSchema, token: ContextToken): CompletionItem[]; | ||
@@ -6,0 +10,0 @@ export declare function getFragmentDefinitions(queryText: string): Array<FragmentDefinitionNode>; |
@@ -1,6 +0,7 @@ | ||
import { CompletionItemKind } from 'vscode-languageserver-types'; | ||
import { isInterfaceType, GraphQLInterfaceType, GraphQLObjectType, Kind, DirectiveLocation, } from 'graphql'; | ||
import { CompletionItemKind, InsertTextFormat, } from 'vscode-languageserver-types'; | ||
import { isInterfaceType, GraphQLInterfaceType, GraphQLObjectType, Kind, DirectiveLocation, isObjectType, isListType, isNonNullType, print, } from 'graphql'; | ||
import { GraphQLBoolean, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, SchemaMetaFieldDef, TypeMetaFieldDef, TypeNameMetaFieldDef, assertAbstractType, doTypesOverlap, getNamedType, getNullableType, isAbstractType, isCompositeType, isInputType, visit, parse, } from 'graphql'; | ||
import { CharacterStream, onlineParser, RuleKinds, } from 'graphql-language-service-parser'; | ||
import { forEachState, getDefinitionState, getFieldDef, hintList, objectValues, } from './autocompleteUtils'; | ||
import { buildSelectionSet, defaultGetDefaultFieldNames, } from 'graphql-language-service-utils'; | ||
const collectFragmentDefs = (op) => { | ||
@@ -19,4 +20,5 @@ const externalFragments = []; | ||
}; | ||
export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs) { | ||
export function getAutocompleteSuggestions(schema, queryText, cursor, contextToken, fragmentDefs, options) { | ||
var _a; | ||
const opts = Object.assign(Object.assign({}, options), { schema }); | ||
const token = contextToken || getTokenAtPosition(queryText, cursor); | ||
@@ -47,3 +49,3 @@ const state = token.state.kind === 'Invalid' ? token.state.prevState : token.state; | ||
kind === RuleKinds.ALIASED_FIELD) { | ||
return getSuggestionsForFieldNames(token, typeInfo, schema); | ||
return getSuggestionsForFieldNames(token, typeInfo, opts); | ||
} | ||
@@ -126,3 +128,37 @@ if (kind === RuleKinds.ARGUMENTS || | ||
} | ||
function getSuggestionsForFieldNames(token, typeInfo, schema) { | ||
const insertSuffix = ` {\n $1\n}`; | ||
const appendInsertText = (field, type, options) => { | ||
if (options === null || options === void 0 ? void 0 : options.fillLeafsOnComplete) { | ||
const selectionSet = buildSelectionSet(field, type, defaultGetDefaultFieldNames, options.schema); | ||
if (selectionSet) { | ||
return ` ${print(selectionSet)}`; | ||
} | ||
} | ||
return insertSuffix; | ||
}; | ||
const getInsertText = (field, options) => { | ||
var _a; | ||
const type = field.type; | ||
if (isCompositeType(type)) { | ||
return appendInsertText(field, type, options); | ||
} | ||
if (isListType(type)) { | ||
if ('ofType' in type) { | ||
return appendInsertText(field, type === null || type === void 0 ? void 0 : type.ofType, options); | ||
} | ||
} | ||
if (isNonNullType(type)) { | ||
if ('ofType' in type) { | ||
if (isObjectType(type.ofType)) { | ||
return appendInsertText(field, type.ofType, options); | ||
} | ||
if (isListType(type.ofType)) { | ||
return appendInsertText(field, (_a = type === null || type === void 0 ? void 0 : type.ofType) === null || _a === void 0 ? void 0 : _a.ofType, options); | ||
} | ||
} | ||
} | ||
return null; | ||
}; | ||
function getSuggestionsForFieldNames(token, typeInfo, options) { | ||
var _a; | ||
if (typeInfo.parentType) { | ||
@@ -137,3 +173,3 @@ const parentType = typeInfo.parentType; | ||
} | ||
if (parentType === schema.getQueryType()) { | ||
if (parentType === ((_a = options === null || options === void 0 ? void 0 : options.schema) === null || _a === void 0 ? void 0 : _a.getQueryType())) { | ||
fields.push(SchemaMetaFieldDef, TypeMetaFieldDef); | ||
@@ -143,5 +179,9 @@ } | ||
var _a; | ||
return ({ | ||
if (field.name === 'securityAdvisories') { | ||
console.log(field); | ||
} | ||
const suggestion = { | ||
sortText: String(index) + field.name, | ||
label: field.name, | ||
insertTextFormat: InsertTextFormat.Snippet, | ||
detail: String(field.type), | ||
@@ -154,3 +194,8 @@ documentation: (_a = field.description) !== null && _a !== void 0 ? _a : undefined, | ||
type: field.type, | ||
}); | ||
}; | ||
const insertText = getInsertText(field, options); | ||
if (insertText) { | ||
suggestion.insertText = field.name + insertText; | ||
} | ||
return suggestion; | ||
})); | ||
@@ -353,6 +398,6 @@ } | ||
if (!definitions[variableName]) { | ||
const label = token.string === '$' ? variableName : '$' + variableName; | ||
definitions[variableName] = { | ||
detail: variableType.toString(), | ||
label, | ||
insertText: token.string === '$' ? variableName : '$' + variableName, | ||
label: variableName, | ||
type: variableType, | ||
@@ -359,0 +404,0 @@ kind: CompletionItemKind.Variable, |
@@ -7,2 +7,3 @@ import { DocumentNode, FragmentSpreadNode, NamedTypeNode } from 'graphql'; | ||
import { DefinitionQueryResult } from './getDefinition'; | ||
import { AutocompleteSuggestionOptions } from '.'; | ||
export declare class GraphQLLanguageService { | ||
@@ -14,3 +15,3 @@ _graphQLCache: GraphQLCache; | ||
getDiagnostics(query: string, uri: Uri, isRelayCompatMode?: boolean): Promise<Array<Diagnostic>>; | ||
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri): Promise<Array<CompletionItem>>; | ||
getAutocompleteSuggestions(query: string, position: IPosition, filePath: Uri, options?: AutocompleteSuggestionOptions): Promise<Array<CompletionItem>>; | ||
getHoverInformation(query: string, position: IPosition, filePath: Uri, options?: HoverConfig): Promise<Hover['contents']>; | ||
@@ -17,0 +18,0 @@ getDefinition(query: string, position: IPosition, filePath: Uri): Promise<DefinitionQueryResult | null>; |
@@ -121,3 +121,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
getAutocompleteSuggestions(query, position, filePath) { | ||
getAutocompleteSuggestions(query, position, filePath, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -129,3 +129,3 @@ const projectConfig = this.getConfigForURI(filePath); | ||
if (schema) { | ||
return getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo); | ||
return getAutocompleteSuggestions(schema, query, position, undefined, fragmentInfo, options); | ||
} | ||
@@ -132,0 +132,0 @@ return []; |
@@ -6,4 +6,4 @@ export * from './autocompleteUtils'; | ||
export { getOutline } from './getOutline'; | ||
export { getHoverInformation } from './getHoverInformation'; | ||
export { getHoverInformation, HoverConfig } from './getHoverInformation'; | ||
export * from './GraphQLLanguageService'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "graphql-language-service-interface", | ||
"version": "2.9.5", | ||
"version": "2.9.6-canary-b5aba87e.0", | ||
"description": "Interface to the GraphQL Language Service", | ||
@@ -34,3 +34,3 @@ "contributors": [ | ||
"graphql-language-service-types": "^1.8.6", | ||
"graphql-language-service-utils": "^2.6.3", | ||
"graphql-language-service-utils": "^2.7.0-canary-b5aba87e.0", | ||
"vscode-languageserver-types": "^3.15.1" | ||
@@ -37,0 +37,0 @@ }, |
@@ -24,2 +24,7 @@ /** | ||
const suggestionCommand = { | ||
command: 'editor.action.triggerSuggest', | ||
title: 'Suggestions', | ||
}; | ||
describe('getAutocompleteSuggestions', () => { | ||
@@ -54,2 +59,4 @@ let schema: GraphQLSchema; | ||
.map(suggestion => { | ||
// TODO: A PR where we do `const { type, ..rest} = suggestion; return rest;` | ||
// and validate the entire completion object - kinds, documentation, etc | ||
const response = { label: suggestion.label } as CompletionItem; | ||
@@ -59,5 +66,11 @@ if (suggestion.detail) { | ||
} | ||
// if(suggestion.documentation) { | ||
// response.documentation = String(suggestion.documentation) | ||
// } | ||
if (suggestion.insertText) { | ||
response.insertText = suggestion.insertText; | ||
} | ||
if (suggestion.insertTextFormat) { | ||
response.insertTextFormat = suggestion.insertTextFormat; | ||
} | ||
if (suggestion.command) { | ||
response.command = suggestion.command; | ||
} | ||
return response; | ||
@@ -200,3 +213,10 @@ }); | ||
const result = testSuggestions('{ human (', new Position(0, 9)); | ||
expect(result).toEqual([{ label: 'id', detail: 'String!' }]); | ||
expect(result).toEqual([ | ||
{ | ||
label: 'id', | ||
detail: 'String!', | ||
insertText: 'id: ', | ||
command: suggestionCommand, | ||
}, | ||
]); | ||
}); | ||
@@ -206,3 +226,10 @@ | ||
const result = testSuggestions('{ aliasTest: human( ', new Position(0, 20)); | ||
expect(result).toEqual([{ label: 'id', detail: 'String!' }]); | ||
expect(result).toEqual([ | ||
{ | ||
label: 'id', | ||
detail: 'String!', | ||
command: suggestionCommand, | ||
insertText: 'id: ', | ||
}, | ||
]); | ||
}); | ||
@@ -292,3 +319,5 @@ | ||
); | ||
expect(result).toEqual([{ label: '$ep', detail: 'Episode' }]); | ||
expect(result).toEqual([ | ||
{ label: 'ep', insertText: '$ep', detail: 'Episode' }, | ||
]); | ||
}); | ||
@@ -302,4 +331,4 @@ | ||
expect(result).toEqual([ | ||
{ label: '$episode', detail: 'Episode' }, | ||
{ label: 'EMPIRE', detail: 'Episode' }, | ||
{ label: 'episode', detail: 'Episode', insertText: '$episode' }, | ||
{ label: 'JEDI', detail: 'Episode' }, | ||
@@ -306,0 +335,0 @@ { label: 'NEWHOPE', detail: 'Episode' }, |
@@ -9,3 +9,6 @@ /** | ||
*/ | ||
import { CompletionItemKind } from 'vscode-languageserver-types'; | ||
import { | ||
CompletionItemKind, | ||
InsertTextFormat, | ||
} from 'vscode-languageserver-types'; | ||
@@ -28,2 +31,7 @@ import { | ||
GraphQLArgument, | ||
isObjectType, | ||
isListType, | ||
isNonNullType, | ||
GraphQLOutputType, | ||
print, | ||
} from 'graphql'; | ||
@@ -74,2 +82,6 @@ | ||
} from './autocompleteUtils'; | ||
import { | ||
buildSelectionSet, | ||
defaultGetDefaultFieldNames, | ||
} from 'graphql-language-service-utils'; | ||
@@ -93,2 +105,7 @@ const collectFragmentDefs = (op: string | undefined) => { | ||
export type AutocompleteSuggestionOptions = { | ||
fillLeafsOnComplete?: boolean; | ||
schema?: GraphQLSchema; | ||
}; | ||
/** | ||
@@ -104,3 +121,8 @@ * Given GraphQLSchema, queryText, and context of the current position within | ||
fragmentDefs?: FragmentDefinitionNode[] | string, | ||
options?: AutocompleteSuggestionOptions, | ||
): Array<CompletionItem> { | ||
const opts = { | ||
...options, | ||
schema, | ||
}; | ||
const token: ContextToken = | ||
@@ -119,3 +141,2 @@ contextToken || getTokenAtPosition(queryText, cursor); | ||
const step = state.step; | ||
const typeInfo = getTypeInfo(schema, token.state); | ||
@@ -153,3 +174,3 @@ // Definition kinds | ||
) { | ||
return getSuggestionsForFieldNames(token, typeInfo, schema); | ||
return getSuggestionsForFieldNames(token, typeInfo, opts); | ||
} | ||
@@ -280,2 +301,54 @@ | ||
const insertSuffix = ` {\n $1\n}`; | ||
const appendInsertText = ( | ||
field: GraphQLField<null, null>, | ||
type: GraphQLOutputType, | ||
options?: AutocompleteSuggestionOptions, | ||
) => { | ||
if (options?.fillLeafsOnComplete) { | ||
const selectionSet = buildSelectionSet( | ||
field, | ||
type, | ||
defaultGetDefaultFieldNames, | ||
options.schema, | ||
); | ||
if (selectionSet) { | ||
return ` ${print(selectionSet)}`; | ||
} | ||
} | ||
return insertSuffix; | ||
}; | ||
const getInsertText = ( | ||
field: GraphQLField<null, null>, | ||
options?: AutocompleteSuggestionOptions, | ||
) => { | ||
const type = field.type; | ||
if (isCompositeType(type)) { | ||
return appendInsertText(field, type, options); | ||
} | ||
if (isListType(type)) { | ||
if ('ofType' in type) { | ||
return appendInsertText(field, type?.ofType, options); | ||
} | ||
} | ||
if (isNonNullType(type)) { | ||
if ('ofType' in type) { | ||
if (isObjectType(type.ofType)) { | ||
return appendInsertText(field, type.ofType, options); | ||
} | ||
if (isListType(type.ofType)) { | ||
return appendInsertText( | ||
field, | ||
type?.ofType?.ofType as GraphQLOutputType, | ||
options, | ||
); | ||
} | ||
} | ||
} | ||
return null; | ||
}; | ||
// Helper functions to get suggestions for each kinds | ||
@@ -285,3 +358,3 @@ function getSuggestionsForFieldNames( | ||
typeInfo: AllTypeInfo, | ||
schema: GraphQLSchema, | ||
options?: AutocompleteSuggestionOptions, | ||
): Array<CompletionItem> { | ||
@@ -301,3 +374,3 @@ if (typeInfo.parentType) { | ||
} | ||
if (parentType === schema.getQueryType()) { | ||
if (parentType === options?.schema?.getQueryType()) { | ||
fields.push(SchemaMetaFieldDef, TypeMetaFieldDef); | ||
@@ -307,14 +380,27 @@ } | ||
token, | ||
fields.map<CompletionItem>((field, index) => ({ | ||
// This will sort the fields in the same order they are listed in the schema | ||
sortText: String(index) + field.name, | ||
label: field.name, | ||
detail: String(field.type), | ||
documentation: field.description ?? undefined, | ||
deprecated: Boolean(field.deprecationReason), | ||
isDeprecated: Boolean(field.deprecationReason), | ||
deprecationReason: field.deprecationReason, | ||
kind: CompletionItemKind.Field, | ||
type: field.type, | ||
})), | ||
fields.map<CompletionItem>((field, index) => { | ||
if (field.name === 'securityAdvisories') { | ||
console.log(field); | ||
} | ||
const suggestion: CompletionItem = { | ||
// This will sort the fields in the same order they are listed in the schema | ||
sortText: String(index) + field.name, | ||
label: field.name, | ||
insertTextFormat: InsertTextFormat.Snippet, | ||
detail: String(field.type), | ||
documentation: field.description ?? undefined, | ||
deprecated: Boolean(field.deprecationReason), | ||
isDeprecated: Boolean(field.deprecationReason), | ||
deprecationReason: field.deprecationReason, | ||
kind: CompletionItemKind.Field, | ||
type: field.type, | ||
}; | ||
const insertText = getInsertText(field, options); | ||
if (insertText) { | ||
suggestion.insertText = field.name + insertText; | ||
} | ||
return suggestion; | ||
}), | ||
); | ||
@@ -626,6 +712,7 @@ } | ||
// append `$` if the `token.string` is not already `$` | ||
const label = token.string === '$' ? variableName : '$' + variableName; | ||
definitions[variableName] = { | ||
detail: variableType.toString(), | ||
label, | ||
insertText: token.string === '$' ? variableName : '$' + variableName, | ||
label: variableName, // keep label the same for `codemirror-graphql` | ||
type: variableType, | ||
@@ -632,0 +719,0 @@ kind: CompletionItemKind.Variable, |
@@ -50,2 +50,3 @@ /** | ||
import { getASTNodeAtPosition } from 'graphql-language-service-utils'; | ||
import { AutocompleteSuggestionOptions } from '.'; | ||
@@ -227,2 +228,3 @@ const { | ||
filePath: Uri, | ||
options?: AutocompleteSuggestionOptions, | ||
): Promise<Array<CompletionItem>> { | ||
@@ -246,2 +248,3 @@ const projectConfig = this.getConfigForURI(filePath); | ||
fragmentInfo, | ||
options, | ||
); | ||
@@ -248,0 +251,0 @@ } |
@@ -19,4 +19,4 @@ /** | ||
export { getOutline } from './getOutline'; | ||
export { getHoverInformation } from './getHoverInformation'; | ||
export { getHoverInformation, HoverConfig } from './getHoverInformation'; | ||
export * from './GraphQLLanguageService'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
395004
6855
2