Skip to content

Commit

Permalink
Included end tag in HTML folding range
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Chen <[email protected]>
  • Loading branch information
Alexander Chen committed Apr 4, 2022
1 parent 88d4621 commit 861f79c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/services/htmlFolding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ export function getFoldingRanges(document: TextDocument, context: { rangeLimit?:
if (i >= 0) {
const stackElement = stack[i];
stack.length = i;
const line = document.positionAt(scanner.getTokenOffset()).line;
const startLine = stackElement.startLine;
const endLine = line - 1;
const endLine = document.positionAt(scanner.getTokenOffset()).line;
if (endLine > startLine && prevStart !== startLine) {
addRange({ startLine, endLine });
}
Expand Down
32 changes: 16 additions & 16 deletions src/test/folding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ suite('HTML Folding', () => {
/*1*/'Hello',
/*2*/'</html>'
];
assertRanges(input, [r(0, 1)]);
assertRanges(input, [r(0, 2)]);
});

test('Fold two level', () => {
Expand All @@ -53,7 +53,7 @@ suite('HTML Folding', () => {
/*3*/'</head>',
/*4*/'</html>'
];
assertRanges(input, [r(0, 3), r(1, 2)]);
assertRanges(input, [r(0, 4), r(1, 3)]);
});

test('Fold siblings', () => {
Expand All @@ -67,7 +67,7 @@ suite('HTML Folding', () => {
/*6*/'</body>',
/*7*/'</html>'
];
assertRanges(input, [r(0, 6), r(1, 2), r(4, 5)]);
assertRanges(input, [r(0, 7), r(1, 3), r(4, 6)]);
});

test('Fold self-closing tags', () => {
Expand All @@ -82,7 +82,7 @@ suite('HTML Folding', () => {
/*7*/'>',
/*8*/'</div>'
];
assertRanges(input, [r(0, 7), r(5, 6)]);
assertRanges(input, [r(0, 8), r(5, 7)]);
});

test('Fold comment', () => {
Expand Down Expand Up @@ -116,7 +116,7 @@ suite('HTML Folding', () => {
/*3*/'</div>',
/*4*/'</body>',
];
assertRanges(input, [r(0, 3)]);
assertRanges(input, [r(0, 4)]);
});

test('Fold incomplete 2', () => {
Expand All @@ -125,7 +125,7 @@ suite('HTML Folding', () => {
/*1*/'<!-- #endregion -->',
/*2*/'</div>',
];
assertRanges(input, [r(0, 1)]);
assertRanges(input, [r(0, 2)]);
});

test('Fold intersecting region', () => {
Expand All @@ -137,7 +137,7 @@ suite('HTML Folding', () => {
/*4*/'</body>',
/*5*/'<!-- #endregion -->',
];
assertRanges(input, [r(0, 3)]);
assertRanges(input, [r(0, 4)]);
});

test('Fold intersecting region 2', () => {
Expand Down Expand Up @@ -176,15 +176,15 @@ suite('HTML Folding', () => {
/*19*/' </span>',
/*20*/'</div>',
];
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(9, 10), r(13, 14), r(16, 17)], 'no limit', void 0);
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(9, 10), r(13, 14), r(16, 17)], 'limit 8', 8);
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(6, 7), r(13, 14), r(16, 17)], 'limit 7', 7);
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(13, 14), r(16, 17)], 'limit 6', 6);
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11), r(13, 14)], 'limit 5', 5);
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3), r(5, 11)], 'limit 4', 4);
assertRanges(input, [r(0, 19), r(1, 18), r(2, 3)], 'limit 3', 3);
assertRanges(input, [r(0, 19), r(1, 18)], 'limit 2', 2);
assertRanges(input, [r(0, 19)], 'limit 1', 1);
assertRanges(input, [r(0, 20), r(1, 19), r(2, 4), r(5, 12), r(6, 8), r(9, 11), r(13, 15), r(16, 18)], 'no limit', void 0);
assertRanges(input, [r(0, 20), r(1, 19), r(2, 4), r(5, 12), r(6, 8), r(9, 11), r(13, 15), r(16, 18)], 'limit 8', 8);
assertRanges(input, [r(0, 20), r(1, 19), r(2, 4), r(5, 12), r(6, 8), r(13, 15), r(16, 18)], 'limit 7', 7);
assertRanges(input, [r(0, 20), r(1, 19), r(2, 4), r(5, 12), r(13, 15), r(16, 18)], 'limit 6', 6);
assertRanges(input, [r(0, 20), r(1, 19), r(2, 4), r(5, 12), r(13, 15)], 'limit 5', 5);
assertRanges(input, [r(0, 20), r(1, 19), r(2, 4), r(5, 12)], 'limit 4', 4);
assertRanges(input, [r(0, 20), r(1, 19), r(2, 4)], 'limit 3', 3);
assertRanges(input, [r(0, 20), r(1, 19)], 'limit 2', 2);
assertRanges(input, [r(0, 20)], 'limit 1', 1);
});

});

0 comments on commit 861f79c

Please sign in to comment.