|
1 |
| -# atom-ide-code-format |
| 1 | +# Code Format |
| 2 | + |
| 3 | +Format a selection of code using the `code-format:format-code` command. |
| 4 | +(Also accessible via context menu, or "Edit > Text > Format Code"). |
| 5 | + |
| 6 | +When no selection is provided, the entire file is formatted. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +Code Format also provides APIs to: |
| 11 | + |
| 12 | +- format code as you type |
| 13 | +- format code on save (after you press save but before writing to disk). |
| 14 | + |
| 15 | +You can enable format-on-save using plain range/file providers from the |
| 16 | +"atom-ide-code-format" section in the `atom-ide-ui` package settings. |
| 17 | + |
| 18 | +## Service API |
| 19 | + |
| 20 | +Provide code format [Atom services](http://flight-manual.atom.io/behind-atom/sections/interacting-with-other-packages-via-services/) by adding one or more of these to your `package.json`: |
| 21 | +(Only the ones that you want to use; you don't need all of them!) |
| 22 | + |
| 23 | +``` |
| 24 | +"providedServices": { |
| 25 | + "code-format.range": { |
| 26 | + "versions": { |
| 27 | + "0.1.0": "provideRangeCodeFormat" |
| 28 | + } |
| 29 | + }, |
| 30 | + "code-format.file": { |
| 31 | + "versions": { |
| 32 | + "0.1.0": "provideFileCodeFormat" |
| 33 | + } |
| 34 | + }, |
| 35 | + "code-format.onType": { |
| 36 | + "versions": { |
| 37 | + "0.1.0": "provideOnTypeCodeFormat" |
| 38 | + } |
| 39 | + }, |
| 40 | + "code-format.onSave": { |
| 41 | + "versions": { |
| 42 | + "0.1.0": "provideOnSaveCodeFormat" |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +Then, in your package entry point: |
| 49 | + |
| 50 | +``` |
| 51 | +export function provideRangeCodeFormat(): RangeCodeFormatProvider {} |
| 52 | +export function provideFileCodeFormat(): FileCodeFormatProvider {} |
| 53 | +export function provideOnTypeCodeFormat(): OnTypeCodeFormatProvider {} |
| 54 | +export function provideOnSaveCodeFormat(): OnSaveCodeFormatProvider {} |
| 55 | +``` |
| 56 | + |
| 57 | +The various provider types are described in |
| 58 | +[`atom-ide-code-format/lib/types.js`](../modules/atom-ide-ui/pkg/atom-ide-code-format/lib/types.js). |
0 commit comments