From 89a1f4108c0ded1225d47afc2566f245854b9a2b Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 5 Dec 2023 10:24:10 +0100 Subject: [PATCH 1/2] adjust documentation display --- .changeset/bright-news-agree.md | 5 +++++ packages/example/src/Pokemon.ts | 2 +- packages/example/src/index.ts | 2 +- packages/graphqlsp/src/quickInfo.ts | 23 +++++++++++++---------- test/e2e/combinations.test.ts | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 .changeset/bright-news-agree.md diff --git a/.changeset/bright-news-agree.md b/.changeset/bright-news-agree.md new file mode 100644 index 00000000..23c418e5 --- /dev/null +++ b/.changeset/bright-news-agree.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphqlsp': patch +--- + +Adjust documentation display diff --git a/packages/example/src/Pokemon.ts b/packages/example/src/Pokemon.ts index 9c254fb9..f2e4b9bb 100644 --- a/packages/example/src/Pokemon.ts +++ b/packages/example/src/Pokemon.ts @@ -1,5 +1,5 @@ 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 { diff --git a/packages/example/src/index.ts b/packages/example/src/index.ts index 4316d24a..77afc182 100644 --- a/packages/example/src/index.ts +++ b/packages/example/src/index.ts @@ -15,5 +15,5 @@ client .query(PokemonQuery, { id: '' }) .toPromise() .then(result => { - result.data?.pokemon; + result.data?.pokemons; }); diff --git a/packages/graphqlsp/src/quickInfo.ts b/packages/graphqlsp/src/quickInfo.ts index 7a0bd57a..2457f55c 100644 --- a/packages/graphqlsp/src/quickInfo.ts +++ b/packages/graphqlsp/src/quickInfo.ts @@ -11,6 +11,7 @@ import { import { resolveTemplate } from './ast/resolve'; import { getToken } from './ast/token'; import { Cursor } from './ast/cursor'; +import { Logger } from '.'; export function getGraphQLQuickInfo( filename: string, @@ -18,6 +19,8 @@ export function getGraphQLQuickInfo( 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; @@ -51,10 +54,10 @@ export function getGraphQLQuickInfo( 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; @@ -87,16 +90,16 @@ export function getGraphQLQuickInfo( ); 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; } diff --git a/test/e2e/combinations.test.ts b/test/e2e/combinations.test.ts index 64eb062a..119bd6a8 100644 --- a/test/e2e/combinations.test.ts +++ b/test/e2e/combinations.test.ts @@ -120,7 +120,7 @@ describe('Fragment + operations', () => { 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); From 4f3f32f5626810f6c445241aea44ff7d51b70d2e Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 5 Dec 2023 10:30:40 +0100 Subject: [PATCH 2/2] test fix --- test/e2e/client-preset.test.ts | 4 ++-- test/e2e/graphqlsp.test.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/e2e/client-preset.test.ts b/test/e2e/client-preset.test.ts index 3fa4ce00..8131e859 100644 --- a/test/e2e/client-preset.test.ts +++ b/test/e2e/client-preset.test.ts @@ -148,7 +148,7 @@ describe('Fragment + operations', () => { 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 () => { @@ -174,7 +174,7 @@ describe('Fragment + operations', () => { 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` diff --git a/test/e2e/graphqlsp.test.ts b/test/e2e/graphqlsp.test.ts index a6f7fd1d..015ec5a1 100644 --- a/test/e2e/graphqlsp.test.ts +++ b/test/e2e/graphqlsp.test.ts @@ -131,8 +131,8 @@ describe('simple', () => { .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); });