Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-fields-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-language-service': patch
---

Fix validation diagnostic ranges so highlights stop at the invalid token instead of including the following character.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ describe('getDiagnostics', () => {
);
expect(error.severity).toEqual(DIAGNOSTIC_SEVERITY.Error);
expect(error.source).toEqual('GraphQL: Validation');
expect(error.range).toMatchObject({
start: { line: 0, character: 18 },
end: { line: 0, character: 23 },
});
});

it('does not include trailing whitespace in validation highlights', () => {
const error = validateQuery(parse('query {\n title \n}'), schema)[0];

expect(error.range).toMatchObject({
start: { line: 1, character: 2 },
end: { line: 1, character: 7 },
});
});

it('catches with multiple highlighted nodes', () => {
Expand All @@ -55,7 +68,7 @@ describe('getDiagnostics', () => {
{
range: {
end: {
character: 20,
character: 19,
line: 0,
},
start: {
Expand All @@ -67,7 +80,7 @@ describe('getDiagnostics', () => {
{
range: {
end: {
character: 32,
character: 31,
line: 0,
},
start: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,16 @@ function annotations(
// https://github.com/microsoft/TypeScript/pull/32695
const loc = error.locations[i];
const highlightLoc = getLocation(highlightNode);
const end = loc.column + (highlightLoc.end - highlightLoc.start);
const start = new Position(loc.line - 1, loc.column - 1);
const end = new Position(
start.line,
start.character + highlightLoc.end - highlightLoc.start,
);
highlightedNodes.push({
source: `GraphQL: ${type}`,
message: error.message,
severity,
range: new Range(
new Position(loc.line - 1, loc.column - 1),
new Position(loc.line - 1, end),
),
range: new Range(start, end),
});
}
}
Expand Down
Loading