Privacy & Cookies Policy
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
12 comments on “Code beautifier for Visual Studio”
I have clang format plugin installed from llvm.org on vs 2015 update 2 rc. That works ok.
I installed your code beautifier and cannot get it to work.
I copied the clang format exec and dll to somewhere on my path. I can run from command line and get the right output
Clang-format -style=file –assume-filename=_clang-format file.cpp
Runs from dir containing the file.cpp with the config file a couple of dirs up.
Running via cb appears to change the file but not its formatting. Any hints on how I might get debug output or common gotchas?
Config is ok as cmd line version decodes it ok. Similarly manually selecting file contents and using clang format plugin directly formats it correctly.
Your tool will be a blessing with all the large projects I need to run through. I just need to get it to work.
For clang You should use as argument ‘-style=file -fallback-style=none -assume-filename=”$(FileName)”‘
Please set the Options/General/Log to High and check logs in VS Output Window ( change ‘show output from’ to CodeB. ). You should get some useful information.
Please also check if You have latest version from this site or visual studio gallery (*.398)
Example configuration attached in main topic
For clang format you should use
-i -style=file -fallback-style=none –assume-filename=”_clang-format” $(FileName)
This works for when a file isnt open in the ide. Unfortunately when open, currently the tool copies the file to a temporary location which means the search to find the config file fails. My workaround is to also copy the _clang-format file to your user home dir but Im hoping the tool can be modded to copy the file to a temp file in the same dir as the original file.
Btw some nice changes adding solution and a progress bar.
Ps your comments captcha timeout is short. I fail to write my comment and have to copy paste and retry.
You may also need to copy the clang-format.exe and its dll to somewhere on your path. Assumes you installed the clang format plugin from llvm.org/builds and managed to find the executable in the vs extensions dir.
This tool makes that plugin so much more useful. Thank you thank you.
New version 411 ( to download from this site ) has extra logs for high priority and fix problem with assume file name ( path to file dir instead of file was given). You should receive something like that when file is opened in vs ide:
CLang: C:\Users\xxx\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp
CLang: Starting process: FileName: C:\Program Files\LLVM\bin\clang-format.exe, Arguments: -style=file -fallback-style=none -assume-filename=”C:\Users\xxx\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp”, WorkingDirectory: C:\Users\xxx\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1
Of course ‘_clang-format’ should be placed somewhere in working directory tree
There is 2 options for using external tool. One using file name as input and second one using standard input/output. First one create temporary files as You mentioned, and second one ( stdInput ) should be use for clang.
You wrote –assume-filename=”_clang-format” but according to help:
‘When reading from stdin, clang-format assumes this filename to look for a style config file (with -style=file) and to determine the language.”.
So $(FileName) in this case ( stdInput ) is not using to format this file, but only for start looking ‘_clang-format’ file and to determine the language. Please check it.
The -i sets in place processing. The filename at the end is the file to transform in place. Search for the – -assume-filename is for a config file when style is file.
If a file is open in the ide you seem to operate on a temp file with the problem of finding the config file relative to the temp dir. Fortunately if a file isnt open in the ide it works in place.
The only combination I could get working was the arguments I showed (with latest plugin version from llvm.org/builds)
I still don’t know why are U trying to use in place processing ( -i ). It will be not working correctly and You should not use it in this way.
Executable/Type -> File ( in CodeB application options ) operate on temporary files and it should not be used for clang.
Please switch ‘Executable type’ to StdInput in application executable combo-box , place _clang-format file somewhere in the tree where You have visual studio project and source files ( place it for sure in directory where You have visual studio source files ). Then set arguments: ‘-style=file -fallback-style=none -assume-filename=”$(FileName)”‘
clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the .clang-format or _clang-format file in the project directory.
When using -style=file, clang-format for each input file will try to find the .clang-format file located in the closest parent directory of the input file. When the standard input is used, the search is started from the current directory.
Because I use standard input the search start directory is set for file location deliver from Visual studio.
Another clang documentation:
When clang-format formats a file, it auto-detects the language using the file name. When formatting standard input or a file that doesn’t have the extension corresponding to its language, -assume-filename= option can be used to override the file name clang-format uses to detect the language.
Because I’m using standard input formatting so -assume-filename is for override language detection.
It’s works flawlessly in our company, so please verify You configuration. Please use clang 3.9, documentation can be found here: http://clang.llvm.org/docs/ClangFormatStyleOptions.html and if You would like to check how clang guys implement it please check https://github.com/llvm-mirror/clang/blob/master/tools/clang-format-vs/ClangFormat/ClangFormatPackage.cs function RunClangFormat
Please also set logs to high and check if there is any error in output window.
Thanks for the clarifications. I’ll give the new version a whirl next week. A very useful tool which should be used by many more people.
Looking forward to trying to hook in cppcheck and other things.
Sent you a small thank you donation via paypal. Most of us dont know the conversion between your currency pln and theirs. Maybe theres an option to allow it to be changed after you hit donate. You can change value but 5 pln is a lot less than 5 gb pounds apparently. Have a beer on me
😉 I’m glad you like it
I’ve changed captcha timeout from 5 to 15 minutes
Hello, i’m trying to use you plugin with clang-format…
but it don’t works…
Clang-Format: Searching through global exclude files
Maker: Clang-Format: Document language: C/C++
Maker: Clang-Format: Source file: D:\dev\sipi\filesystem\FileOps.cpp
Maker: Clang-Format: Using source file encoding: Unicode (UTF-8)
Maker: Clang-Format: Starting process: C:\Program Files (x86)\LLVM\bin\clang-format.exe
Arguments: -style=file -fallback-style=llvm –assume-filename=D:\dev\sipi\filesystem\FileOps.cpp
Maker: Clang-Format: CodeBeautifier encounter error while make document.
Die Pipe wurde beendet.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.WriteCore(Byte buffer, Int32 offset, Int32 count)
at System.IO.FileStream.Write(Byte array, Int32 offset, Int32 count)
at Manobit.CodeBeautifier.Sources.MakerUsingStdInput.makeText(String text, String filePath)
at Manobit.CodeBeautifier.Sources.Maker.makeDocument(TextDocument textDocument)
Comments are closed.