Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.

Fix off by one issue in getToken character tracking

Changed files
+5 -5
src
+5 -5
src/token.ts
···
let cPos = template.pos + 1;
let foundToken: Token | undefined = undefined;
-
for (let i = 0; i < input.length; i++) {
-
const lPos = cPos;
-
const stream = new CharacterStream(input[i]);
+
for (let line = 0; line < input.length; line++) {
+
const lPos = cPos - 1;
+
const stream = new CharacterStream(input[line]);
while (!stream.eol()) {
const token = parser.token(stream, state);
const string = stream.current();
···
lPos + stream.getCurrentPosition() >= cursorPosition
) {
foundToken = {
-
line: i,
+
line,
start: stream.getStartOfToken() + 1,
end: stream.getCurrentPosition(),
string,
···
}
}
-
cPos += input[i].length + 1;
+
cPos += input[line].length + 1;
}
return foundToken;