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

fix: adjust documentation display (#126)

* adjust documentation display

* test fix

Changed files
+26 -18
.changeset
packages
example
graphqlsp
test
+5
.changeset/bright-news-agree.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Adjust documentation display
+1 -1
packages/example/src/Pokemon.ts
···
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
-
import { gql } from '@urql/core';
+
import { createClient, gql } from '@urql/core';
export const PokemonFields = gql`
fragment pokemonFields on Pokemon {
+1 -1
packages/example/src/index.ts
···
.query(PokemonQuery, { id: '' })
.toPromise()
.then(result => {
-
result.data?.pokemon;
+
result.data?.pokemons;
});
+13 -10
packages/graphqlsp/src/quickInfo.ts
···
import { resolveTemplate } from './ast/resolve';
import { getToken } from './ast/token';
import { Cursor } from './ast/cursor';
+
import { Logger } from '.';
export function getGraphQLQuickInfo(
filename: string,
···
schema: { current: GraphQLSchema | null },
info: ts.server.PluginCreateInfo
): ts.QuickInfo | undefined {
+
const logger: Logger = (msg: string) =>
+
info.project.projectService.logger.info(`[GraphQLSP] ${msg}`);
const tagTemplate = info.config.template || 'gql';
const isCallExpression = info.config.templateIsCallExpression ?? false;
···
start: cursorPosition,
length: 1,
},
-
kindModifiers: '',
-
displayParts: Array.isArray(hoverInfo)
-
? hoverInfo.map(item => ({ kind: '', text: item as string }))
-
: [{ kind: '', text: hoverInfo as string }],
+
kindModifiers: 'text',
+
documentation: Array.isArray(hoverInfo)
+
? hoverInfo.map(item => ({ kind: 'text', text: item as string }))
+
: [{ kind: 'text', text: hoverInfo as string }],
};
} else if (ts.isTaggedTemplateExpression(node)) {
const { template, tag } = node;
···
);
return {
-
kind: ts.ScriptElementKind.string,
+
kind: ts.ScriptElementKind.label,
textSpan: {
start: cursorPosition,
length: 1,
},
-
kindModifiers: '',
-
displayParts: Array.isArray(hoverInfo)
-
? hoverInfo.map(item => ({ kind: '', text: item as string }))
-
: [{ kind: '', text: hoverInfo as string }],
-
};
+
kindModifiers: 'text',
+
documentation: Array.isArray(hoverInfo)
+
? hoverInfo.map(item => ({ kind: 'text', text: item as string }))
+
: [{ kind: 'text', text: hoverInfo as string }],
+
} as ts.QuickInfo;
} else {
return undefined;
}
+2 -2
test/e2e/client-preset.test.ts
···
expect(res).toBeDefined();
expect(typeof res?.body).toEqual('object');
-
expect(res?.body.displayString).toEqual(`Pokemon.name: String!`);
+
expect(res?.body.documentation).toEqual(`Pokemon.name: String!`);
}, 30000);
it('gives quick-info with documents', async () => {
···
expect(res).toBeDefined();
expect(typeof res?.body).toEqual('object');
-
expect(res?.body.displayString).toEqual(
+
expect(res?.body.documentation).toEqual(
`Query.pokemons: [Pokemon]
List out all Pokémon, optionally in pages`
+1 -1
test/e2e/combinations.test.ts
···
expect(res).toBeDefined();
expect(typeof res?.body).toEqual('object');
-
expect(res?.body.displayString).toEqual(
+
expect(res?.body.documentation).toEqual(
`Query.posts: [Post]\n\nList out all posts`
);
}, 30000);
+3 -3
test/e2e/graphqlsp.test.ts
···
.find(resp => resp.type === 'response' && resp.command === 'quickinfo');
expect(res).toBeDefined();
expect(typeof res?.body).toEqual('object');
-
expect(res?.body.displayString).toEqual(`Query.posts: [Post]
-
-
List out all posts`);
+
expect(res?.body.documentation).toEqual(
+
`Query.posts: [Post]\n\nList out all posts`
+
);
}, 7500);
});