Skip to content

Commit

Permalink
fix: adjust documentation display (#126)
Browse files Browse the repository at this point in the history
* adjust documentation display

* test fix
  • Loading branch information
JoviDeCroock authored Dec 21, 2023
1 parent a2180af commit 01ade44
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-news-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Adjust documentation display
2 changes: 1 addition & 1 deletion packages/example/src/Pokemon.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ client
.query(PokemonQuery, { id: '' })
.toPromise()
.then(result => {
result.data?.pokemon;
result.data?.pokemons;
});
23 changes: 13 additions & 10 deletions packages/graphqlsp/src/quickInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import {
import { resolveTemplate } from './ast/resolve';
import { getToken } from './ast/token';
import { Cursor } from './ast/cursor';
import { Logger } from '.';

export function getGraphQLQuickInfo(
filename: string,
cursorPosition: number,
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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/client-preset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/combinations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/graphqlsp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 01ade44

Please sign in to comment.