Format ModifiedFormats modified sections of code on save. This is useful where you have a legacy codebase where you want to only format code changes and new code. Requires git and clang-format. The location of the clang-format executable will be determined from Glob patterns can also be used to specify alternative clang-format configuration files. This allows you got further tailor the formatting of legacy code, where some files may need to adhere to different standards, for example. This works by temporarily copying an alternative configuration file into the folder containing the file to format, and renaming it to Note: Determining the modified sections may take longer than a simple format, so you may mind that no formatting appears to happen. If this is the case, you should try increasing your CommandsNormally the extension will work as a standard formatter for the file types configured in The command Set Configuration File For Workspace can be used to set an alternative configuration file for the current workspace. This will show a list of configurations files (which can be set in the settings). Similarly, the command Set Configuration File For This File can be used to set an alternative configuration file for the current file in the editor. The command Format Whole Document can be used to force the whole document to be formatted with the appropriate configuration file. Likewise, Format Selection will format the current selection. InstallingYou can install the latest version of the extension via the Visual Studio Marketplace here. Source CodeThe source code is available on GitHub here. Configuration
Enable this to create an output channel showing information for debugging purposes. To open the output channel, select Output from the View menu and then choose Format Modified from the drop down.
The extension will try and find the
Use this to control which files are formatted. It is set to
By default, clang-format will look for a configuration file (
To make it quicker to associate individual files with specific clang-format configuration files, you can add then to this list. You can then use the command Format Modified: Set Configuration File to select a configuration file from the list which will be used for the current file (see Notes below).
Override the default behaviour of only formatting modified parts of the file. This allows the extension to be used as a standard formatter using clang format, but allows the alternative configuration files to be used.
Normally the configuration file that will be used for the current file is shown in the status bar. If you want to hide it, set this to false. Note: You can also right click on it to hide it, but you'll have to do it in every window.
When the diffs for the file can't be generated (if the file is not tracked in git, for example) the default behaviour is to format the whole file (if possible). Set this to false if you want the file to remain unchanged. NotesUsing the Format Modified: Set Configuration File will update When looking for alternative configurations, the combined settings are searched for an exact filename match first. If no exact match is found, the filename is matched against the globs. You can organise the settings as you wish, but the Format Modified: Set Configuration File will always attempt to update the Workspace Settings. Known issuesclang-format sometimes insists on formatting the line after any specified ranges of lines, even if only a single line is specified. CreditsIcons made by Vaadin from www.flaticon.com, licensed by CC 3.0BY. Icons made by Dave Gandy from www.flaticon.com, licensed by CC 3.0BY. |