mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-24 20:44:53 -05:00
isInMultiLineComment
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
12
tests/cases/fourslash/isInMultiLineCommentEOF.ts
Normal file
12
tests/cases/fourslash/isInMultiLineCommentEOF.ts
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user