mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
fix(44812): add outlining spans for comments inside blocks (#44847)
This commit is contained in:
@@ -34,7 +34,7 @@ namespace ts.OutliningElementsCollector {
|
||||
if (depthRemaining === 0) return;
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
if (isDeclaration(n) || isVariableStatement(n) || n.kind === SyntaxKind.EndOfFileToken) {
|
||||
if (isDeclaration(n) || isVariableStatement(n) || isReturnStatement(n) || n.kind === SyntaxKind.EndOfFileToken) {
|
||||
addOutliningForLeadingCommentsForNode(n, sourceFile, cancellationToken, out);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,14 @@ namespace ts.OutliningElementsCollector {
|
||||
addOutliningForLeadingCommentsForNode(n.parent.left, sourceFile, cancellationToken, out);
|
||||
}
|
||||
|
||||
if (isBlock(n) || isModuleBlock(n)) {
|
||||
addOutliningForLeadingCommentsForPos(n.statements.end, sourceFile, cancellationToken, out);
|
||||
}
|
||||
|
||||
if (isClassLike(n) || isInterfaceDeclaration(n)) {
|
||||
addOutliningForLeadingCommentsForPos(n.members.end, sourceFile, cancellationToken, out);
|
||||
}
|
||||
|
||||
const span = getOutliningSpanForNode(n, sourceFile);
|
||||
if (span) out.push(span);
|
||||
|
||||
@@ -106,9 +114,10 @@ namespace ts.OutliningElementsCollector {
|
||||
return regionDelimiterRegExp.exec(lineText);
|
||||
}
|
||||
|
||||
function addOutliningForLeadingCommentsForNode(n: Node, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
|
||||
const comments = getLeadingCommentRangesOfNode(n, sourceFile);
|
||||
function addOutliningForLeadingCommentsForPos(pos: number, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
|
||||
const comments = getLeadingCommentRanges(sourceFile.text, pos);
|
||||
if (!comments) return;
|
||||
|
||||
let firstSingleLineCommentStart = -1;
|
||||
let lastSingleLineCommentEnd = -1;
|
||||
let singleLineCommentCount = 0;
|
||||
@@ -152,6 +161,11 @@ namespace ts.OutliningElementsCollector {
|
||||
}
|
||||
}
|
||||
|
||||
function addOutliningForLeadingCommentsForNode(n: Node, sourceFile: SourceFile, cancellationToken: CancellationToken, out: Push<OutliningSpan>): void {
|
||||
if (isJsxText(n)) return;
|
||||
addOutliningForLeadingCommentsForPos(n.pos, sourceFile, cancellationToken, out);
|
||||
}
|
||||
|
||||
function createOutliningSpanFromBounds(pos: number, end: number, kind: OutliningSpanKind): OutliningSpan {
|
||||
return createOutliningSpan(createTextSpanFromBounds(pos, end), kind);
|
||||
}
|
||||
|
||||
@@ -136,7 +136,187 @@
|
||||
//// function method(param)[| {
|
||||
//// }|]
|
||||
////}|]
|
||||
////
|
||||
////function fn1()[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////function fn2()[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////function fn3()[| {
|
||||
//// const x = 1;
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////function fn4()[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// const x = 1;
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////function fn5()[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// return 1;
|
||||
////}|]
|
||||
////function fn6()[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// const x = 1;
|
||||
////}|]
|
||||
////class C1[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////class C2[| {
|
||||
//// private prop = 1;
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////class C3[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// private prop = 1;
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////class C4[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// private prop = 1;
|
||||
////}|]
|
||||
////module M1[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////module M2[| {
|
||||
//// export const a = 1;
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////module M3[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// export const a = 1;
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////module M4[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// export const a = 1;
|
||||
////}|]
|
||||
////interface I1[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////interface I2[| {
|
||||
//// x: number;
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////interface I3[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// x: number;
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
////interface I4[| {
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
//// x: number;
|
||||
////}|]
|
||||
////[|{
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////
|
||||
//// [|/**
|
||||
//// * comment
|
||||
//// */|]
|
||||
////}|]
|
||||
|
||||
verify.outliningSpansInCurrentFile(test.ranges());
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user