fix: correct validation diagnostic highlight range#4319
Open
cyphercodes wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: 2717712 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
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. |
Author
|
Updated the PR description with:
|
Contributor
|
@cyphercodes thanks. Still need the CLA signed. See the bot comment on this PR for more info. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-jslocations 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
Use the GraphQL language service with a schema that does not contain a
titlefield at the queried location.Open this query:
Trigger validation diagnostics in the editor / LSP client.
Confirm the validation underline starts at the
tintitleand ends immediately aftertitle; the following space before the newline is not highlighted.Automated verification
yarn vitest run packages/graphql-language-service/src/interface/__tests__/getDiagnostics.test.tsyarn tsgo --build packages/graphql-language-service/tsconfig.jsonyarn vitest run packages/graphql-language-service/srcyarn turbo run test --filter=graphql-language-serviceyarn turbo run types:check --filter=graphql-language-serviceyarn oxfmt --check packages/graphql-language-service/src/interface/getDiagnostics.ts packages/graphql-language-service/src/interface/__tests__/getDiagnostics.test.ts .changeset/loud-fields-dance.mdgit diff --checkFixes #4234.