Skip to content

Commit 3b5c309

Browse files
fix(graphql-language-service): return null instead of empty contents array when hover results are empty (#3913)
* fix(graphql-language-service): return `null` instead of empty `contents` * Create wild-paws-smash.md --------- Co-authored-by: Dimitri POSTOLOV <[email protected]>
1 parent 2b5d200 commit 3b5c309

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.changeset/wild-paws-smash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"graphql-language-service-server": patch
3+
---
4+
5+
return `null` instead of an empty `contents` array when hover results are empty

packages/graphql-language-service-server/src/MessageProcessor.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,9 @@ export class MessageProcessor {
656656

657657
public async handleHoverRequest(
658658
params: TextDocumentPositionParams,
659-
): Promise<Hover> {
659+
): Promise<Hover | null> {
660660
if (!this._isInitialized) {
661-
return { contents: [] };
661+
return null;
662662
}
663663

664664
this.validateDocumentAndPosition(params);
@@ -667,7 +667,7 @@ export class MessageProcessor {
667667

668668
const cachedDocument = this._getCachedDocument(textDocument.uri);
669669
if (!cachedDocument) {
670-
return { contents: [] };
670+
return null;
671671
}
672672

673673
const found = cachedDocument.contents.find(content => {
@@ -679,7 +679,7 @@ export class MessageProcessor {
679679

680680
// If there is no GraphQL query in this file, return an empty result.
681681
if (!found) {
682-
return { contents: [] };
682+
return null;
683683
}
684684

685685
const { query, range } = found;

packages/graphql-language-service-server/src/__tests__/MessageProcessor.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ describe('MessageProcessor', () => {
553553
messageProcessor._getCachedDocument = (_uri: string) => null;
554554

555555
const result = await messageProcessor.handleHoverRequest(test);
556-
expect(result).toEqual({ contents: [] });
556+
expect(result).toBeNull();
557557
});
558558
it('handles provided config', async () => {
559559
const msgProcessor = new MessageProcessor({

0 commit comments

Comments
 (0)