@@ -2503,6 +2503,9 @@ function extractCommentsFromCode(code, grammar, annotationNames) {
25032503 .map((line) => {
25042504 const { annotations, lineWithoutComments } = getAnnotationsFromLine(line, annotationNames, lineNumber);
25052505 allAnnotations.push(...annotations);
2506+ if (lineWithoutComments) {
2507+ lineNumber++;
2508+ }
25062509 return lineWithoutComments;
25072510 })
25082511 .filter((line) => line !== null);
@@ -2588,6 +2591,7 @@ function annotateLine(line, annotations) {
25882591 toColumn: columnNumber + token.content.length - 1,
25892592 token,
25902593 });
2594+ columnNumber += token.content.length;
25912595 });
25922596 annotations.forEach((annotation) => {
25932597 annotatedLine = reannotateLine(annotatedLine, annotation);
@@ -2610,7 +2614,7 @@ function removeFakeGroups$1(group) {
26102614 }
26112615}
26122616function reannotateLine(annotatedLine, annotation) {
2613- const { range, name, query } = annotation;
2617+ const { range } = annotation;
26142618 const { fromColumn, toColumn } = range;
26152619 const newAnnotatedLine = [];
26162620 let i = 0;
@@ -2631,8 +2635,9 @@ function reannotateLine(annotatedLine, annotation) {
26312635 const firstGroup = annotatedLine[i];
26322636 if (firstGroup.fromColumn < fromColumn) {
26332637 // we need to split the first group in two
2634- newGroup.tokens.push(Object.assign(Object.assign({}, firstGroup), { toColumn: fromColumn - 1 }));
2635- newGroup.tokens.push(Object.assign(Object.assign({}, firstGroup), { fromColumn }));
2638+ const [firstHalf, secondHalf] = splitGroup$1(firstGroup, fromColumn);
2639+ newAnnotatedLine.push(firstHalf);
2640+ newGroup.tokens.push(secondHalf);
26362641 i++;
26372642 }
26382643 while (i < annotatedLine.length && annotatedLine[i].toColumn < toColumn) {
@@ -2646,15 +2651,45 @@ function reannotateLine(annotatedLine, annotation) {
26462651 const lastGroup = annotatedLine[i];
26472652 if (lastGroup.toColumn > toColumn) {
26482653 // we need to split the last group in two
2649- newGroup.tokens.push(Object.assign(Object.assign({}, lastGroup), { toColumn }));
2650- newGroup.tokens.push(Object.assign(Object.assign({}, lastGroup), { fromColumn: toColumn + 1 }));
2654+ const [firstHalf, secondHalf] = splitGroup$1(lastGroup, toColumn + 1);
2655+ newGroup.tokens.push(firstHalf);
2656+ newAnnotatedLine.push(secondHalf);
26512657 i++;
26522658 }
26532659 while (i < annotatedLine.length) {
26542660 newAnnotatedLine.push(annotatedLine[i]);
26552661 i++;
26562662 }
26572663 return newAnnotatedLine;
2664+ }
2665+ function splitGroup$1(group, column) {
2666+ if ("token" in group) {
2667+ const firstToken = Object.assign(Object.assign({}, group.token), { content: group.token.content.slice(0, column - group.fromColumn) });
2668+ const secondToken = Object.assign(Object.assign({}, group.token), { content: group.token.content.slice(column - group.fromColumn) });
2669+ const firstGroup = Object.assign(Object.assign({}, group), { toColumn: column - 1, token: firstToken });
2670+ const secondGroup = Object.assign(Object.assign({}, group), { fromColumn: column, token: secondToken });
2671+ return [firstGroup, secondGroup];
2672+ }
2673+ else {
2674+ const firstTokens = [];
2675+ const secondTokens = [];
2676+ group.tokens.forEach((token) => {
2677+ if (token.toColumn < column) {
2678+ firstTokens.push(token);
2679+ }
2680+ else if (token.fromColumn >= column) {
2681+ secondTokens.push(token);
2682+ }
2683+ else {
2684+ const [firstGroup, secondGroup] = splitGroup$1(token, column);
2685+ firstTokens.push(firstGroup);
2686+ secondTokens.push(secondGroup);
2687+ }
2688+ });
2689+ const firstGroup = Object.assign(Object.assign({}, group), { toColumn: column - 1, tokens: firstTokens });
2690+ const secondGroup = Object.assign(Object.assign({}, group), { fromColumn: column, tokens: secondTokens });
2691+ return [firstGroup, secondGroup];
2692+ }
26582693}
26592694
26602695function annotateLines(lines, annotations) {
@@ -2707,8 +2742,9 @@ function reannotateLines(annotatedLines, annotation) {
27072742 };
27082743 const firstGroup = annotatedLines[i];
27092744 if (firstGroup.fromLineNumber < fromLineNumber) {
2710- newGroup.lines.push(Object.assign(Object.assign({}, firstGroup), { toLineNumber: fromLineNumber - 1 }));
2711- newGroup.lines.push(Object.assign(Object.assign({}, firstGroup), { fromLineNumber }));
2745+ const [firstHalf, secondHalf] = splitGroup(firstGroup, fromLineNumber);
2746+ newAnnotatedLines.push(firstHalf);
2747+ newGroup.lines.push(secondHalf);
27122748 i++;
27132749 }
27142750 while (i < annotatedLines.length &&
@@ -2722,15 +2758,45 @@ function reannotateLines(annotatedLines, annotation) {
27222758 }
27232759 const lastGroup = annotatedLines[i];
27242760 if (lastGroup.toLineNumber > toLineNumber) {
2725- newAnnotatedLines.push(Object.assign(Object.assign({}, lastGroup), { toLineNumber }));
2726- newAnnotatedLines.push(Object.assign(Object.assign({}, lastGroup), { fromLineNumber: toLineNumber + 1 }));
2761+ const [firstHalf, secondHalf] = splitGroup(lastGroup, toLineNumber + 1);
2762+ newGroup.lines.push(firstHalf);
2763+ newAnnotatedLines.push(secondHalf);
27272764 i++;
27282765 }
27292766 while (i < annotatedLines.length) {
27302767 newAnnotatedLines.push(annotatedLines[i]);
27312768 i++;
27322769 }
27332770 return newAnnotatedLines;
2771+ }
2772+ function splitGroup(group, lineNumber) {
2773+ if ("line" in group) {
2774+ return [
2775+ Object.assign(Object.assign({}, group), { toLineNumber: lineNumber - 1 }),
2776+ Object.assign(Object.assign({}, group), { fromLineNumber: lineNumber }),
2777+ ];
2778+ }
2779+ else {
2780+ const firstLines = [];
2781+ const secondLines = [];
2782+ group.lines.forEach((line) => {
2783+ if (line.toLineNumber < lineNumber) {
2784+ firstLines.push(line);
2785+ }
2786+ else if (line.fromLineNumber >= lineNumber) {
2787+ secondLines.push(line);
2788+ }
2789+ else {
2790+ const [firstLine, secondLine] = splitGroup(line, lineNumber);
2791+ firstLines.push(firstLine);
2792+ secondLines.push(secondLine);
2793+ }
2794+ });
2795+ return [
2796+ Object.assign(Object.assign({}, group), { toLineNumber: lineNumber - 1, lines: firstLines }),
2797+ Object.assign(Object.assign({}, group), { fromLineNumber: lineNumber, lines: secondLines }),
2798+ ];
2799+ }
27342800}
27352801
27362802function applyAnnotations(lines, annotations) {
0 commit comments