File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -120,7 +120,14 @@ module ts.formatting {
120120
121121 function findOutermostParent ( position : number , expectedTokenKind : SyntaxKind , sourceFile : SourceFile ) : Node {
122122 var precedingToken = findPrecedingToken ( position , sourceFile ) ;
123- if ( ! precedingToken || precedingToken . kind !== expectedTokenKind ) {
123+
124+ // when it is claimed that trigger character was typed at given position
125+ // we verify that there is a token with a matching kind whose end is equal to position (because the character was just typed).
126+ // If this condition is not hold - then trigger character was typed in some other context,
127+ // i.e.in comment and thus should not trigger autoformatting
128+ if ( ! precedingToken ||
129+ precedingToken . kind !== expectedTokenKind ||
130+ position !== precedingToken . getEnd ( ) ) {
124131 return undefined ;
125132 }
126133
Original file line number Diff line number Diff line change 1+ /// <reference path='fourslash.ts'/>
2+ ////class A {
3+ ////foo( ); // /*1*/
4+ //// }
5+ ////function foo() { var x; } // /*2*/
6+
7+ goTo . marker ( "1" ) ;
8+ edit . insert ( ";" ) ;
9+ verify . currentLineContentIs ( "foo( ); // ;" )
10+
11+ goTo . marker ( "2" ) ;
12+ edit . insert ( "}" ) ;
13+ verify . currentLineContentIs ( "function foo() { var x; } // }" ) ;
You can’t perform that action at this time.
0 commit comments