Vscode-cpptools: Clang-formatter don't allow work another code formatter

Created on 20 Oct 2016  路  13Comments  路  Source: microsoft/vscode-cpptools

After installing extension my previous formatter has stopped working. I really don't know how force to work extension and other formatter together? Is there some method? ("C_Cpp.clang_format_fallbackStyle": "none" - not works)

Language Service

Most helpful comment

@delmyers When two matching formatters for a language are available VS Code picks the one that came last. This isn't ideal, for October we are working on resolving this, and we also need your support here. After a long thought process and weighing options we agreed on adding settings for our formatters, like typescript.format.enable: true|false such that another registered formatter can be picked. See https://github.com/Microsoft/vscode/issues/11609 all the details.

Our ask for you guys would be to add a setting ala cpp.format.enable such that users can decide if they want to use the formatter the language service provides or their formatter-extension.

All 13 comments

My guess is that vscode picks an extension to go with somehow. @sean-mcmanus, do you know a way to get this to work?

@astand, currently our extension does not provide a way to turn off the code-formatting feature that's built into it. This is something that we will definitely consider for our next release as VSCode overall does not provide an ability to force the order of extensions being used. Therefore if there are two extensions loaded that have similar functionality, only one of them will win.

That being said, is there something in particular about the other formatter your using that you like or something in particular about our formatter that you find lacking?

@greazer, I am using astyle extension, I used it before vscode and it is very familiar to me.
I guess that there is no a big conceptual difference between them, and I tried to use clang-formater from the extension but I really don't understand how to work with .clang-format option file. I put it in different locations on pc (LLVM/bin, project workspace, .vscode folder, unrelated folders), tried set "C_Cpp.clang_format_style": "path" - with absolute or relative path format.
It is still not works. (Astyle option file uses the same way, and it works)
Content of file is very simple:
BasedOnStyle: LLVM

@delmyers When two matching formatters for a language are available VS Code picks the one that came last. This isn't ideal, for October we are working on resolving this, and we also need your support here. After a long thought process and weighing options we agreed on adding settings for our formatters, like typescript.format.enable: true|false such that another registered formatter can be picked. See https://github.com/Microsoft/vscode/issues/11609 all the details.

Our ask for you guys would be to add a setting ala cpp.format.enable such that users can decide if they want to use the formatter the language service provides or their formatter-extension.

@jrieken Thanks, we'll be adding this switch to our extension. Most likely our next release.
@astand The way clang format works is by looking for a .clang-format or _clang-format file in the same folder or one of the parent folders of the source that's being formatted. Also note that C_Cpp.clang_format_style is not used to set the path to the .clang-format file.

@astand Oh, it's also important to not set C_Cpp.clang_format_style at all, or set it to "file" in order to make our formatter look for the .clang-format file. This may be the source of the problems you're having since it sounds like you're trying to set the path the .clang-format file using that option. That won't work.

@greazer Thanks, i've got it. I deleted wrong settings (all related to c_cpp.clang_*) and added ".clang-format" file to source code dir. It has only one string - {BasedOnStyle: Visual Studio}. Predefined style - "Visual Studio" but formatter applies another style (I guess that it is LLVM) . When I delete ".clang-format" file, formatter uses Visual Studio style.

@delmyers Any update on this? Can we help with the change?

Yeah, an update with the formatter enable/disable option is planned to be released soon in 0.9.3.

It doesn't look like this made it into 0.9.3? Any idea when it will? It's a bit of a dealbreaker for me - I'd love to use this extension, but my legacy codebase is not consistently formatted, and I don't want to make wholesale formatting changes unnecessarily. It seems a bit crazy not to allow formatting to be disabled in some way or other...

Yes, it has not any changes in this problem. VS code makes things simpler ( I may enable/disable my formatter and it is again in work state), but it is no much less annoying.

We're releasing an update with the fix today, unless something unexpected happens.

Thanks, It's working!

Was this page helpful?
0 / 5 - 0 ratings