isInMultiLineComment

This commit is contained in:
Arthur Ozga
2017-06-07 16:43:13 -07:00
parent 6b4cd0bd03
commit a819e4ed17
3 changed files with 56 additions and 9 deletions

View File

@@ -1791,12 +1791,17 @@ namespace ts {
function getIsInMultiLineComment(_fileName: string, position: number): boolean {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(_fileName);
const token = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ true);
const _triviaWidth = token.getLeadingTriviaWidth(sourceFile); _triviaWidth;
const _text = token.getText(sourceFile); _text;
const _fullText = token.getFullText(sourceFile); _fullText;
// TODO: distinguish multi-line and single line comments...
return token.getFullStart() <= position && position < token.getStart(sourceFile, /*includeJsDocComment*/ false);
const token = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false);
const leadingCommentRanges = getLeadingCommentRangesOfNode(token, sourceFile);
for (const range of leadingCommentRanges) {
// We need to extend the range when in an unclosed multi-line comment.
if (range.pos < position && (position < range.end || position === range.end && position === sourceFile.getFullWidth())) {
return range.kind === SyntaxKind.MultiLineCommentTrivia;
}
}
return false;
}
function isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {

View File

@@ -1,6 +1,36 @@
/// <reference path="fourslash.ts" />
//// /* blach /*m0*/ */ let x = 10;
//// /* x */
//// /** x */
//// // x
//// let x = 1;
goTo.marker("m0");
verify.isInMultiLineComment();
for (let i = 1; i < 7; ++i) {
goTo.position(i);
verify.isInMultiLineComment();
}
for (let i = 0; i < 2; ++i) {
goTo.position(i * 7);
verify.not.isInMultiLineComment();
}
const jsDocStart = 8;
for (let i = 1; i < 8; ++i) {
goTo.position(jsDocStart + i);
verify.isInMultiLineComment();
}
for (let i = 0; i < 2; ++i) {
goTo.position(jsDocStart + i * 8);
verify.not.isInMultiLineComment();
}
const singleLineCommentStart = 17;
for (let i = 0; i < 5; ++i) {
goTo.position(singleLineCommentStart + i);
verify.not.isInMultiLineComment();
}

View File

@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />
// @Filename: f1.ts
//// /* /*0*/ blah /*1*/ */
// @Filename: f2.ts
//// /* /*2*/ blah /*3*/
for (let i = 0; i < 4; ++i) {
goTo.marker(`${i}`);
verify.isInMultiLineComment();
}