From 102a6920cedfc5d8171d0c0f83fe269a0e206cdd Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 28 Mar 2019 10:36:33 +0100 Subject: [PATCH] show status bar message when formatter is gone --- .../format/browser/formatActionsMultiple.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts b/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts index cb24c04ee8a..64a3c48aaf7 100644 --- a/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts +++ b/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts @@ -26,6 +26,8 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { ITextModel } from 'vs/editor/common/model'; import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { IModeService } from 'vs/editor/common/services/modeService'; +import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar'; +import { ILabelService } from 'vs/platform/label/common/label'; type FormattingEditProvider = DocumentFormattingEditProvider | DocumentRangeFormattingEditProvider; @@ -41,7 +43,9 @@ class DefaultFormatter extends Disposable implements IWorkbenchContribution { @IConfigurationService private readonly _configService: IConfigurationService, @INotificationService private readonly _notificationService: INotificationService, @IQuickInputService private readonly _quickInputService: IQuickInputService, - @IModeService private readonly _modeService: IModeService + @IModeService private readonly _modeService: IModeService, + @IStatusbarService private readonly _statusbarService: IStatusbarService, + @ILabelService private readonly _labelService: ILabelService, ) { super(); this._register(this._extensionService.onDidChangeExtensions(this._updateConfigValues, this)); @@ -76,7 +80,20 @@ class DefaultFormatter extends Disposable implements IWorkbenchContribution { if (defaultFormatterId) { // good -> formatter configured const [defaultFormatter] = formatter.filter(formatter => ExtensionIdentifier.equals(formatter.extensionId, defaultFormatterId)); - return defaultFormatter; // this is the formatter or undefined + if (defaultFormatter) { + // formatter available + return defaultFormatter; + + } else { + // formatter gone + const extension = await this._extensionService.getExtension(defaultFormatterId); + const label = this._labelService.getUriLabel(document.uri, { relative: true }); + const message = extension + ? nls.localize('miss', "Extension '{0}' cannot format '{1}'", extension.displayName || extension.name, label) + : nls.localize('gone', "Extension '{0}' is configured as formatter but not available", defaultFormatterId); + this._statusbarService.setStatusMessage(message, 4000); + return undefined; + } } else if (formatter.length === 1) { // ok -> nothing configured but only one formatter available -- GitLab