Merge pull request #4305 from ToddThomson/SpaceWithinNonEmptyBrackets
Add Spacing for Nonempty Brackets Formatting Option
This commit is contained in:
commit
e34238cb92
8 changed files with 43 additions and 9 deletions
|
@ -364,6 +364,7 @@ module FourSlash {
|
||||||
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||||
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||||
PlaceOpenBraceOnNewLineForFunctions: false,
|
PlaceOpenBraceOnNewLineForFunctions: false,
|
||||||
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -990,6 +990,7 @@ namespace ts.server {
|
||||||
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
InsertSpaceAfterKeywordsInControlFlowStatements: true,
|
||||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
|
||||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
|
||||||
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
|
||||||
PlaceOpenBraceOnNewLineForFunctions: false,
|
PlaceOpenBraceOnNewLineForFunctions: false,
|
||||||
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
PlaceOpenBraceOnNewLineForControlBlocks: false,
|
||||||
}
|
}
|
||||||
|
|
3
src/server/protocol.d.ts
vendored
3
src/server/protocol.d.ts
vendored
|
@ -453,6 +453,9 @@ declare namespace ts.server.protocol {
|
||||||
/** Defines space handling after opening and before closing non empty parenthesis. Default value is false. */
|
/** Defines space handling after opening and before closing non empty parenthesis. Default value is false. */
|
||||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||||
|
|
||||||
|
/** Defines space handling after opening and before closing non empty brackets. Default value is false. */
|
||||||
|
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||||
|
|
||||||
/** Defines whether an open brace is put onto a new line for functions or not. Default value is false. */
|
/** Defines whether an open brace is put onto a new line for functions or not. Default value is false. */
|
||||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||||
|
|
||||||
|
|
|
@ -39,12 +39,12 @@ namespace ts.formatting {
|
||||||
public SpaceBetweenCloseBraceAndWhile: Rule;
|
public SpaceBetweenCloseBraceAndWhile: Rule;
|
||||||
public NoSpaceAfterCloseBrace: Rule;
|
public NoSpaceAfterCloseBrace: Rule;
|
||||||
|
|
||||||
// No space for indexer and dot
|
// No space for dot
|
||||||
public NoSpaceBeforeDot: Rule;
|
public NoSpaceBeforeDot: Rule;
|
||||||
public NoSpaceAfterDot: Rule;
|
public NoSpaceAfterDot: Rule;
|
||||||
|
|
||||||
|
// No space before and after indexer
|
||||||
public NoSpaceBeforeOpenBracket: Rule;
|
public NoSpaceBeforeOpenBracket: Rule;
|
||||||
public NoSpaceAfterOpenBracket: Rule;
|
|
||||||
public NoSpaceBeforeCloseBracket: Rule;
|
|
||||||
public NoSpaceAfterCloseBracket: Rule;
|
public NoSpaceAfterCloseBracket: Rule;
|
||||||
|
|
||||||
// Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}.
|
// Insert a space after { and before } in single-line contexts, but remove space from empty object literals {}.
|
||||||
|
@ -191,6 +191,13 @@ namespace ts.formatting {
|
||||||
public NoSpaceAfterOpenParen: Rule;
|
public NoSpaceAfterOpenParen: Rule;
|
||||||
public NoSpaceBeforeCloseParen: Rule;
|
public NoSpaceBeforeCloseParen: Rule;
|
||||||
|
|
||||||
|
// Insert space after opening and before closing nonempty brackets
|
||||||
|
public SpaceAfterOpenBracket: Rule;
|
||||||
|
public SpaceBeforeCloseBracket: Rule;
|
||||||
|
public NoSpaceBetweenBrackets: Rule;
|
||||||
|
public NoSpaceAfterOpenBracket: Rule;
|
||||||
|
public NoSpaceBeforeCloseBracket: Rule;
|
||||||
|
|
||||||
// Insert space after function keyword for anonymous functions
|
// Insert space after function keyword for anonymous functions
|
||||||
public SpaceAfterAnonymousFunctionKeyword: Rule;
|
public SpaceAfterAnonymousFunctionKeyword: Rule;
|
||||||
public NoSpaceAfterAnonymousFunctionKeyword: Rule;
|
public NoSpaceAfterAnonymousFunctionKeyword: Rule;
|
||||||
|
@ -232,13 +239,13 @@ namespace ts.formatting {
|
||||||
this.SpaceBetweenCloseBraceAndWhile = new Rule(RuleDescriptor.create1(SyntaxKind.CloseBraceToken, SyntaxKind.WhileKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
this.SpaceBetweenCloseBraceAndWhile = new Rule(RuleDescriptor.create1(SyntaxKind.CloseBraceToken, SyntaxKind.WhileKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||||
this.NoSpaceAfterCloseBrace = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBraceToken, Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.CloseBracketToken, SyntaxKind.CommaToken, SyntaxKind.SemicolonToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
this.NoSpaceAfterCloseBrace = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBraceToken, Shared.TokenRange.FromTokens([SyntaxKind.CloseParenToken, SyntaxKind.CloseBracketToken, SyntaxKind.CommaToken, SyntaxKind.SemicolonToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
|
|
||||||
// No space for indexer and dot
|
// No space for dot
|
||||||
this.NoSpaceBeforeDot = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.DotToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
this.NoSpaceBeforeDot = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.DotToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
this.NoSpaceAfterDot = new Rule(RuleDescriptor.create3(SyntaxKind.DotToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
this.NoSpaceAfterDot = new Rule(RuleDescriptor.create3(SyntaxKind.DotToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
|
|
||||||
|
// No space before and after indexer
|
||||||
this.NoSpaceBeforeOpenBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
this.NoSpaceBeforeOpenBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext ), RuleAction.Delete));
|
||||||
this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
|
||||||
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), RuleAction.Delete));
|
|
||||||
|
|
||||||
// Place a space before open brace in a function declaration
|
// Place a space before open brace in a function declaration
|
||||||
this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments;
|
this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments;
|
||||||
|
@ -405,8 +412,8 @@ namespace ts.formatting {
|
||||||
this.NoSpaceBeforeSemicolon,
|
this.NoSpaceBeforeSemicolon,
|
||||||
this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock,
|
this.SpaceBeforeOpenBraceInControl, this.SpaceBeforeOpenBraceInFunction, this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock,
|
||||||
this.NoSpaceBeforeComma,
|
this.NoSpaceBeforeComma,
|
||||||
this.NoSpaceBeforeOpenBracket, this.NoSpaceAfterOpenBracket,
|
this.NoSpaceBeforeOpenBracket,
|
||||||
this.NoSpaceBeforeCloseBracket, this.NoSpaceAfterCloseBracket,
|
this.NoSpaceAfterCloseBracket,
|
||||||
this.SpaceAfterSemicolon,
|
this.SpaceAfterSemicolon,
|
||||||
this.NoSpaceBeforeOpenParenInFuncDecl,
|
this.NoSpaceBeforeOpenParenInFuncDecl,
|
||||||
this.SpaceBetweenStatements, this.SpaceAfterTryFinally
|
this.SpaceBetweenStatements, this.SpaceAfterTryFinally
|
||||||
|
@ -451,6 +458,13 @@ namespace ts.formatting {
|
||||||
this.NoSpaceAfterOpenParen = new Rule(RuleDescriptor.create3(SyntaxKind.OpenParenToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
this.NoSpaceAfterOpenParen = new Rule(RuleDescriptor.create3(SyntaxKind.OpenParenToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
this.NoSpaceBeforeCloseParen = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
this.NoSpaceBeforeCloseParen = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
|
|
||||||
|
// Insert space after opening and before closing nonempty brackets
|
||||||
|
this.SpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||||
|
this.SpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
|
||||||
|
this.NoSpaceBetweenBrackets = new Rule(RuleDescriptor.create1(SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
|
this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
|
this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
|
||||||
|
|
||||||
// Insert space after function keyword for anonymous functions
|
// Insert space after function keyword for anonymous functions
|
||||||
this.SpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
|
this.SpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
|
||||||
this.NoSpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Delete));
|
this.NoSpaceAfterAnonymousFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Delete));
|
||||||
|
|
|
@ -71,6 +71,17 @@ namespace ts.formatting {
|
||||||
rules.push(this.globalRules.NoSpaceBetweenParens);
|
rules.push(this.globalRules.NoSpaceBetweenParens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( options.InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets ) {
|
||||||
|
rules.push( this.globalRules.SpaceAfterOpenBracket );
|
||||||
|
rules.push( this.globalRules.SpaceBeforeCloseBracket );
|
||||||
|
rules.push( this.globalRules.NoSpaceBetweenBrackets );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rules.push( this.globalRules.NoSpaceAfterOpenBracket );
|
||||||
|
rules.push( this.globalRules.NoSpaceBeforeCloseBracket );
|
||||||
|
rules.push( this.globalRules.NoSpaceBetweenBrackets );
|
||||||
|
}
|
||||||
|
|
||||||
if (options.InsertSpaceAfterSemicolonInForStatements) {
|
if (options.InsertSpaceAfterSemicolonInForStatements) {
|
||||||
rules.push(this.globalRules.SpaceAfterSemicolonInFor);
|
rules.push(this.globalRules.SpaceAfterSemicolonInFor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1149,6 +1149,7 @@ namespace ts {
|
||||||
InsertSpaceAfterKeywordsInControlFlowStatements: boolean;
|
InsertSpaceAfterKeywordsInControlFlowStatements: boolean;
|
||||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
|
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
|
||||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
|
||||||
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean;
|
||||||
PlaceOpenBraceOnNewLineForFunctions: boolean;
|
PlaceOpenBraceOnNewLineForFunctions: boolean;
|
||||||
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
|
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
|
||||||
[s: string]: boolean | number| string;
|
[s: string]: boolean | number| string;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
/////*InsertSpaceAfterKeywordsInControlFlowStatements*/if (true) { }
|
/////*InsertSpaceAfterKeywordsInControlFlowStatements*/if (true) { }
|
||||||
/////*InsertSpaceAfterFunctionKeywordForAnonymousFunctions*/(function () { })
|
/////*InsertSpaceAfterFunctionKeywordForAnonymousFunctions*/(function () { })
|
||||||
/////*InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis*/(1 )
|
/////*InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis*/(1 )
|
||||||
|
/////*InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets*/[1 ]; [ ]; []; [,]
|
||||||
/////*PlaceOpenBraceOnNewLineForFunctions*/class foo {
|
/////*PlaceOpenBraceOnNewLineForFunctions*/class foo {
|
||||||
////}
|
////}
|
||||||
/////*PlaceOpenBraceOnNewLineForControlBlocks*/if (true) {
|
/////*PlaceOpenBraceOnNewLineForControlBlocks*/if (true) {
|
||||||
|
@ -17,6 +18,7 @@ runTest("InsertSpaceBeforeAndAfterBinaryOperators", "1 + 2 - 3", "1+2-3");
|
||||||
runTest("InsertSpaceAfterKeywordsInControlFlowStatements", "if (true) { }", "if(true) { }");
|
runTest("InsertSpaceAfterKeywordsInControlFlowStatements", "if (true) { }", "if(true) { }");
|
||||||
runTest("InsertSpaceAfterFunctionKeywordForAnonymousFunctions", "(function () { })", "(function() { })");
|
runTest("InsertSpaceAfterFunctionKeywordForAnonymousFunctions", "(function () { })", "(function() { })");
|
||||||
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", " ( 1 )", " (1)");
|
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", " ( 1 )", " (1)");
|
||||||
|
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets", "[ 1 ];[];[];[ , ]", "[1];[];[];[, ]");
|
||||||
runTest("PlaceOpenBraceOnNewLineForFunctions", "class foo", "class foo {");
|
runTest("PlaceOpenBraceOnNewLineForFunctions", "class foo", "class foo {");
|
||||||
runTest("PlaceOpenBraceOnNewLineForControlBlocks", "if ( true )", "if ( true ) {");
|
runTest("PlaceOpenBraceOnNewLineForControlBlocks", "if ( true )", "if ( true ) {");
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ module FourSlashInterface {
|
||||||
InsertSpaceAfterKeywordsInControlFlowStatements: boolean;
|
InsertSpaceAfterKeywordsInControlFlowStatements: boolean;
|
||||||
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
|
InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
|
||||||
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
|
||||||
|
InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean;
|
||||||
PlaceOpenBraceOnNewLineForFunctions: boolean;
|
PlaceOpenBraceOnNewLineForFunctions: boolean;
|
||||||
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
|
PlaceOpenBraceOnNewLineForControlBlocks: boolean;
|
||||||
[s: string]: boolean | number| string;
|
[s: string]: boolean | number| string;
|
||||||
|
|
Loading…
Reference in a new issue