Skip to content

Commit

Permalink
fix(html): formatting is pushing <pre> contents
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 25, 2023
1 parent 7bdf906 commit ff68f56
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ export default (options: {
},

provideFormattingIndentSensitiveLines(document) {
return worker(document, () => {
return worker(document, (htmlDocument) => {
const lines: number[] = [];
/**
* comments
*/
const scanner = htmlLs.createScanner(document.getText());
let token = scanner.scan();
let startCommentTagLine: number | undefined;
Expand All @@ -176,9 +179,24 @@ export default (options: {
for (let i = startCommentTagLine! + 1; i <= line; i++) {
lines.push(i);
}
startCommentTagLine = undefined;
}
token = scanner.scan();
}
/**
* tags
*/
htmlDocument.roots.forEach(function visit(node) {
// TODO: check source code for all sensitive tags
if (node.tag === 'pre' && node.startTagEnd !== undefined && node.endTagStart !== undefined) {
for (let i = document.positionAt(node.startTagEnd).line + 1; i <= document.positionAt(node.endTagStart).line; i++) {
lines.push(i);
}
}
else {
node.children.forEach(visit);
}
});
return lines;
});
},
Expand Down

0 comments on commit ff68f56

Please sign in to comment.