Skip to content

Commit 17f3e14

Browse files
committed
Merge pull request microsoft#2402 from Microsoft/dropInternedStrings
drop interned indentation prefixes if format options has changed
2 parents bb37ea9 + 8afde73 commit 17f3e14

3 files changed

Lines changed: 36 additions & 56 deletions

File tree

src/services/formatting/formatting.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,20 @@ module ts.formatting {
10081008
return SyntaxKind.Unknown;
10091009
}
10101010

1011-
let internedTabsIndentation: string[];
1012-
let internedSpacesIndentation: string[];
1011+
var internedSizes: { tabSize: number; indentSize: number };
1012+
var internedTabsIndentation: string[];
1013+
var internedSpacesIndentation: string[];
10131014

10141015
export function getIndentationString(indentation: number, options: FormatCodeOptions): string {
1016+
// reset interned strings if FormatCodeOptions were changed
1017+
let resetInternedStrings =
1018+
!internedSizes || (internedSizes.tabSize !== options.TabSize || internedSizes.indentSize !== options.IndentSize);
1019+
1020+
if (resetInternedStrings) {
1021+
internedSizes = { tabSize: options.TabSize, indentSize: options.IndentSize };
1022+
internedTabsIndentation = internedSpacesIndentation = undefined;
1023+
}
1024+
10151025
if (!options.ConvertTabsToSpaces) {
10161026
let tabs = Math.floor(indentation / options.TabSize);
10171027
let spaces = indentation - tabs * options.TabSize;

src/services/formatting/indentation.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////module M {
4+
/////*1*/var x=1;
5+
////}
6+
7+
var originalOptions = format.copyFormatOptions();
8+
9+
format.document();
10+
11+
goTo.marker("1");
12+
verify.currentLineContentIs(" var x = 1;");
13+
14+
var copy = format.copyFormatOptions();
15+
copy.TabSize = 2;
16+
copy.IndentSize = 2;
17+
18+
format.setFormatOptions(copy);
19+
format.document();
20+
21+
goTo.marker("1");
22+
verify.currentLineContentIs(" var x = 1;");
23+
24+
format.setFormatOptions(originalOptions);

0 commit comments

Comments
 (0)