Skip to content

Commit 273a0db

Browse files
committed
add getOption
1 parent f65c865 commit 273a0db

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/harness/fourslash.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,6 +3530,10 @@ namespace FourSlashInterface {
35303530
public setOption(name: string, value: any): void {
35313531
(<any>this.state.formatCodeSettings)[name] = value;
35323532
}
3533+
3534+
public getOption(name: keyof ts.FormatCodeSettings) {
3535+
return this.state.formatCodeSettings[name];
3536+
}
35333537
}
35343538

35353539
export class Cancellation {

tests/cases/fourslash/formattingOptionsChange.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
////}
1414
/////*PlaceOpenBraceOnNewLineForControlBlocks*/if (true) {
1515
////}
16-
/////*InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces*/{ var t = 1}; var {a,b } = { a: 'sw', b:'r' };
16+
/////*InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces*/{ var t = 1}; var {a,b } = { a: 'sw', b:'r' };function f( { a, b}) { }
1717

1818
runTest("InsertSpaceAfterCommaDelimiter", "[1, 2, 3];[72,];", "[1,2,3];[72,];");
1919
runTest("InsertSpaceAfterSemicolonInForStatements", "for (i = 0; i; i++);", "for (i = 0;i;i++);");
@@ -26,9 +26,9 @@ runTest("InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", "`${ 1 }`
2626
runTest("InsertSpaceAfterTypeAssertion", "const bar = <Bar> Thing.getFoo();", "const bar = <Bar>Thing.getFoo();");
2727
runTest("PlaceOpenBraceOnNewLineForFunctions", "class foo", "class foo {");
2828
runTest("PlaceOpenBraceOnNewLineForControlBlocks", "if ( true )", "if ( true ) {");
29-
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces", "{ var t = 1 }; var { a, b } = { a: 'sw', b: 'r' };", "{var t = 1}; var {a, b} = {a: 'sw', b: 'r'};");
30-
29+
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces", "{ var t = 1 }; var { a, b } = { a: 'sw', b: 'r' }; function f({ a, b }) { }", "{var t = 1}; var {a, b} = {a: 'sw', b: 'r'}; function f({a, b}) {}");
3130

31+
const defaultFormatOption = format.copyFormatOptions();
3232
function runTest(propertyName: string, expectedStringWhenTrue: string, expectedStringWhenFalse: string) {
3333
// Go to the correct file
3434
goTo.marker(propertyName);
@@ -52,4 +52,6 @@ function runTest(propertyName: string, expectedStringWhenTrue: string, expectedS
5252
// Verify
5353
goTo.marker(propertyName);
5454
verify.currentLineContentIs(expectedStringWhenTrue);
55+
56+
format.setOption(propertyName, defaultFormatOption[propertyName])
5557
}

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ declare namespace FourSlashInterface {
294294
setFormatOptions(options: FormatCodeOptions): any;
295295
selection(startMarker: string, endMarker: string): void;
296296
onType(posMarker: string, key: string): void;
297-
setOption(name: string, value: number): any;
298-
setOption(name: string, value: string): any;
299-
setOption(name: string, value: boolean): any;
297+
setOption(name: string, value: number): void;
298+
setOption(name: string, value: string): void;
299+
setOption(name: string, value: boolean): void;
300+
getOption(name: string): number|string|boolean;
300301
}
301302
class cancellation {
302303
resetCancelled(): void;

0 commit comments

Comments
 (0)