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(graphql-language-service): fix off by one on hover #3882

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bensengupta
Copy link

@bensengupta bensengupta commented Mar 16, 2025

Hey, thanks for making this! This PR fixes a small off-by-one issue when hovering.

Details I am using graphql-language-service-cli in Neovim. The issue is illustrated below:

Hover, no information (incorrect, should show info)
Screenshot 2025-03-16 at 6 37 17 PM
Hover, shows information (correct)
Screenshot 2025-03-16 at 6 37 22 PM
Hover, shows information (incorrect, should not show info)
Screenshot 2025-03-16 at 6 37 27 PM
Hover, no information (correct)
Screenshot 2025-03-16 at 6 37 31 PM

Copy link

changeset-bot bot commented Mar 16, 2025

🦋 Changeset detected

Latest commit: b7e0a66

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
graphql-language-service Patch
codemirror-graphql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

linux-foundation-easycla bot commented Mar 16, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@bensengupta bensengupta marked this pull request as ready for review March 16, 2025 22:49
@bensengupta
Copy link
Author

Seems like there is a race condition in the tests. Am unable to reproduce test failure locally.

Maybe replace this

if (!existsSync(this._tmpDirBase)) {
void mkdirSync(this._tmpDirBase);
}

with this?

    try {
      void mkdirSync(this._tmpDirBase);
    } catch (err) {
      if (err instanceof Error && 'code' in err && err.code === 'EEXIST') {
        return;
      }
      throw err;
    }

@@ -176,14 +176,15 @@ export function getContextAtPosition(
schema: GraphQLSchema,
contextToken?: ContextToken,
options?: { mode?: GraphQLDocumentMode; uri?: string },
offset = 0,
Copy link
Author

Choose a reason for hiding this comment

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

Just to explain this change: getContextAtPosition is used in 2 places:

In getHoverInformation, the offset needs to be changed to 0 to fix the off-by-one problem on hover.

const context = getContextAtPosition(queryText, cursor, schema, contextToken);

In getAutocompleteSuggestions, the offset needs to be kept at 1 as the current behavior is correct.

const context = getContextAtPosition(
queryText,
cursor,
schema,
contextToken,
options,
1,
);

@bensengupta
Copy link
Author

Hey @acao @dimaMachina, any chance one of you could have a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant