Skip to content

fix: correct validation diagnostic highlight range#4319

Open
cyphercodes wants to merge 1 commit into
graphql:mainfrom
cyphercodes:fix/graphql-language-service-validation-highlight-range
Open

fix: correct validation diagnostic highlight range#4319
cyphercodes wants to merge 1 commit into
graphql:mainfrom
cyphercodes:fix/graphql-language-service-validation-highlight-range

Conversation

@cyphercodes
Copy link
Copy Markdown

@cyphercodes cyphercodes commented May 23, 2026

Issue

The GraphQL language service reports validation diagnostics with a range that is one character too long. In VS Code / LSP clients this makes an invalid field underline include the following whitespace, instead of stopping at the invalid field name. This reproduces the screenshot and report in #4234.

Why this fixes it

graphql-js locations are 1-based, while LSP ranges are 0-based and end-exclusive. The previous code converted the start column to 0-based but computed the end column from the original 1-based column, so the diagnostic end position was shifted one character too far.

This PR computes the LSP start position first, then adds the highlighted AST node length to that zero-based start character. The resulting end position stops exactly after the invalid token and no longer includes trailing whitespace.

Manual verification steps

  1. Use the GraphQL language service with a schema that does not contain a title field at the queried location.

  2. Open this query:

    query {
      title 
    }
  3. Trigger validation diagnostics in the editor / LSP client.

  4. Confirm the validation underline starts at the t in title and ends immediately after title; the following space before the newline is not highlighted.

Automated verification

  • yarn vitest run packages/graphql-language-service/src/interface/__tests__/getDiagnostics.test.ts
  • yarn tsgo --build packages/graphql-language-service/tsconfig.json
  • yarn vitest run packages/graphql-language-service/src
  • yarn turbo run test --filter=graphql-language-service
  • yarn turbo run types:check --filter=graphql-language-service
  • yarn oxfmt --check packages/graphql-language-service/src/interface/getDiagnostics.ts packages/graphql-language-service/src/interface/__tests__/getDiagnostics.test.ts .changeset/loud-fields-dance.md
  • git diff --check

Fixes #4234.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 23, 2026

🦋 Changeset detected

Latest commit: 2717712

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

@linux-foundation-easycla
Copy link
Copy Markdown

CLA Not Signed

@trevor-scheer
Copy link
Copy Markdown
Contributor

@cyphercodes need you to sign the CLA before I can land this.

Can you please update your PR description to explain the issue, why this fixes it, and very clear steps for me to manually reproduce and verify the issue and your fix? The "Tests" section in your PR description is not helpful to me as a reviewer at all.

@cyphercodes
Copy link
Copy Markdown
Author

Updated the PR description with:

  • the reported validation-highlight issue,
  • why the zero-based LSP range calculation fixes it,
  • manual reproduction/verification steps,
  • the automated verification commands already run for this branch.

@trevor-scheer
Copy link
Copy Markdown
Contributor

@cyphercodes thanks. Still need the CLA signed. See the bot comment on this PR for more info.

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.

[lsp-server] 🐞 Validation highlight offset

2 participants