Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

display documentation for fields and fragments (#31)

authored by

Jovi De Croock and committed by
GitHub
e2faba4b 39f31ccb

+36 -13
+5
.changeset/grumpy-toes-serve.md
··· 1 + --- 2 + '@0no-co/graphqlsp': minor 3 + --- 4 + 5 + Display some documentation alongside fields and fragments, for fields it will show the documentation or the type and for fragmentSpreads the typeCondition will be displayed
+31 -13
src/index.ts
··· 8 8 isTemplateExpression, 9 9 isImportTypeNode, 10 10 ImportTypeNode, 11 + CompletionEntry, 11 12 } from 'typescript'; 12 13 import { 13 14 getHoverInformation, ··· 305 306 306 307 if (!foundToken || !schema.current) return originalCompletions; 307 308 308 - const suggestions = getAutocompleteSuggestions( 309 - schema.current, 310 - text, 311 - new Cursor(foundToken.line, foundToken.start) 312 - ); 313 - 314 309 let fragments: Array<FragmentDefinitionNode> = []; 315 310 try { 316 311 const parsed = parse(text); ··· 319 314 ) as Array<FragmentDefinitionNode>; 320 315 } catch (e) {} 321 316 317 + const suggestions = getAutocompleteSuggestions( 318 + schema.current, 319 + text, 320 + new Cursor(foundToken.line, foundToken.start), 321 + undefined, 322 + fragments 323 + ); 324 + 322 325 const result: ts.WithMetadata<ts.CompletionInfo> = { 323 326 isGlobalCompletion: false, 324 327 isMemberCompletion: false, 325 328 isNewIdentifierLocation: false, 326 - // TODO: check whether we can add descriptions to the entries 327 329 entries: [ 328 - ...suggestions.map(suggestion => ({ 329 - kind: ScriptElementKind.variableElement, 330 - name: suggestion.label, 331 - kindModifiers: 'declare', 332 - sortText: suggestion.sortText || '0', 333 - })), 330 + ...suggestions.map( 331 + suggestion => 332 + ({ 333 + kind: ScriptElementKind.variableElement, 334 + name: suggestion.label, 335 + kindModifiers: 'declare', 336 + sortText: suggestion.sortText || '0', 337 + labelDetails: { 338 + detail: 339 + ' ' + suggestion.documentation || 340 + suggestion.labelDetails?.detail || 341 + suggestion.type, 342 + description: 343 + ' ' + suggestion.labelDetails?.description || 344 + suggestion.documentation, 345 + }, 346 + } as CompletionEntry) 347 + ), 334 348 ...fragments.map(fragment => ({ 335 349 kind: ScriptElementKind.variableElement, 336 350 name: fragment.name.value, 337 351 insertText: '...' + fragment.name.value, 338 352 kindModifiers: 'declare', 339 353 sortText: '0', 354 + labelDetails: { 355 + detail: ' on type ' + fragment.typeCondition.name.value, 356 + description: ' on type ' + fragment.typeCondition.name.value, 357 + }, 340 358 })), 341 359 ...originalCompletions.entries, 342 360 ],