Merge pull request #1906 from Microsoft/formattingTriggerInComment

ensure that autoformat is not triggered from inside comments
This commit is contained in:
Vladimir Matveev
2015-02-03 11:18:24 -08:00
2 changed files with 21 additions and 1 deletions

View File

@@ -120,7 +120,14 @@ module ts.formatting {
function findOutermostParent(position: number, expectedTokenKind: SyntaxKind, sourceFile: SourceFile): Node {
var precedingToken = findPrecedingToken(position, sourceFile);
if (!precedingToken || precedingToken.kind !== expectedTokenKind) {
// when it is claimed that trigger character was typed at given position
// we verify that there is a token with a matching kind whose end is equal to position (because the character was just typed).
// If this condition is not hold - then trigger character was typed in some other context,
// i.e.in comment and thus should not trigger autoformatting
if (!precedingToken ||
precedingToken.kind !== expectedTokenKind ||
position !== precedingToken.getEnd()) {
return undefined;
}

View File

@@ -0,0 +1,13 @@
/// <reference path='fourslash.ts'/>
////class A {
////foo( ); // /*1*/
////}
////function foo() { var x; } // /*2*/
goTo.marker("1");
edit.insert(";");
verify.currentLineContentIs("foo( ); // ;")
goTo.marker("2");
edit.insert("}");
verify.currentLineContentIs("function foo() { var x; } // }");