This is an archive of the discontinued LLVM Phabricator instance.

[clang-format-vs] Add Alternate format config and auto-format on Open
Needs ReviewPublic

Authored by gigadude on May 31 2017, 4:00 PM.

Details

Summary

This diff adds support for an alternate formatting style and auto-format on open. The intent is to make it easy to use a personal formatting style while working under a team-standard .clang-format.

New Format Options

  • Style (Alternate): specifies an alternate formatting style.

Either Style can be specified as file:<path_to_clang-format>, which will select a formatting config file explicitly.

New Format On... Options

  • Format On Open (Alternative): if true, the alternate style will be applied on file open. Note that the document dirty flag is forced clean when this happens, which can result in the in-editor version differing from the version saved to disk. Externally modified files will require a manual reinvokation when reloaded, for example.
  • Format On Save: will re-run Format On Open (Alternative) after the save if it is set to true.
  • Path Filter: a regex tested against the full file path to further refine which files are auto-formatted.

New menu commands

  • Format Selection (Alternate): format the selection using Style (Alternate)
  • Format Document (Alternate): format the current document using Style (Alternate)
  • Format Open Documents: format currently opened documents using Style
  • Format Open Documents (Alternate): format currently opened documents using Style (Alternate)

Example Setup

This examples allows you to view a personally preferred style in the editor while working under a
company-imposed formatting standard set by the repository-local .clang-format file:

Under Format On...:

  • Format On Open (Alternate): True
  • Format On Save: True

Under Format Options:

  • Style: file
  • Style (Alternate): file:c:\Users\me\my-format.clang-format

Diff Detail

Repository
rL LLVM

Event Timeline

gigadude created this revision.May 31 2017, 4:00 PM
gigadude edited the summary of this revision. (Show Details)
gigadude edited the summary of this revision. (Show Details)Jun 2 2017, 12:01 PM
gigadude updated this revision to Diff 101257.Jun 2 2017, 12:05 PM
  • Fixed bugs when auto-formatting files on startup (wait for solution loading to complete)
  • Added commands to format all opened files (useful for switching between debugging using the saved format and editing using the alternate format)
  • Preserve dirty state but reformat unconditionally when running Format Opened Documents
alexfh edited reviewers, added: krasimir; removed: alexfh.Mar 14 2018, 8:12 AM