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

"C_Cpp: Formatting default" not working: editorconfig ignored and clang-format forced anyway #12933

Open
KonssnoK opened this issue Nov 6, 2024 · 13 comments · Fixed by #12953
Assignees
Labels
bug Feature: Code Formatting fixed Check the Milestone for the release in which the fix is or will be available. Language Service regression A bug that didn't exist in a previous release verified Bug has been reproduced
Milestone

Comments

@KonssnoK
Copy link

KonssnoK commented Nov 6, 2024

Environment

  • OS and Version: Win11
  • VS Code Version: 1.95.1
  • C/C++ Extension Version: v1.22.11

Bug Summary and Steps to Reproduce

Bug Summary:
According to the extension itself,
Image

Steps to reproduce:

  • have a .editorconfig
  • open a .c file
  • format the doc

Expected behavior:

  • formatting is done according to .editorconfig

Result:

  • formatting is done according to clang-format

Workaround:

  • Currently a workaround we found is to force the formatting engine to vcFormat

Configuration and Logs

None relevant

Other Extensions

No response

Additional context

No response

@KonssnoK
Copy link
Author

KonssnoK commented Nov 6, 2024

Actually it seems that even by selecting vcFormat as default formatting engine the .editorconfig is ignored.

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Nov 6, 2024

@KonssnoK We fixed a bug with .editorconfig formatting with 1.22.11 (and our pending 1.23.1, but the fix is not in 1.23.0) -- are you sure you're on that version? (you may need to reload the extension after it installs the new version). With C_Cpp.loggingLevel set to "Debug" what do you see in the C/C++ logging pane after formatting? Previously, error messages were logged relating to editorconfig.

@sean-mcmanus sean-mcmanus self-assigned this Nov 6, 2024
@sean-mcmanus sean-mcmanus added Language Service more info needed The issue report is not actionable in its current state Feature: Code Formatting labels Nov 6, 2024
@KonssnoK
Copy link
Author

KonssnoK commented Nov 6, 2024

Image
pretty sure about the version, yes.

this is what i see when i do "format" with default as selected engine

LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 28)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 28)
LSP: Sending response (id: 28)
LSP: (received) cpptools/formatDocument: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 29)
LSP: (invoked) cpptools/formatDocument: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 29)
Formatting document: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
Formatting Engine: clangFormat
c:\Users\NR6085\.vscode\extensions\ms-vscode.cpptools-1.22.11-win32-x64/bin/../LLVM/bin/clang-format.exe "-style={ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }" -fallback-style=LLVM -sort-includes=0 --Wno-error=unknown -assume-filename=C:\src\v3\v3_sensor_now\components\hardware\power.c
LSP: Sending response (id: 29)
LSP: (received) textDocument/didChange: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
LSP: (received) cpptools/didChangeTextEditorSelection
LSP: (invoked) textDocument/didChange: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
LSP: (invoked) cpptools/didChangeTextEditorSelection
LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 30)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 30)
LSP: Sending response (id: 30)
LSP: (received) cpptools/getDocumentSymbols: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 31)
LSP: (invoked) cpptools/getDocumentSymbols: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 31)
tag parsing file: C:\src\v3\v3_sensor_now\components\hardware\power.c
LSP: Sending response (id: 31)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 32)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 32)
LSP: Sending response (id: 32)
LSP: (received) cpptools/getDocumentSymbols: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 33)
LSP: (invoked) cpptools/getDocumentSymbols: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 33)
tag parsing file: C:\src\v3\v3_sensor_now\components\hardware\power.c
LSP: Sending response (id: 33)
Intellisense update pending for: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
tag parsing file: C:\src\v3\v3_sensor_now\components\hardware\power.c
IntelliSense update scheduled and TU acquisition started for: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
Update IntelliSense time (sec): 0.103
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 34)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 34)
LSP: Sending response (id: 34)
LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 35)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 35)
LSP: Sending response (id: 35)
Database safe to open.

and instead this is what i see when i format with vcFormat

LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
LSP: (received) cpptools/didChangeVisibleTextEditors
LSP: (invoked) cpptools/didChangeVisibleTextEditors
Intellisense update pending for: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 45)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 45)
LSP: Sending response (id: 45)
LSP: (received) cpptools/didChangeTextEditorSelection
LSP: (invoked) cpptools/didChangeTextEditorSelection
LSP: (received) textDocument/documentHighlight: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 46)
LSP: (invoked) textDocument/documentHighlight: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 46)
LSP: Sending response (id: 46)
IntelliSense update scheduled and TU acquisition started for: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
Update IntelliSense time (sec): 0.023
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 47)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 47)
LSP: Sending response (id: 47)
LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 48)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 48)
LSP: Sending response (id: 48)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 49)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 49)
LSP: Sending response (id: 49)
LSP: Message ignored due to no registered handler: $/setTrace
LSP: (received) cpptools/didChangeSettings
LSP: (invoked) cpptools/didChangeSettings
LSP: (received) cpptools/didChangeCppProperties (id: 50)
Autocomplete is enabled.
Error squiggles are enabled if all header dependencies are resolved.
Hover is enabled.
IntelliSense Engine = default.
Enhanced Colorization is enabled.
LSP: (invoked) cpptools/didChangeCppProperties (id: 50)
LSP: Sending response (id: 50)
LSP: (received) cpptools/didChangeActiveEditor: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
LSP: (invoked) cpptools/didChangeActiveEditor: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
LSP: (received) cpptools/didChangeTextEditorSelection
LSP: (invoked) cpptools/didChangeTextEditorSelection
LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 51)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 51)
LSP: Sending response (id: 51)
LSP: (received) cpptools/formatDocument: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 52)
LSP: (invoked) cpptools/formatDocument: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 52)
Formatting document: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
Formatting Engine: vcFormat
LSP: Sending response (id: 52)
LSP: (received) textDocument/didChange: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
LSP: (invoked) textDocument/didChange: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
LSP: (received) cpptools/didChangeTextEditorSelection
LSP: (invoked) cpptools/didChangeTextEditorSelection
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 53)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 53)
LSP: Sending response (id: 53)
LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 54)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 54)
LSP: Sending response (id: 54)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 55)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 55)
LSP: Sending response (id: 55)
LSP: (received) cpptools/getDocumentSymbols: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 56)
LSP: (invoked) cpptools/getDocumentSymbols: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 56)
tag parsing file: C:\src\v3\v3_sensor_now\components\hardware\power.c
LSP: Sending response (id: 56)
Intellisense update pending for: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
tag parsing file: C:\src\v3\v3_sensor_now\components\hardware\power.c
IntelliSense update scheduled and TU acquisition started for: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c
Update IntelliSense time (sec): 0.047
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 57)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 57)
LSP: Sending response (id: 57)
LSP: (received) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 58)
LSP: (invoked) cpptools/getCodeActions: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 58)
LSP: Sending response (id: 58)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 59)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/v3_sensor_now/components/hardware/power.c (id: 59)
LSP: Sending response (id: 59)
Database safe to open.

in both cases editorconfig is ignored

i guess you refer to #12921

@sean-mcmanus
Copy link
Collaborator

@KonssnoK Yes, I don't repro the issue and your logging doesn't show any errors/issues -- can you send a minimal .editorconfig that repros the issue. There might be something particular that is causing an issue or we may not be handling certain values in the .editorconfig.

It sounds like their might be an additional bug with vcFormat not used by default if there's an .editorconfig, but it needs to have "cpp_" properties in it.

@KonssnoK
Copy link
Author

KonssnoK commented Nov 6, 2024

sure here is the editorconfig that we use:

.editorconfig.txt

I know it's not minimal..
I can tell you that the 2 settings i noticed were not working were:

  • when default is selected, brackets are put on new lines (according to default clang-format)
  • when vcFormat is selected, i noticed the editorconfig was not used because of cpp_new_line_before_else which we use as False when the default is True in vcFormat settings

PS: the issue exists even if you remove


# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

....

indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8

from the file.
We added this by regenerating the editorconfig via the editorconfig extension while we were trying to understand what was not working (we removed that extension later on)

@sean-mcmanus sean-mcmanus added verified Bug has been reproduced and removed more info needed The issue report is not actionable in its current state labels Nov 6, 2024
@sean-mcmanus
Copy link
Collaborator

@KonssnoK Okay, thanks. I repro the bug using that .editorconfig file -- the repro occurs when [*.{c, h}] is used.

@sean-mcmanus sean-mcmanus added the regression A bug that didn't exist in a previous release label Nov 6, 2024
@sean-mcmanus sean-mcmanus removed their assignment Nov 6, 2024
@sean-mcmanus sean-mcmanus added this to the 1.23 milestone Nov 6, 2024
@sean-mcmanus sean-mcmanus modified the milestones: 1.23, 1.23.2 Nov 6, 2024
@KonssnoK
Copy link
Author

KonssnoK commented Nov 7, 2024

cool, i wait for 1.23.2 then :)

@sean-mcmanus sean-mcmanus modified the milestones: 1.23.2, 1.23 Nov 7, 2024
@sean-mcmanus
Copy link
Collaborator

@KonssnoK We know a fix for your exact repro, but correctly handling all .editorconfig cases is more difficult than we had initially thought so I'm not sure if it'll be ready for 1.23.2, but I would think we'd want it for 1.23.x, since it's a regression from 1.21.6.

@sean-mcmanus
Copy link
Collaborator

@KonssnoK FYI, it looks like [*.{c, h}] in your .editorconfig is invalid and should be [*.{c,h}]. I don't think would work in 1.21.6 (or 1.23.2).

@github-project-automation github-project-automation bot moved this from Pull Request to Done in cpptools Nov 13, 2024
@KonssnoK
Copy link
Author

KonssnoK commented Nov 13, 2024

oh so spaces are not allowed 🤔
ok thanks i'll check (we haven't changed anything and it was working before)

@KonssnoK
Copy link
Author

KonssnoK commented Nov 13, 2024

well @sean-mcmanus nothing happens even by removing the space. the editorconfig is still ignored.

Actually by setting default formatter engine we go back to clang format being used even if i have "file" as setting and an .editorconfig .

Not sure why @Colengms closed this :)

Formatting Engine: clangFormat
c:\Users\NR6085\.vscode\extensions\ms-vscode.cpptools-1.22.11-win32-x64/bin/../LLVM/bin/clang-format.exe "-style={ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Allman, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }" -fallback-style=LLVM -sort-includes=0 --Wno-error=unknown -assume-filename=C:\src\v3\firmware\components\logging\logging.c
LSP: Sending response (id: 74)
LSP: (received) textDocument/didChange: file:///c%3A/src/v3/firmware/components/logging/logging.c
LSP: (invoked) textDocument/didChange: file:///c%3A/src/v3/firmware/components/logging/logging.c
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 75)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 75)
LSP: Sending response (id: 75)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 76)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 76)
LSP: Sending response (id: 76)
LSP: (received) cpptools/getDocumentSymbols: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 77)
LSP: (invoked) cpptools/getDocumentSymbols: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 77)
tag parsing file: C:\src\v3\firmware\components\logging\logging.c
LSP: Sending response (id: 77)
Intellisense update pending for: file:///c%3A/src/v3/firmware/components/logging/logging.c
IntelliSense update scheduled and TU acquisition started for: file:///c%3A/src/v3/firmware/components/logging/logging.c
Update IntelliSense time (sec): 0.121
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 78)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 78)
LSP: Sending response (id: 78)
LSP: (received) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 79)
LSP: (invoked) cpptools/getFoldingRanges: file:///c%3A/src/v3/firmware/components/logging/logging.c (id: 79)

.editorconfig.txt

@Colengms
Copy link
Collaborator

Hi @KonssnoK . This was closed automatically when the associated PR was completed. You wouldn't see this work properly until a new version is released (1.23.2). We've moved to using exactly the same code to parse section patterns as editorconfig-core-js. Once that is available, the pattern you provided containing a space would not work without removing that space.

Opening this for now, so we can close it when the new version is released.

@Colengms Colengms reopened this Nov 13, 2024
@Colengms Colengms added the fixed Check the Milestone for the release in which the fix is or will be available. label Nov 13, 2024
@Colengms Colengms modified the milestones: 1.23, 1.23.2 Nov 13, 2024
@KonssnoK
Copy link
Author

thanks @Colengms, i will close as soon as i can verify the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Feature: Code Formatting fixed Check the Milestone for the release in which the fix is or will be available. Language Service regression A bug that didn't exist in a previous release verified Bug has been reproduced
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants