Skip to content

Commit

Permalink
fix: Hover docs were offset one position (#3149)
Browse files Browse the repository at this point in the history
  • Loading branch information
mskelton committed Jun 11, 2023
1 parent e33c665 commit d9e5089
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-cats-hammer.md
@@ -0,0 +1,5 @@
---
'graphql-language-service': patch
---

Fix hover docs being off by one position.
Expand Up @@ -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;
Expand Down Expand Up @@ -963,14 +963,15 @@ function getSuggestionsForDirective(
export function getTokenAtPosition(
queryText: string,
cursor: IPosition,
offset = 0,
): ContextToken {
let styleAtCursor = null;
let stateAtCursor = null;
let stringAtCursor = null;
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 };
Expand Down

0 comments on commit d9e5089

Please sign in to comment.