Skip to content

Commit 9b01ce1

Browse files
committed
search gallery for specific language extensions
related to microsoft#13415
1 parent 537af13 commit 9b01ce1

2 files changed

Lines changed: 73 additions & 37 deletions

File tree

src/vs/workbench/browser/parts/editor/editorStatus.ts

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { Selection } from 'vs/editor/common/core/selection';
4545
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
4646
import { TabFocus } from 'vs/editor/common/config/commonEditorConfig';
4747
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
48+
import { ShowLanguageExtensionsAction } from 'vs/workbench/parts/extensions/electron-browser/extensionsActions';
4849

4950
function getCodeEditor(editorWidget: IEditor): ICommonCodeEditor {
5051
if (editorWidget) {
@@ -681,7 +682,8 @@ export class ChangeModeAction extends Action {
681682
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService,
682683
@IMessageService private messageService: IMessageService,
683684
@IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService,
684-
@IQuickOpenService private quickOpenService: IQuickOpenService
685+
@IQuickOpenService private quickOpenService: IQuickOpenService,
686+
@IInstantiationService private instantiationService: IInstantiationService
685687
) {
686688
super(actionId, actionLabel);
687689
}
@@ -740,12 +742,17 @@ export class ChangeModeAction extends Action {
740742

741743
// Offer action to configure via settings
742744
let configureModeAssociations: IPickOpenEntry;
745+
let galleryAction: Action;
743746
if (fileinput) {
744747
const resource = fileinput.getResource();
745-
configureModeAssociations = {
746-
label: nls.localize('configureAssociationsExt', "Configure File Association for '{0}'...", paths.extname(resource.fsPath) || paths.basename(resource.fsPath))
747-
};
748+
const ext = paths.extname(resource.fsPath) || paths.basename(resource.fsPath);
748749

750+
galleryAction = this.instantiationService.createInstance(ShowLanguageExtensionsAction, ext);
751+
if (galleryAction.enabled) {
752+
picks.unshift(galleryAction);
753+
}
754+
755+
configureModeAssociations = { label: nls.localize('configureAssociationsExt', "Configure File Association for '{0}'...", ext) };
749756
picks.unshift(configureModeAssociations);
750757
}
751758

@@ -757,45 +764,51 @@ export class ChangeModeAction extends Action {
757764
picks.unshift(autoDetectMode);
758765
}
759766

760-
return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickLanguage', "Select Language Mode") }).then(language => {
761-
if (language) {
767+
return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickLanguage', "Select Language Mode") }).then(pick => {
768+
if (!pick) {
769+
return;
770+
}
762771

763-
// User decided to permanently configure associations, return right after
764-
if (language === configureModeAssociations) {
765-
this.configureFileAssociation(fileinput.getResource());
766-
return;
767-
}
772+
if (pick === galleryAction) {
773+
galleryAction.run();
774+
return;
775+
}
768776

769-
// Change mode for active editor
770-
activeEditor = this.editorService.getActiveEditor();
771-
if (activeEditor instanceof BaseTextEditor) {
772-
const editorWidget = activeEditor.getControl();
773-
const models: IModel[] = [];
777+
// User decided to permanently configure associations, return right after
778+
if (pick === configureModeAssociations) {
779+
this.configureFileAssociation(fileinput.getResource());
780+
return;
781+
}
774782

775-
const textModel = getTextModel(editorWidget);
776-
if (textModel) {
777-
models.push(textModel);
778-
}
783+
// Change mode for active editor
784+
activeEditor = this.editorService.getActiveEditor();
785+
if (activeEditor instanceof BaseTextEditor) {
786+
const editorWidget = activeEditor.getControl();
787+
const models: IModel[] = [];
779788

780-
// Support for original side of diff
781-
const model = editorWidget.getModel();
782-
if (model && !!(<IDiffEditorModel>model).original) {
783-
models.push((<IDiffEditorModel>model).original);
784-
}
789+
const textModel = getTextModel(editorWidget);
790+
if (textModel) {
791+
models.push(textModel);
792+
}
785793

786-
// Find mode
787-
let mode: TPromise<IMode>;
788-
if (language === autoDetectMode) {
789-
mode = this.modeService.getOrCreateModeByFilenameOrFirstLine(getUntitledOrFileResource(activeEditor.input, true).fsPath, textModel.getLineContent(1));
790-
} else {
791-
mode = this.modeService.getOrCreateModeByLanguageName(language.label);
792-
}
794+
// Support for original side of diff
795+
const model = editorWidget.getModel();
796+
if (model && !!(<IDiffEditorModel>model).original) {
797+
models.push((<IDiffEditorModel>model).original);
798+
}
793799

794-
// Change mode
795-
models.forEach(textModel => {
796-
this.modelService.setMode(textModel, mode);
797-
});
800+
// Find mode
801+
let mode: TPromise<IMode>;
802+
if (pick === autoDetectMode) {
803+
mode = this.modeService.getOrCreateModeByFilenameOrFirstLine(getUntitledOrFileResource(activeEditor.input, true).fsPath, textModel.getLineContent(1));
804+
} else {
805+
mode = this.modeService.getOrCreateModeByLanguageName(pick.label);
798806
}
807+
808+
// Change mode
809+
models.forEach(textModel => {
810+
this.modelService.setMode(textModel, mode);
811+
});
799812
}
800813
});
801814
}

src/vs/workbench/parts/extensions/electron-browser/extensionsActions.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
1616
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
1717
import { ReloadWindowAction } from 'vs/workbench/electron-browser/actions';
1818
import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewlet, ConfigurationKey } from './extensions';
19-
import { LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
19+
import { LocalExtensionType, IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement';
2020
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2121
import { IMessageService } from 'vs/platform/message/common/message';
2222
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -677,6 +677,29 @@ export class ShowDisabledExtensionsAction extends Action {
677677
}
678678
}
679679

680+
export class ShowLanguageExtensionsAction extends Action {
681+
682+
static ID = 'workbench.extensions.action.showLanguageExtensions';
683+
684+
constructor(
685+
private extension: string,
686+
@IViewletService private viewletService: IViewletService,
687+
@IExtensionGalleryService galleryService: IExtensionGalleryService
688+
) {
689+
super(ShowLanguageExtensionsAction.ID, localize('showLanguageExtensions', "Search Gallery Extensions for '{0}'...", extension), null, true);
690+
this.enabled = galleryService.isEnabled();
691+
}
692+
693+
run(): TPromise<void> {
694+
return this.viewletService.openViewlet(VIEWLET_ID, true)
695+
.then(viewlet => viewlet as IExtensionsViewlet)
696+
.then(viewlet => {
697+
viewlet.search(`tag:__ext_${this.extension.replace(/^\./, '')}`);
698+
viewlet.focus();
699+
});
700+
}
701+
}
702+
680703
export class ClearExtensionsInputAction extends ShowInstalledExtensionsAction {
681704

682705
static ID = 'workbench.extensions.action.clearExtensionsInput';

0 commit comments

Comments
 (0)