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

display documentation for fields and fragments (#31)

Changed files
+36 -13
.changeset
src
+5
.changeset/grumpy-toes-serve.md
···
+
---
+
'@0no-co/graphqlsp': minor
+
---
+
+
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
···
isTemplateExpression,
isImportTypeNode,
ImportTypeNode,
+
CompletionEntry,
} from 'typescript';
import {
getHoverInformation,
···
if (!foundToken || !schema.current) return originalCompletions;
-
const suggestions = getAutocompleteSuggestions(
-
schema.current,
-
text,
-
new Cursor(foundToken.line, foundToken.start)
-
);
-
let fragments: Array<FragmentDefinitionNode> = [];
try {
const parsed = parse(text);
···
) as Array<FragmentDefinitionNode>;
} catch (e) {}
+
const suggestions = getAutocompleteSuggestions(
+
schema.current,
+
text,
+
new Cursor(foundToken.line, foundToken.start),
+
undefined,
+
fragments
+
);
+
const result: ts.WithMetadata<ts.CompletionInfo> = {
isGlobalCompletion: false,
isMemberCompletion: false,
isNewIdentifierLocation: false,
-
// TODO: check whether we can add descriptions to the entries
entries: [
-
...suggestions.map(suggestion => ({
-
kind: ScriptElementKind.variableElement,
-
name: suggestion.label,
-
kindModifiers: 'declare',
-
sortText: suggestion.sortText || '0',
-
})),
+
...suggestions.map(
+
suggestion =>
+
({
+
kind: ScriptElementKind.variableElement,
+
name: suggestion.label,
+
kindModifiers: 'declare',
+
sortText: suggestion.sortText || '0',
+
labelDetails: {
+
detail:
+
' ' + suggestion.documentation ||
+
suggestion.labelDetails?.detail ||
+
suggestion.type,
+
description:
+
' ' + suggestion.labelDetails?.description ||
+
suggestion.documentation,
+
},
+
} as CompletionEntry)
+
),
...fragments.map(fragment => ({
kind: ScriptElementKind.variableElement,
name: fragment.name.value,
insertText: '...' + fragment.name.value,
kindModifiers: 'declare',
sortText: '0',
+
labelDetails: {
+
detail: ' on type ' + fragment.typeCondition.name.value,
+
description: ' on type ' + fragment.typeCondition.name.value,
+
},
})),
...originalCompletions.entries,
],