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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { join } from 'node:path';
import { GraphQLConfig } from 'graphql-config';
import { GraphQLLanguageService } from '../GraphQLLanguageService';
import { SymbolKind } from 'vscode-languageserver-protocol';
import { Position } from 'graphql-language-service';
import { getRange, Position } from 'graphql-language-service';
import { NoopLogger } from '../Logger';
import { GraphQLEnumType } from 'graphql';

Expand Down Expand Up @@ -207,6 +207,7 @@ describe('GraphQLLanguageService', () => {
);
expect(definitionQueryResult?.definitions.length).toEqual(1);
});

it('runs definition service on fragment spread', async () => {
const definitionQueryResult = await languageService.getDefinition(
'fragment TestFragment on Human { name }\nquery { ...TestFragment }',
Expand Down Expand Up @@ -236,6 +237,24 @@ describe('GraphQLLanguageService', () => {
expect(definitionQueryResult?.definitions.length).toEqual(1);
});

it('can get range on first line', async () => {
const range = await getRange(
{ line: 0, column: 15 },
`query myHero($id: ID) {
hero(id: $id) {
name
id
}
}
`,
);

expect(range).toMatchObject({
end: { character: 23, line: -1 },
start: { character: 22, line: -1 },
Comment on lines +253 to +254
Copy link
Copy Markdown
Contributor

@trevor-scheer trevor-scheer Apr 15, 2026

Choose a reason for hiding this comment

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

This smells funny, I suspect we need to normalize the off by 1 line number at the LSP/Monaco boundary where the line off by 1 is happening (presumably).

I can spend some more time investigating at some point but there's probably a more comprehensive solution that results in line numbers we'd actually expect here (presumably 0).

});
});

it('runs hover service as expected', async () => {
const hoverInformation = await languageService.getHoverInformation(
'type Query { hero(episode: String): String }',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ export function getRange(location: SourceLocation, queryText: string): IRange {

let stream = null;

for (let i = 0; i < location.line; i++) {
// LSP may count from 1, but monaco counts from 0
for (
let i = 0;
location.line === 0 ? i <= location.line : i < location.line;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Related to the comment above, this doesn't feel like the correct place for this fix.

i++
) {
stream = new CharacterStream(lines[i]);
while (!stream.eol()) {
const style = parser.token(stream, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export default class CharacterStream implements CharacterStreamInterface {
return isMatched;
}

public eol = (): boolean => this._sourceText.length === this._pos;
public eol = (): boolean => {
if (!this._sourceText) {
return true;
}
return this._sourceText.length === this._pos;
};

public sol = (): boolean => this._pos === 0;

Expand Down