Skip to content

Commit 55be7b4

Browse files
committed
Adds floating block comments to the outlining spans response
1 parent fa3173f commit 55be7b4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/services/outliningElementsCollector.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace ts.OutliningElementsCollector {
44
const res: OutliningSpan[] = [];
55
addNodeOutliningSpans(sourceFile, cancellationToken, res);
66
addRegionOutliningSpans(sourceFile, res);
7+
addTopLevelUnattachedCommentSpans(sourceFile, res);
78
return res.sort((span1, span2) => span1.textSpan.start - span2.textSpan.start);
89
}
910

@@ -106,6 +107,23 @@ namespace ts.OutliningElementsCollector {
106107
return regionDelimiterRegExp.exec(lineText);
107108
}
108109

110+
function addTopLevelUnattachedCommentSpans(sourceFile: SourceFile, out: Push<OutliningSpan>): void {
111+
// Comments which are attached to statements would be included in addNodeOutliningSpans
112+
if (sourceFile.statements.length > 0) return;
113+
114+
// This will instead set up spans for the missing ones
115+
forEach(getLeadingCommentRangesOfNode(sourceFile, sourceFile), (range) => {
116+
// To not mess with // #region support
117+
const isMultiline = sourceFile.text.substring(range.pos, 2) === "/*";
118+
if (!isMultiline) return;
119+
120+
const span = createTextSpanFromBounds(range.pos, range.end);
121+
const comment = sourceFile.text.substring(range.pos, range.end);
122+
const outline = createOutliningSpan(span, OutliningSpanKind.Comment, span, /*autoCollapse*/ false, comment);
123+
out.push(outline);
124+
});
125+
}
126+
109127
function addOutliningForLeadingCommentsForNode(n: Node, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
110128
const comments = getLeadingCommentRangesOfNode(n, sourceFile);
111129
if (!comments) return;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
// #22732
4+
5+
////[|/*
6+
///// * Some text
7+
//// */|]
8+
9+
verify.outliningHintSpansInCurrentFile(test.ranges());

0 commit comments

Comments
 (0)