Process `@verbatim` and `@bye` in folding.
This commit is contained in:
parent
ea3b0182c3
commit
b83a63b6f0
|
@ -95,17 +95,32 @@ export class FoldingRangeContext {
|
||||||
private calculateFoldingRanges() {
|
private calculateFoldingRanges() {
|
||||||
this.headerStart = undefined;
|
this.headerStart = undefined;
|
||||||
const closingBlocks = <{ name: string, line: number }[]>[];
|
const closingBlocks = <{ name: string, line: number }[]>[];
|
||||||
|
let verbatim = false;
|
||||||
for (let idx = this.document.lineCount - 1; idx >= 0; --idx) {
|
for (let idx = this.document.lineCount - 1; idx >= 0; --idx) {
|
||||||
const line = this.document.lineAt(idx).text;
|
const line = this.document.lineAt(idx).text;
|
||||||
if (!line.startsWith('@')) {
|
if (!line.startsWith('@')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (this.processComment(line, idx)) {
|
if (!verbatim) {
|
||||||
continue;
|
if (line === '@bye') {
|
||||||
|
// Abort anything after `@bye`.
|
||||||
|
this.foldingRanges = undefined;
|
||||||
|
this.commentRange = undefined;
|
||||||
|
this.headerStart = undefined;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (this.processComment(line, idx)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Process block.
|
// Process block.
|
||||||
if (line.startsWith('end ', 1)) {
|
if (line.startsWith('@end ')) {
|
||||||
closingBlocks.push({ name: line.substring(5), line: idx });
|
if (verbatim) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const name = line.substring(5);
|
||||||
|
name === 'verbatim' && (verbatim = true);
|
||||||
|
closingBlocks.push({ name: name, line: idx });
|
||||||
} else {
|
} else {
|
||||||
const closingBlock = closingBlocks.pop();
|
const closingBlock = closingBlocks.pop();
|
||||||
if (closingBlock === undefined) {
|
if (closingBlock === undefined) {
|
||||||
|
@ -113,6 +128,8 @@ export class FoldingRangeContext {
|
||||||
}
|
}
|
||||||
if (line.substring(1, closingBlock.name.length + 2).trim() === closingBlock.name) {
|
if (line.substring(1, closingBlock.name.length + 2).trim() === closingBlock.name) {
|
||||||
this.insertRange(idx, closingBlock.line);
|
this.insertRange(idx, closingBlock.line);
|
||||||
|
// If `verbatim == true` goes here, this line must be the `@verbatim` line.
|
||||||
|
verbatim = false;
|
||||||
} else {
|
} else {
|
||||||
closingBlocks.push(closingBlock);
|
closingBlocks.push(closingBlock);
|
||||||
}
|
}
|
||||||
|
@ -120,13 +137,13 @@ export class FoldingRangeContext {
|
||||||
}
|
}
|
||||||
if (this.commentRange !== undefined) {
|
if (this.commentRange !== undefined) {
|
||||||
this.insertRange(this.commentRange.start, this.commentRange.end, vscode.FoldingRangeKind.Comment);
|
this.insertRange(this.commentRange.start, this.commentRange.end, vscode.FoldingRangeKind.Comment);
|
||||||
|
this.commentRange = undefined;
|
||||||
}
|
}
|
||||||
this.commentRange = undefined;
|
|
||||||
return this.foldingRanges;
|
return this.foldingRanges;
|
||||||
}
|
}
|
||||||
|
|
||||||
private processComment(lineText: string, lineNum: number) {
|
private processComment(lineText: string, lineNum: number) {
|
||||||
if (lineText.startsWith('c', 1)) {
|
if (lineText.startsWith('@c')) {
|
||||||
if (!lineText.startsWith(' ', 2) && !lineText.startsWith('omment ', 2)) {
|
if (!lineText.startsWith(' ', 2) && !lineText.startsWith('omment ', 2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue