mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 07:29:16 -05:00
outlining Comments v0.1 4/2
This commit is contained in:
@@ -5195,7 +5195,7 @@ module ts {
|
||||
break;
|
||||
}
|
||||
|
||||
let range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos() };
|
||||
let range = { pos: triviaScanner.getTokenPos(), end: triviaScanner.getTextPos(), kind: triviaScanner.getToken() };
|
||||
|
||||
let comment = sourceText.substring(range.pos, range.end);
|
||||
let referencePathMatchResult = getFileReferenceFromReferencePath(comment, range);
|
||||
|
||||
@@ -523,6 +523,7 @@ module ts {
|
||||
let nextChar = text.charCodeAt(pos + 1);
|
||||
let hasTrailingNewLine = false;
|
||||
if (nextChar === CharacterCodes.slash || nextChar === CharacterCodes.asterisk) {
|
||||
let kind = nextChar === CharacterCodes.slash ? SyntaxKind.SingleLineCommentTrivia : SyntaxKind.MultiLineCommentTrivia;
|
||||
let startPos = pos;
|
||||
pos += 2;
|
||||
if (nextChar === CharacterCodes.slash) {
|
||||
@@ -548,7 +549,7 @@ module ts {
|
||||
result = [];
|
||||
}
|
||||
|
||||
result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine });
|
||||
result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine, kind });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -966,9 +966,10 @@ module ts {
|
||||
|
||||
export interface CommentRange extends TextRange {
|
||||
hasTrailingNewLine?: boolean;
|
||||
kind: SyntaxKind;
|
||||
}
|
||||
|
||||
// Source files are declarations when they are external modules.
|
||||
//* Source files are declarations when they are external modules.
|
||||
export interface SourceFile extends Declaration {
|
||||
statements: NodeArray<ModuleElement>;
|
||||
endOfFileToken: Node;
|
||||
|
||||
@@ -1,17 +1,5 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/// <reference path='services.ts' />
|
||||
|
||||
module ts {
|
||||
export module OutliningElementsCollector {
|
||||
@@ -31,6 +19,53 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function addOutliningSpanComments(commentSpan: CommentRange, autoCollapse: boolean) {
|
||||
if (commentSpan) {
|
||||
let span: OutliningSpan = {
|
||||
textSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end),
|
||||
hintSpan: createTextSpanFromBounds(commentSpan.pos, commentSpan.end),
|
||||
bannerText: collapseText,
|
||||
autoCollapse: autoCollapse
|
||||
};
|
||||
elements.push(span);
|
||||
}
|
||||
}
|
||||
|
||||
function addOutliningForLeadingCommentsForNode(n: Node) {
|
||||
let comments = ts.getLeadingCommentRangesOfNode(n, sourceFile);
|
||||
|
||||
// if we found comments
|
||||
if (comments) {
|
||||
let firstSingleLineCommentStart = -1;
|
||||
let lastSingleLineCommentEnd = -1;
|
||||
let isFirstSingleLineComment = true;
|
||||
let singleLineCommentCount = 0;
|
||||
|
||||
for (let i = 0; i < comments.length; i++) {
|
||||
let currentComment = comments[i];
|
||||
|
||||
if (currentComment.kind == SyntaxKind.SingleLineCommentTrivia) {
|
||||
if (isFirstSingleLineComment) {
|
||||
firstSingleLineCommentStart = currentComment.pos;
|
||||
}
|
||||
|
||||
lastSingleLineCommentEnd = currentComment.end;
|
||||
singleLineCommentCount++;
|
||||
}
|
||||
|
||||
if (currentComment.kind == SyntaxKind.MultiLineCommentTrivia)
|
||||
{
|
||||
// add the block
|
||||
addOutliningSpanComments(currentComment, false);
|
||||
|
||||
// see if we have multiple single line ones
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function autoCollapse(node: Node) {
|
||||
return isFunctionBlock(node) && node.parent.kind !== SyntaxKind.ArrowFunction;
|
||||
}
|
||||
@@ -41,6 +76,8 @@ module ts {
|
||||
if (depth > maxDepth) {
|
||||
return;
|
||||
}
|
||||
|
||||
addOutliningForLeadingCommentsForNode(n);
|
||||
switch (n.kind) {
|
||||
case SyntaxKind.Block:
|
||||
if (!isFunctionBlock(n)) {
|
||||
@@ -93,7 +130,7 @@ module ts {
|
||||
});
|
||||
break;
|
||||
}
|
||||
// Fallthrough.
|
||||
// Fallthrough.
|
||||
|
||||
case SyntaxKind.ModuleBlock: {
|
||||
let openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
@@ -116,6 +153,9 @@ module ts {
|
||||
let closeBracket = findChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile);
|
||||
addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n));
|
||||
break;
|
||||
case SyntaxKind.Constructor:
|
||||
// addOutliningForLeadingCommentsForNode(n);
|
||||
break;
|
||||
}
|
||||
depth++;
|
||||
forEachChild(n, walk);
|
||||
|
||||
Reference in New Issue
Block a user