|
1 | 1 | # README |
2 | 2 |
|
3 | | -## Release history |
| 3 | +[Clang-Format](http://clang.llvm.org/docs/ClangFormat.html) is a tool to format C/C++/Java/JavaScript/Objective-C/Objective-C++/Protobuf code. It can be configured with a config file within the working folder or a parent folder. Configuration see: http://clang.llvm.org/docs/ClangFormatStyleOptions.html |
4 | 4 |
|
5 | | -### v 0.9.0 |
6 | | -* add protobuf support (work with https://marketplace.visualstudio.com/items?itemName=peterj.proto) |
7 | | -* add javascript/typescript support |
8 | | -* allow different style & fallback style option for different languages |
9 | | -* format on save is available now (just like https://github.com/Microsoft/vscode-go/blob/master/src/goMain.ts) |
10 | 5 |
|
11 | | -### v 0.6.1 |
12 | | -* clean up dependencies #9 |
| 6 | +## Usage |
13 | 7 |
|
14 | | -### v 0.6.0 |
15 | | -* fixed multibyte character handling #7 (by [OWenT](https://github.com/owt5008137)) |
16 | | -* fixed "clang-format is ignoring the -style setting because of invalid value" #6 (by [OWenT](https://github.com/owt5008137)) |
17 | | -* LLVM style is now the default fallback style (fixes #1) |
18 | | -* changed dependency to VS Code 1.0.0 or higher |
| 8 | +This extension allows clang-format (version 3.6 or higher) to be used to format C/C++, Javascript etc. |
| 9 | +source files directly from within Visual Studio Code. |
19 | 10 |
|
20 | | -### v 0.5.0 |
21 | | -* Included [OWenT](https://github.com/owt5008137)'s changes: |
22 | | - 1. add setting of clang-format executable |
23 | | - 2. add style setting |
24 | | - 3. add fallback style setting |
| 11 | +Files can be formatted on-demand by right clicking in the document and |
| 12 | +selecting "Format Document", or by using the associated keyboard shortcut |
| 13 | +(usually Ctrl+Shift+F on Windows/Linux, and Cmd+Shift+F on Mac). |
25 | 14 |
|
26 | | -### v 0.1.2 |
27 | | -* Included [ioachim](https://github.com/ioachim/)'s changes: |
28 | | -> it doesn't require saving the file, works by doing partial edits (instead of replacing the whole buffer), and enables range formatting. |
| 15 | +To automatically format a file on save, add the following to your |
| 16 | +vscode settings.json file: |
29 | 17 |
|
30 | | -[Clang-Format](http://clang.llvm.org/docs/ClangFormat.html) is a tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code. It can be configured with a config file within the working folder or a parent folder. Configuration see: http://clang.llvm.org/docs/ClangFormatStyleOptions.html |
| 18 | +```json |
| 19 | +{ |
| 20 | + "editor.formatOnSave": true |
| 21 | +} |
| 22 | +``` |
31 | 23 |
|
| 24 | +## Specifying the location of clang-format |
32 | 25 |
|
33 | | -## Usage |
34 | | -If clang-format is installed and in PATH, C/C++ etc source files can be formatted with Visual Studio Code's built-in formatter (Usually: Ctrl+Shift+F). |
| 26 | +This extension will attempt to find clang-format on your `PATH`. |
| 27 | +Alternatively, the clang-format executable can be specified in your vscode |
| 28 | +settings.json file: |
| 29 | + |
| 30 | +```json |
| 31 | +{ |
| 32 | + "clang-format.executable": "/absolute/path/to/clang-format" |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +Placeholders can also be used in the `clang-format.executable` value. |
| 37 | +The following placeholders are supported: |
| 38 | + |
| 39 | +- `${workspaceRoot}` - replaced by the absolute path of the current vscode |
| 40 | + workspace root. |
| 41 | +- `${cwd}` - replaced by the current working directory of vscode. |
| 42 | +- `${env.VAR}` - replaced by the environment variable $VAR, e.g. `${env.HOME}` |
| 43 | + will be replaced by `$HOME`, your home directory. |
| 44 | + |
| 45 | +Some examples: |
| 46 | + |
| 47 | +- `${workspaceRoot}/node_modules/.bin/clang-format` - specifies the version of |
| 48 | + clang that has been added to your workspace by `npm install clang-format`. |
| 49 | +- `${env.HOME}/tools/clang38/clang-format` - use a specific clang format version |
| 50 | + under your home directory. |
35 | 51 |
|
36 | 52 | ## Source code |
37 | 53 | Available on github: https://github.com/xaverh/vscode-clang-format-provider |
0 commit comments