eclipse-cdt / cdt-lsp

Eclipse CDT™ LSP Extensions for CDT
Eclipse Public License 2.0
23 stars 11 forks source link

Not respecting and format in the eclipse configurations. #348

Open alirana01 opened 3 weeks ago

alirana01 commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

See also https://clang.llvm.org/docs/ClangFormatStyleOptions.html

alirana01 commented 2 weeks ago

@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 commented 2 weeks ago

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