Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not respecting and format in the eclipse configurations. #348

Open
alirana01 opened this issue Jun 13, 2024 · 15 comments
Open

Not respecting and format in the eclipse configurations. #348

alirana01 opened this issue Jun 13, 2024 · 15 comments

Comments

@alirana01
Copy link

Which ever format I try to select from the preferences in eclipse
C/C++ -> Code Style -> Formatter

I see that the editor is always going back to some default formatter like K&R.

It would be helpful if you can provide someway to make that work. Maybe I am missing something. Also let me know if there are some changes required in the implementation or point me to the particular file you are using for the formatting and I can see if in our integration we can change it in a way to utalize the code style from eclipse

@ghentschke
Copy link
Contributor

The formatting in the new LSP based editor relies on a .clang-format file in the source file folder or its parents (e.g. a .clang-format file in the project root will be used for all source files in the project)

Here is a little documentation how its works.

The format info comes from the clangd language server. The formatting defined in the .clang-format will also be applied via the Ctrl+Shift+F shortcut or via the context menu in the editor:
image

@ghentschke
Copy link
Contributor

@alirana01
Copy link
Author

@ghentschke thanks for the quick response can you please also let me know why the color formatting is not working in the eclipse as well?

@ghentschke
Copy link
Contributor

Which editor are u using? In the old editor you can run the formatter via context menu:
image
Or you can tell Eclipse to format your file on file save:
image

@emaayan
Copy link

emaayan commented Jan 19, 2025

The formatting in the new LSP based editor relies on a .clang-format file in the source file folder or its parents (e.g. a .clang-format file in the project root will be used for all source files in the project)

Here is a little documentation how its works.

The format info comes from the clangd language server. The formatting defined in the .clang-format will also be applied via the Ctrl+Shift+F shortcut or via the context menu in the editor:
image

it's still doesn't respect line length wrapping.

@ghentschke
Copy link
Contributor

it's still doesn't respect line length wrapping.

Can you please post your .clang-format configuration?

@emaayan
Copy link

emaayan commented Jan 19, 2025

---
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCompound: false
  AlignFunctionPointers: false
  PadOperators: true
AlignConsecutiveBitFields:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCompound: false
  AlignFunctionPointers: false
  PadOperators: false
AlignConsecutiveDeclarations:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCompound: false
  AlignFunctionPointers: false
  PadOperators: false
AlignConsecutiveMacros:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCompound: false
  AlignFunctionPointers: false
  PadOperators: false
AlignConsecutiveShortCaseStatements:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCaseArrows: false
  AlignCaseColons: false
AlignConsecutiveTableGenBreakingDAGArgColons:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCompound: false
  AlignFunctionPointers: false
  PadOperators: false
AlignConsecutiveTableGenCondOperatorColons:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCompound: false
  AlignFunctionPointers: false
  PadOperators: false
AlignConsecutiveTableGenDefinitionColons:
  Enabled: false
  AcrossEmptyLines: false
  AcrossComments: false
  AlignCompound: false
  AlignFunctionPointers: false
  PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments:
  Kind: Always
  OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Never
AllowShortBlocksOnASingleLine: Never
AllowShortCaseExpressionOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros:
  - __capability
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
  AfterCaseLabel: false
  AfterClass: false
  AfterControlStatement: Never
  AfterEnum: false
  AfterFunction: false
  AfterNamespace: false
  AfterObjCDeclaration: false
  AfterStruct: false
  AfterUnion: false
  AfterExternBlock: false
  BeforeCatch: false
  BeforeElse: false
  BeforeLambdaBody: false
  BeforeWhile: false
  IndentBraces: false
  SplitEmptyFunction: true
  SplitEmptyRecord: true
  SplitEmptyNamespace: true
BreakAdjacentStringLiterals: true
BreakAfterAttributes: Leave
BreakAfterJavaFieldAnnotations: false
BreakAfterReturnType: None
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: Always
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: AfterColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: MultiLine
ColumnLimit: 200
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
  - foreach
  - Q_FOREACH
  - BOOST_FOREACH
IfMacros:
  - KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
  - Regex: ^"(llvm|llvm-c|clang|clang-c)/
    Priority: 2
    SortPriority: 0
    CaseSensitive: false
  - Regex: ^(<|"(gtest|gmock|isl|json)/)
    Priority: 3
    SortPriority: 0
    CaseSensitive: false
  - Regex: .*
    Priority: 1
    SortPriority: 0
    CaseSensitive: false
IncludeIsMainRegex: (Test)?$
IncludeIsMainSourceRegex: ""
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: false
InsertTrailingCommas: None
IntegerLiteralSeparator:
  Binary: 0
  BinaryMinDigits: 0
  Decimal: 0
  DecimalMinDigits: 0
  Hex: 0
  HexMinDigits: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
  AtEndOfFile: false
  AtStartOfBlock: true
  AtStartOfFile: true
LambdaBodyIndentation: Signature
Language: Cpp
LineEnding: DeriveLF
MacroBlockBegin: ""
MacroBlockEnd: ""
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PPIndentWidth: -1
PackConstructorInitializers: NextLineOnly
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakScopeResolution: 500
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveParentheses: Leave
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeJsonColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
  AfterControlStatements: true
  AfterForeachMacros: true
  AfterFunctionDeclarationName: false
  AfterFunctionDefinitionName: false
  AfterIfMacros: true
  AfterOverloadedOperator: false
  AfterPlacementOperator: true
  AfterRequiresInClause: false
  AfterRequiresInExpression: false
  BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
  Minimum: 1
  Maximum: -1
SpacesInParens: Never
SpacesInParensOptions:
  ExceptDoubleParentheses: false
  InConditionalStatements: false
  InCStyleCasts: false
  InEmptyParentheses: false
  Other: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
  - Q_EMIT
StatementMacros:
  - Q_UNUSED
  - QT_REQUIRE_VERSION
TabWidth: 4
TableGenBreakInsideDAGArg: DontBreak
UseTab: Always
VerilogBreakBetweenInstancePorts: true
WhitespaceSensitiveMacros:
  - BOOST_PP_STRINGIZE
  - CF_SWIFT_NAME
  - NS_SWIFT_NAME
  - PP_STRINGIZE
  - STRINGIZE

@ghentschke
Copy link
Contributor

As I can see from your settings is that the lines are wrapped after 200 characters (ColumnLimit: 200)
This does not work?

@emaayan
Copy link

emaayan commented Jan 19, 2025

nope,
trying to do format source on this:
Image

still gets me this:

Image

@ghentschke
Copy link
Contributor

You can check if your .clang-format is valid via the --dry-run option:

C:\temp>clang-format --dry-run functions_file.c
C:/temp/.clang-format:43:1: error: unknown key 'AllowShortCaseExpressionOnASingleLine'
AllowShortCaseExpressionOnASingleLine: true
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error reading C:/temp/.clang-format: Invalid argument

@emaayan
Copy link

emaayan commented Jan 20, 2025

You can check if your .clang-format is valid via the --dry-run option:

C:\temp>clang-format --dry-run functions_file.c
C:/temp/.clang-format:43:1: error: unknown key 'AllowShortCaseExpressionOnASingleLine'
AllowShortCaseExpressionOnASingleLine: true
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error reading C:/temp/.clang-format: Invalid argument

yea, even my minimal file had issue, but that's something eclipse should warn me about, because that means you can easily work without formatting and spend hours trying to figure out why if you don't know how it works, i mean from my POV if you can trigger an event of on save, or when the file is first created to do this validation, that would be something.

@ghentschke
Copy link
Contributor

yea, even my minimal file had issue, but that's something eclipse should warn me about

You're right I`ll try to fix this soon. When there's more that bothers you, feel free to open new issues.

@emaayan
Copy link

emaayan commented Jan 20, 2025

yea, even my minimal file had issue, but that's something eclipse should warn me about

You're right I`ll try to fix this soon. When there's more that bothers you, feel free to open new issues.

i'll hold you to that, as espressif-ide becomes my main tool for ESP dev, i'll probably encounter a lot one issue i haven't gotten to the buttom of it, is this super annoying delay and dispcrepency between code editor and problems view when making comments
like for example i'll int i=0;
then i'll
do //int i=0; and i'l have a compile error, i'll do some space keys or some change and i'll have no compile error.
i'll have a lot of issues with macro interpolation, that don't show up on editor, but i'm not sure if this is espressif part or yours.

@ghentschke
Copy link
Contributor

I think this post meant to be here: #392 (comment)

@emaayan
Copy link

emaayan commented Jan 22, 2025

yea, even my minimal file had issue, but that's something eclipse should warn me about

You're right I`ll try to fix this soon. When there's more that bothers you, feel free to open new issues.

before i forget clanf-format is a yaml file so i would think it should also use a yaml editor and validator at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants