diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 15ff50fc909..531b768f6d8 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -1117,25 +1117,6 @@ namespace ts.formatting { } } - export function getRangeOfEnclosingComment(sourceFile: SourceFile, position: number, onlyMultiLine: boolean): CommentRange | undefined { - const precedingToken = findPrecedingToken(position, sourceFile); - const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges(sourceFile.text, precedingToken.end); - const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode(getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false), sourceFile); - const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ? - trailingRangesOfPreviousToken.concat(leadingCommentRangesOfNextToken) : - trailingRangesOfPreviousToken || leadingCommentRangesOfNextToken; - if (commentRanges) { - for (const range of commentRanges) { - // We need to extend the range when in an unclosed multi-line comment. - if (range.pos < position && position < range.end || - position === range.end && (range.kind === SyntaxKind.SingleLineCommentTrivia || position === sourceFile.getFullWidth())) { - return onlyMultiLine && range.kind !== SyntaxKind.MultiLineCommentTrivia ? undefined : range; - } - } - } - return undefined; - } - function getOpenTokenForList(node: Node, list: Node[]) { switch (node.kind) { case SyntaxKind.Constructor: diff --git a/src/services/services.ts b/src/services/services.ts index 32c3a428f1b..b28e52ce6d6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1826,7 +1826,7 @@ namespace ts { case CharacterCodes.singleQuote: case CharacterCodes.doubleQuote: case CharacterCodes.backtick: - return !ts.formatting.getRangeOfEnclosingComment(sourceFile, position, /*onlyMultiLine*/ false); + return !isInComment(sourceFile, position); } return true; diff --git a/tests/cases/fourslash/commentBraceCompletionPosition.ts b/tests/cases/fourslash/commentBraceCompletionPosition.ts index 12a7629c383..e206b161e7f 100644 --- a/tests/cases/fourslash/commentBraceCompletionPosition.ts +++ b/tests/cases/fourslash/commentBraceCompletionPosition.ts @@ -7,8 +7,8 @@ //// // inside regular comment /*2*/ //// var c = ""; //// -//// /* inside multi- -//// line comment /*3*/ +//// /*3*//* inside /*4*/multi- +//// line comment /*5*/ //// */ //// var y =12; //// } @@ -25,4 +25,12 @@ verify.not.isValidBraceCompletionAtPosition('"'); goTo.marker('3'); verify.isValidBraceCompletionAtPosition('('); +verify.isValidBraceCompletionAtPosition('"'); + +goTo.marker('4'); +verify.isValidBraceCompletionAtPosition('('); +verify.not.isValidBraceCompletionAtPosition('"'); + +goTo.marker('5'); +verify.isValidBraceCompletionAtPosition('('); verify.not.isValidBraceCompletionAtPosition('"'); \ No newline at end of file