formatting: handle templates spans
This commit is contained in:
parent
aec8d9621c
commit
4609d242cf
2 changed files with 21 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
/// <reference path="..\formatting.ts"/>
|
||||||
/// <reference path="..\..\compiler\scanner.ts"/>
|
/// <reference path="..\..\compiler\scanner.ts"/>
|
||||||
|
|
||||||
module ts.formatting {
|
module ts.formatting {
|
||||||
|
@ -14,7 +15,8 @@ module ts.formatting {
|
||||||
const enum ScanAction{
|
const enum ScanAction{
|
||||||
Scan,
|
Scan,
|
||||||
RescanGreaterThanToken,
|
RescanGreaterThanToken,
|
||||||
RescanSlashToken
|
RescanSlashToken,
|
||||||
|
RescanTemplateToken
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFormattingScanner(sourceFile: SourceFile, startPos: number, endPos: number): FormattingScanner {
|
export function getFormattingScanner(sourceFile: SourceFile, startPos: number, endPos: number): FormattingScanner {
|
||||||
|
@ -111,6 +113,10 @@ module ts.formatting {
|
||||||
return container.kind === SyntaxKind.RegularExpressionLiteral;
|
return container.kind === SyntaxKind.RegularExpressionLiteral;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldRescanTemplateToken(container: Node): boolean {
|
||||||
|
return container.kind === SyntaxKind.TemplateSpan;
|
||||||
|
}
|
||||||
|
|
||||||
function startsWithSlashToken(t: SyntaxKind): boolean {
|
function startsWithSlashToken(t: SyntaxKind): boolean {
|
||||||
return t === SyntaxKind.SlashToken || t === SyntaxKind.SlashEqualsToken;
|
return t === SyntaxKind.SlashToken || t === SyntaxKind.SlashEqualsToken;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +138,9 @@ module ts.formatting {
|
||||||
? ScanAction.RescanGreaterThanToken
|
? ScanAction.RescanGreaterThanToken
|
||||||
: shouldRescanSlashToken(n)
|
: shouldRescanSlashToken(n)
|
||||||
? ScanAction.RescanSlashToken
|
? ScanAction.RescanSlashToken
|
||||||
: ScanAction.Scan
|
: shouldRescanTemplateToken(n)
|
||||||
|
? ScanAction.RescanTemplateToken
|
||||||
|
: ScanAction.Scan
|
||||||
|
|
||||||
if (lastTokenInfo && expectedScanAction === lastScanAction) {
|
if (lastTokenInfo && expectedScanAction === lastScanAction) {
|
||||||
// readTokenInfo was called before with the same expected scan action.
|
// readTokenInfo was called before with the same expected scan action.
|
||||||
|
@ -159,6 +167,10 @@ module ts.formatting {
|
||||||
Debug.assert(n.kind === currentToken);
|
Debug.assert(n.kind === currentToken);
|
||||||
lastScanAction = ScanAction.RescanSlashToken;
|
lastScanAction = ScanAction.RescanSlashToken;
|
||||||
}
|
}
|
||||||
|
else if (expectedScanAction === ScanAction.RescanTemplateToken && currentToken === SyntaxKind.CloseBraceToken) {
|
||||||
|
currentToken = scanner.reScanTemplateToken();
|
||||||
|
lastScanAction = ScanAction.RescanTemplateToken;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
lastScanAction = ScanAction.Scan;
|
lastScanAction = ScanAction.Scan;
|
||||||
}
|
}
|
||||||
|
|
7
tests/cases/fourslash/formattingTemplates.ts
Normal file
7
tests/cases/fourslash/formattingTemplates.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
///<reference path="fourslash.ts"/>
|
||||||
|
|
||||||
|
////String.call `${123}`/*1*/
|
||||||
|
|
||||||
|
goTo.marker("1");
|
||||||
|
edit.insert(";");
|
||||||
|
verify.currentLineContentIs("String.call `${123}`;");
|
Loading…
Reference in a new issue