Skip to content

Commit e77f981

Browse files
committed
Sync sketch formatter configuration from source
The Arduino Language Server's embedded ClangFormat configuration is designed to produce the standard Arduino sketch formatting style, as established by the Arduino IDE 1.x formatter. The configuration is consumed by several other projects. In order to provide all the consumers with a single canonical source and to locate the infrastructure and activity related to the maintenance of the file in a more appropriate repository, it is now hosted in a permanent location in the arduino/tooling-project-assets repository. The following changes have been made to the source configuration: - Move documentation comments to a dedicated file in the upstream repository (which is accessible via the URL in the comment at the top of the configuration) - Make additional non-functional changes to the configuration format to facilitate maintenance - Update to use the configuration API of ClangFormat 14.0.0 This last item did result in some functional changes to the configuration which will result in minor differences in the formatter output. These are actually reversions of unwanted differences from the Arduino IDE 1.x formatter output, which were unavoidable when using the 11.0.1 version of ClangFormat in use at the time of the configuration's creation. The default output of the Arduino IDE 1.x formatter will continue to be considered the "gold standard" until Arduino IDE 2.x graduates from "pre-release" status, at which time its output (which is produced via the same configuration) will become the new standard. The Arduino Language Server formatter configuration is fully customizable according to the preferences of each user. Those already using custom configurations will not be affected in any way (though they are encouraged to sync their configuration files from the source to bring them into compliance with the configuration API of the clangd version 14.0.0 Arduino Language Server is intended to be used with). See the documentation and commit history for the source file for details on the configuration changes: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
1 parent bc125ab commit e77f981

File tree

1 file changed

+94
-49
lines changed

1 file changed

+94
-49
lines changed

Diff for: ls/ls_formatter.go

+94-49
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@ func (ls *INOLanguageServer) createClangdFormatterConfig(logger jsonrpc.Function
1212
// https://github.com/llvm/llvm-project/blob/64d06ed9c9e0389cd27545d2f6e20455a91d89b1/clang-tools-extra/clangd/ClangdLSPServer.cpp#L856-L868
1313
// https://github.com/llvm/llvm-project/blob/64d06ed9c9e0389cd27545d2f6e20455a91d89b1/clang-tools-extra/clangd/ClangdServer.cpp#L402-L404
1414

15-
config := `# See: https://releases.llvm.org/11.0.1/tools/clang/docs/ClangFormatStyleOptions.html
15+
config := `# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
1616
---
17-
Language: Cpp
18-
# LLVM is the default style setting, used when a configuration option is not set here
19-
BasedOnStyle: LLVM
2017
AccessModifierOffset: -2
2118
AlignAfterOpenBracket: Align
22-
AlignConsecutiveAssignments: false
23-
AlignConsecutiveBitFields: false
24-
AlignConsecutiveDeclarations: false
25-
AlignConsecutiveMacros: false
19+
AlignArrayOfStructures: None
20+
AlignConsecutiveAssignments: None
21+
AlignConsecutiveBitFields: None
22+
AlignConsecutiveDeclarations: None
23+
AlignConsecutiveMacros: None
2624
AlignEscapedNewlines: DontAlign
2725
AlignOperands: Align
2826
AlignTrailingComments: true
@@ -33,24 +31,27 @@ AllowShortBlocksOnASingleLine: Always
3331
AllowShortCaseLabelsOnASingleLine: true
3432
AllowShortEnumsOnASingleLine: true
3533
AllowShortFunctionsOnASingleLine: Empty
36-
AllowShortIfStatementsOnASingleLine: Always
34+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
3735
AllowShortLambdasOnASingleLine: Empty
3836
AllowShortLoopsOnASingleLine: true
3937
AlwaysBreakAfterDefinitionReturnType: None
4038
AlwaysBreakAfterReturnType: None
4139
AlwaysBreakBeforeMultilineStrings: false
4240
AlwaysBreakTemplateDeclarations: No
41+
AttributeMacros:
42+
- __capability
43+
BasedOnStyle: LLVM
4344
BinPackArguments: true
4445
BinPackParameters: true
45-
# Only used when "BreakBeforeBraces" set to "Custom"
46+
BitFieldColonSpacing: Both
4647
BraceWrapping:
4748
AfterCaseLabel: false
4849
AfterClass: false
4950
AfterControlStatement: Never
5051
AfterEnum: false
5152
AfterFunction: false
5253
AfterNamespace: false
53-
#AfterObjCDeclaration:
54+
AfterObjCDeclaration: false
5455
AfterStruct: false
5556
AfterUnion: false
5657
AfterExternBlock: false
@@ -59,104 +60,148 @@ BraceWrapping:
5960
BeforeLambdaBody: false
6061
BeforeWhile: false
6162
IndentBraces: false
62-
SplitEmptyFunction: false
63-
SplitEmptyRecord: false
64-
SplitEmptyNamespace: false
65-
# Java-specific
66-
#BreakAfterJavaFieldAnnotations:
63+
SplitEmptyFunction: true
64+
SplitEmptyRecord: true
65+
SplitEmptyNamespace: true
66+
BreakAfterJavaFieldAnnotations: false
6767
BreakBeforeBinaryOperators: NonAssignment
6868
BreakBeforeBraces: Attach
69+
BreakBeforeConceptDeclarations: false
70+
BreakBeforeInheritanceComma: false
6971
BreakBeforeTernaryOperators: true
7072
BreakConstructorInitializers: BeforeColon
73+
BreakConstructorInitializersBeforeComma: false
7174
BreakInheritanceList: BeforeColon
7275
BreakStringLiterals: false
7376
ColumnLimit: 0
74-
# "" matches none
75-
CommentPragmas: ""
77+
CommentPragmas: ''
7678
CompactNamespaces: false
77-
ConstructorInitializerAllOnOneLineOrOnePerLine: true
79+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
7880
ConstructorInitializerIndentWidth: 2
7981
ContinuationIndentWidth: 2
8082
Cpp11BracedListStyle: false
8183
DeriveLineEnding: true
8284
DerivePointerAlignment: true
8385
DisableFormat: false
84-
# Docs say "Do not use this in config files". The default (LLVM 11.0.1) is "false".
85-
#ExperimentalAutoDetectBinPacking:
86+
EmptyLineAfterAccessModifier: Leave
87+
EmptyLineBeforeAccessModifier: Leave
88+
ExperimentalAutoDetectBinPacking: false
8689
FixNamespaceComments: false
87-
ForEachMacros: []
90+
ForEachMacros:
91+
- foreach
92+
- Q_FOREACH
93+
- BOOST_FOREACH
94+
IfMacros:
95+
- KJ_IF_MAYBE
8896
IncludeBlocks: Preserve
89-
IncludeCategories: []
90-
# "" matches none
91-
IncludeIsMainRegex: ""
92-
IncludeIsMainSourceRegex: ""
97+
IncludeCategories:
98+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
99+
Priority: 2
100+
SortPriority: 0
101+
CaseSensitive: false
102+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
103+
Priority: 3
104+
SortPriority: 0
105+
CaseSensitive: false
106+
- Regex: '.*'
107+
Priority: 1
108+
SortPriority: 0
109+
CaseSensitive: false
110+
IncludeIsMainRegex: ''
111+
IncludeIsMainSourceRegex: ''
112+
IndentAccessModifiers: false
93113
IndentCaseBlocks: true
94114
IndentCaseLabels: true
95115
IndentExternBlock: Indent
96116
IndentGotoLabels: false
97117
IndentPPDirectives: None
118+
IndentRequires: true
98119
IndentWidth: 2
99120
IndentWrappedFunctionNames: false
100121
InsertTrailingCommas: None
101-
# Java-specific
102-
#JavaImportGroups:
103-
# JavaScript-specific
104-
#JavaScriptQuotes:
105-
#JavaScriptWrapImports
122+
JavaScriptQuotes: Leave
123+
JavaScriptWrapImports: true
106124
KeepEmptyLinesAtTheStartOfBlocks: true
107-
MacroBlockBegin: ""
108-
MacroBlockEnd: ""
109-
# Set to a large number to effectively disable
125+
LambdaBodyIndentation: Signature
126+
Language: Cpp
127+
MacroBlockBegin: ''
128+
MacroBlockEnd: ''
110129
MaxEmptyLinesToKeep: 100000
111130
NamespaceIndentation: None
112-
NamespaceMacros: []
113-
# Objective C-specific
114-
#ObjCBinPackProtocolList:
115-
#ObjCBlockIndentWidth:
116-
#ObjCBreakBeforeNestedBlockParam:
117-
#ObjCSpaceAfterProperty:
118-
#ObjCSpaceBeforeProtocolList
131+
ObjCBinPackProtocolList: Auto
132+
ObjCBlockIndentWidth: 2
133+
ObjCBreakBeforeNestedBlockParam: true
134+
ObjCSpaceAfterProperty: false
135+
ObjCSpaceBeforeProtocolList: true
136+
PPIndentWidth: -1
137+
PackConstructorInitializers: BinPack
119138
PenaltyBreakAssignment: 1
120139
PenaltyBreakBeforeFirstCallParameter: 1
121140
PenaltyBreakComment: 1
122141
PenaltyBreakFirstLessLess: 1
142+
PenaltyBreakOpenParenthesis: 1
123143
PenaltyBreakString: 1
124144
PenaltyBreakTemplateDeclaration: 1
125145
PenaltyExcessCharacter: 1
146+
PenaltyIndentedWhitespace: 1
126147
PenaltyReturnTypeOnItsOwnLine: 1
127-
# Used as a fallback if alignment style can't be detected from code (DerivePointerAlignment: true)
128148
PointerAlignment: Right
129-
RawStringFormats: []
149+
QualifierAlignment: Leave
150+
ReferenceAlignment: Pointer
130151
ReflowComments: false
131-
SortIncludes: false
152+
RemoveBracesLLVM: false
153+
SeparateDefinitionBlocks: Leave
154+
ShortNamespaceLines: 0
155+
SortIncludes: Never
156+
SortJavaStaticImport: Before
132157
SortUsingDeclarations: false
133158
SpaceAfterCStyleCast: false
134159
SpaceAfterLogicalNot: false
135160
SpaceAfterTemplateKeyword: false
161+
SpaceAroundPointerQualifiers: Default
136162
SpaceBeforeAssignmentOperators: true
163+
SpaceBeforeCaseColon: false
137164
SpaceBeforeCpp11BracedList: false
138165
SpaceBeforeCtorInitializerColon: true
139166
SpaceBeforeInheritanceColon: true
140167
SpaceBeforeParens: ControlStatements
168+
SpaceBeforeParensOptions:
169+
AfterControlStatements: true
170+
AfterForeachMacros: true
171+
AfterFunctionDefinitionName: false
172+
AfterFunctionDeclarationName: false
173+
AfterIfMacros: true
174+
AfterOverloadedOperator: false
175+
BeforeNonEmptyParentheses: false
141176
SpaceBeforeRangeBasedForLoopColon: true
142177
SpaceBeforeSquareBrackets: false
143178
SpaceInEmptyBlock: false
144179
SpaceInEmptyParentheses: false
145180
SpacesBeforeTrailingComments: 2
146-
SpacesInAngles: false
181+
SpacesInAngles: Leave
147182
SpacesInCStyleCastParentheses: false
148183
SpacesInConditionalStatement: false
149184
SpacesInContainerLiterals: false
185+
SpacesInLineCommentPrefix:
186+
Minimum: 0
187+
Maximum: -1
150188
SpacesInParentheses: false
151189
SpacesInSquareBrackets: false
152190
Standard: Auto
153-
StatementMacros: []
191+
StatementAttributeLikeMacros:
192+
- Q_EMIT
193+
StatementMacros:
194+
- Q_UNUSED
195+
- QT_REQUIRE_VERSION
154196
TabWidth: 2
155-
TypenameMacros: []
156-
# Default to LF if line endings can't be detected from the content (DeriveLineEnding).
157197
UseCRLF: false
158198
UseTab: Never
159-
WhitespaceSensitiveMacros: []
199+
WhitespaceSensitiveMacros:
200+
- STRINGIZE
201+
- PP_STRINGIZE
202+
- BOOST_PP_STRINGIZE
203+
- NS_SWIFT_NAME
204+
- CF_SWIFT_NAME
160205
`
161206
try := func(conf *paths.Path) bool {
162207
if c, err := conf.ReadFile(); err != nil {

0 commit comments

Comments
 (0)