Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the timeout for formatOnSave configurable #43702

Merged
merged 2 commits into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ class FormatOnSaveParticipant implements ISaveParticipantParticipant {
const versionNow = model.getVersionId();
const { tabSize, insertSpaces } = model.getOptions();

const timeout = this._configurationService.getValue('editor.formatOnSaveTimeout', { overrideIdentifier: model.getLanguageIdentifier().language, resource: editorModel.getResource() });

return new Promise<ISingleEditOperation[]>((resolve, reject) => {
setTimeout(reject, 750);
setTimeout(reject, timeout);
getDocumentFormattingEdits(model, { tabSize, insertSpaces })
.then(edits => this._editorWorkerService.computeMoreMinimalEdits(model.uri, edits))
.then(resolve, err => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ configurationRegistry.registerConfiguration({
'description': nls.localize('formatOnSave', "Format a file on save. A formatter must be available, the file must not be auto-saved, and editor must not be shutting down."),
'overridable': true,
'scope': ConfigurationScope.RESOURCE
},
'editor.formatOnSaveTimeout': {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting is editor-global, it will be hard for end user to figure out correct timeout as it depends on the language and the machine speed.

Copy link
Contributor Author

@buyology buyology Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Made it overridable, then at least every extension that identifies this as a potential issue can provide a sane default (and the user the opportunity to configure it for that specific usage).

'type': 'number',
'default': 750,
'description': nls.localize('formatOnSaveTimeout', "Format on save timeout. Specifies a time limit in milliseconds for formatOnSave-commands. Commands taking longer than the specified timeout will be cancelled."),
'overridable': true,
'scope': ConfigurationScope.RESOURCE
}
}
});
Expand Down