@@ -53,6 +53,9 @@ export default class CodeFormatManager {
53
53
const editorSubs = new CompositeDisposable (
54
54
// Format on typing in the editor
55
55
editor . getBuffer ( ) . onDidStopChanging ( async ( event ) => {
56
+ if ( ! getFormatOnType ( ) ) {
57
+ return
58
+ }
56
59
try {
57
60
await this . _formatCodeOnTypeInTextEditor ( editor , event )
58
61
} catch ( err ) {
@@ -148,26 +151,26 @@ export default class CodeFormatManager {
148
151
149
152
async _formatCodeOnTypeInTextEditor (
150
153
editor : TextEditor ,
151
- aggregatedEvent : BufferStoppedChangingEvent
154
+ { changes } : BufferStoppedChangingEvent
152
155
) : Promise < Array < TextEdit > > {
153
156
// Don't try to format changes with multiple cursors.
154
- if ( aggregatedEvent . changes . length !== 1 ) {
157
+ if ( changes . length !== 1 ) {
158
+ return [ ]
159
+ }
160
+ // if no provider return immediately
161
+ const providers = [ ...this . _onTypeProviders . getAllProvidersForEditor ( editor ) ]
162
+ if ( providers . length === 0 ) {
155
163
return [ ]
156
164
}
157
- const event = aggregatedEvent . changes [ 0 ]
165
+ const event = changes [ 0 ]
158
166
// This also ensures the non-emptiness of event.newText for below.
159
- if ( ! shouldFormatOnType ( event ) || ! getFormatOnType ( ) ) {
167
+ if ( ! shouldFormatOnType ( event ) ) {
160
168
return [ ]
161
169
}
162
170
// In the case of bracket-matching, we use the last character because that's
163
171
// the character that will usually cause a reformat (i.e. ` }` instead of `{`).
164
172
const character = event . newText [ event . newText . length - 1 ]
165
173
166
- const providers = [ ...this . _onTypeProviders . getAllProvidersForEditor ( editor ) ]
167
- if ( providers . length === 0 ) {
168
- return [ ]
169
- }
170
-
171
174
const contents = editor . getText ( )
172
175
const cursorPosition = editor . getCursorBufferPosition ( ) . copy ( )
173
176
0 commit comments