Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust documentation display #126

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm admittedly a bit confused about this. It looks like displayString may be reserved for code-like references, while documentation is only for "meta" information?

This could correspond to the hover string, where displayString might be displayed in monospace, while documentation is the smaller sans-serif text below it, if I'm not mistaken

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a tad smaller... Not sure how to combine displayString though as that expects code it looks like

? 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);
});