mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Fix #22419: Add kind field to OutliningSpan
This commit is contained in:
1 parent
23b9a23455
commit
e52efb04f3
15 files changed
+73
-24
No files matched your search
@@ -50,7 +50,7 @@ namespace ts.OutliningElementsCollector {
|
||||
|
||||
if (!result[1]) {
|
||||
const span = createTextSpanFromBounds(sourceFile.text.indexOf("//", currentLineStart), lineEnd);
|
||||
regions.push(createOutliningSpan(span, span, /*autoCollapse*/ false, result[2] || "#region"));
|
||||
regions.push(createOutliningSpan(span, OutliningSpanKind.Region, span, /*autoCollapse*/ false, result[2] || "#region"));
|
||||
}
|
||||
else {
|
||||
const region = regions.pop();
|
||||
@@ -83,7 +83,7 @@ namespace ts.OutliningElementsCollector {
|
||||
break;
|
||||
case SyntaxKind.MultiLineCommentTrivia:
|
||||
combineAndAddMultipleSingleLineComments();
|
||||
out.push(createOutliningSpanFromBounds(pos, end));
|
||||
out.push(createOutliningSpanFromBounds(pos, end, OutliningSpanKind.Comment));
|
||||
singleLineCommentCount = 0;
|
||||
break;
|
||||
default:
|
||||
@@ -95,13 +95,13 @@ namespace ts.OutliningElementsCollector {
|
||||
function combineAndAddMultipleSingleLineComments(): void {
|
||||
// Only outline spans of two or more consecutive single line comments
|
||||
if (singleLineCommentCount > 1) {
|
||||
out.push(createOutliningSpanFromBounds(firstSingleLineCommentStart, lastSingleLineCommentEnd));
|
||||
out.push(createOutliningSpanFromBounds(firstSingleLineCommentStart, lastSingleLineCommentEnd, OutliningSpanKind.Comment));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createOutliningSpanFromBounds(pos: number, end: number): OutliningSpan {
|
||||
return createOutliningSpan(createTextSpanFromBounds(pos, end));
|
||||
function createOutliningSpanFromBounds(pos: number, end: number, kind: OutliningSpanKind): OutliningSpan {
|
||||
return createOutliningSpan(createTextSpanFromBounds(pos, end), kind);
|
||||
}
|
||||
|
||||
function getOutliningSpanForNode(n: Node, sourceFile: SourceFile): OutliningSpan | undefined {
|
||||
@@ -136,7 +136,7 @@ namespace ts.OutliningElementsCollector {
|
||||
default:
|
||||
// Block was a standalone block. In this case we want to only collapse
|
||||
// the span of the block, independent of any parent span.
|
||||
return createOutliningSpan(createTextSpanFromNode(n, sourceFile));
|
||||
return createOutliningSpan(createTextSpanFromNode(n, sourceFile), OutliningSpanKind.Code);
|
||||
}
|
||||
case SyntaxKind.ModuleBlock:
|
||||
return spanForNode(n.parent);
|
||||
@@ -166,11 +166,11 @@ namespace ts.OutliningElementsCollector {
|
||||
return undefined;
|
||||
}
|
||||
const textSpan = createTextSpanFromBounds(useFullStart ? openToken.getFullStart() : openToken.getStart(sourceFile), closeToken.getEnd());
|
||||
return createOutliningSpan(textSpan, createTextSpanFromNode(hintSpanNode, sourceFile), autoCollapse);
|
||||
return createOutliningSpan(textSpan, OutliningSpanKind.Code, createTextSpanFromNode(hintSpanNode, sourceFile), autoCollapse);
|
||||
}
|
||||
}
|
||||
|
||||
function createOutliningSpan(textSpan: TextSpan, hintSpan: TextSpan = textSpan, autoCollapse = false, bannerText = "..."): OutliningSpan {
|
||||
return { textSpan, hintSpan, bannerText, autoCollapse };
|
||||
function createOutliningSpan(textSpan: TextSpan, kind: OutliningSpanKind, hintSpan: TextSpan = textSpan, autoCollapse = false, bannerText = "..."): OutliningSpan {
|
||||
return { textSpan, kind, hintSpan, bannerText, autoCollapse };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -816,6 +816,17 @@ namespace ts {
|
||||
* the 'Collapse to Definitions' command is invoked.
|
||||
*/
|
||||
autoCollapse: boolean;
|
||||
|
||||
/**
|
||||
* Classification of the contents of the span
|
||||
*/
|
||||
kind: OutliningSpanKind;
|
||||
}
|
||||
|
||||
export const enum OutliningSpanKind {
|
||||
Comment = "comment",
|
||||
Region = "region",
|
||||
Code = "code"
|
||||
}
|
||||
|
||||
export const enum OutputFileType {
|
||||
|
||||
Reference in new issue
Block a user