You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[language-service] getRange does not work for line 0 #3168
The call comes in from doHover(..) if its called on the 1st line - it comes in as line 0. So the for loop never triggers and an invariant error is thrown.
export function getRange(location: SourceLocation, queryText: string): IRange {
const parser = onlineParser();
const state = parser.startState();
const lines = queryText.split('\n');
invariant(
lines.length >= location.line,
'Query text must have more lines than where the error happened',
);
let stream = null;
for (let i = 0; i < location.line; i++) { // Likely should be <=
stream = new CharacterStream(lines[i]);
while (!stream.eol()) {
const style = parser.token(stream, state);
if (style === 'invalidchar') {
break;
}
}
}
invariant(stream, 'Expected Parser stream to be available.');
hmm, indeed. if I understand correctly, i think this is why we had to offset lines in packages/monaco-graphql/src/LanguageService.ts, because if I recall, the LSP spec counts lines from 1, whereas monaco counts lines from 0
have you seen this surface as an issue in any specific implementation such as graphiql or monaco-graphql or the LSP server, or are you making a new implementation directly from getHover()?
As you see the actual query is just 1 liner (incomplete) = "query { }"
So the hover is coming from monaco. There is no custom implementation on my part
Activity
acao commentedon May 10, 2023
#3149 I believe will fix this?
acao commentedon May 10, 2023
would you say this is a duplicate of #2874?
ValtsS commentedon May 10, 2023
Seems related, but I don't know the code well enough. But I am not sure it would, the call is coming from here
lands here

and we have line 0 while in fact its the 1st line. It might not be 1st token, just fact that it s on 1st line breaks it.
ValtsS commentedon May 10, 2023
Also this part
tells me that the issue is in this function, since invariant expects 0 based line index. Yet it does not work when there is just line 0:
acao commentedon May 10, 2023
hmm, indeed. if I understand correctly, i think this is why we had to offset lines in
packages/monaco-graphql/src/LanguageService.ts, because if I recall, the LSP spec counts lines from 1, whereas monaco counts lines from 0have you seen this surface as an issue in any specific implementation such as graphiql or monaco-graphql or the LSP server, or are you making a new implementation directly from
getHover()?ValtsS commentedon May 10, 2023
I am using this with monaco
As you see the actual query is just 1 liner (incomplete) = "query { }"
So the hover is coming from monaco. There is no custom implementation on my part