Atom форматирование кода

Обновлено: 08.07.2024

The core dependency you need to support formatting services.

Provides a service API that you can register by scope name to send Async formatting edits.

  • Provides unified keyboard shortcuts
  • Takes care of command resolution to the correct scope and therefore provider
  • Takes care of applying the code edits in a manner that they can be easily undone (transactional)

Default (inspired from IntelliJ):

Given you understand these simple concepts:

The Provider really needs to be a FormatterProvider . It needs to provide a selector for which it will work. And then Either of the two:

  • a getCodeEdits function that gets passed in FormattingOptions and returns a bunch of CodeEdit[] or a promise thereof. This method is preferred as we do not create a string .
  • a getNewText function that gets passed in text and then returns formatted text. This is slower as we create and pass around strings.

2- Использование Atom-Beautify

Улучшение всего содержания на Editor.


Улучнить часть кода и определить конкретный язык.

  1. Выбрать часть кода, которую вы хотите улучшить.
  2. Нажмите Ctrl + Shift + P, потом введите название языка.

Улучшить при сохранении фалов.

Например вы хотите, чтобы ваши HTML файлы улучшались, каждый раз когда вы сохраняете эти файлы.

Sample Provider

package.json:

Providers:

Sample Coffeescript

Sample TypeScript

I think this package is bad news.

Good catch. Let us know what about this package looks wrong to you, and we'll investigate right away.


Следуйте за нами на нашей фан-странице, чтобы получать уведомления каждый раз, когда появляются новые статьи. Facebook

1- Atom-Beautify

Atom-Beautify это plugin у Atom, он позволяет вам реформатировать код, делая ваш код лучше и проще. Список видов материалов, которые поддерживаются с помощью Atom-Beautify включают:

Например это код HTML перед улучшением с помощью Atom-Beautify:


И это код HTML после улучшения с помощью Atom-Beautify:


Чтобы установить Atom-Beautify, вам нужно получить доступ в ссылку ниже:




Читайте также: