diff --git a/.changeset/metal-cats-hammer.md b/.changeset/metal-cats-hammer.md new file mode 100644 index 00000000000..2ab740fdb9a --- /dev/null +++ b/.changeset/metal-cats-hammer.md @@ -0,0 +1,5 @@ +--- +'graphql-language-service': patch +--- + +Fix hover docs being off by one position. diff --git a/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts b/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts index 6600b2f95af..dcfa719c5d8 100644 --- a/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts +++ b/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts @@ -165,7 +165,7 @@ export function getAutocompleteSuggestions( schema, }; const token: ContextToken = - contextToken || getTokenAtPosition(queryText, cursor); + contextToken || getTokenAtPosition(queryText, cursor, 1); const state = token.state.kind === 'Invalid' ? token.state.prevState : token.state; @@ -963,6 +963,7 @@ function getSuggestionsForDirective( export function getTokenAtPosition( queryText: string, cursor: IPosition, + offset = 0, ): ContextToken { let styleAtCursor = null; let stateAtCursor = null; @@ -970,7 +971,7 @@ export function getTokenAtPosition( const token = runOnlineParser(queryText, (stream, state, style, index) => { if ( index === cursor.line && - stream.getCurrentPosition() >= cursor.character + stream.getCurrentPosition() + offset >= cursor.character + 1 ) { styleAtCursor = style; stateAtCursor = { ...state };