mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 05:36:37 +00:00
default contributed profile as editor terminals and make createContributedTerminalProfile private (#129261)
This commit is contained in:
parent
58c59316f8
commit
a1b4b8d303
|
@ -409,6 +409,11 @@ export interface ICreateTerminalOptions {
|
||||||
* The terminal's resource, passed when the terminal has moved windows.
|
* The terminal's resource, passed when the terminal has moved windows.
|
||||||
*/
|
*/
|
||||||
resource?: URI;
|
resource?: URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not this terminal should be a split
|
||||||
|
*/
|
||||||
|
isSplitTerminal?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICreateContributedTerminalProfileOptions {
|
export interface ICreateContributedTerminalProfileOptions {
|
||||||
|
|
|
@ -133,8 +133,6 @@ export interface ITerminalService extends ITerminalInstanceHost {
|
||||||
*/
|
*/
|
||||||
createTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance>;
|
createTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance>;
|
||||||
|
|
||||||
createContributedTerminalProfile(extensionIdentifier: string, id: string, options: ICreateContributedTerminalProfileOptions): Promise<void>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a raw terminal instance, this should not be used outside of the terminal part.
|
* Creates a raw terminal instance, this should not be used outside of the terminal part.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -238,13 +238,21 @@ export class TerminalEditor extends EditorPane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Support contributed profiles with editor target
|
|
||||||
for (const contributed of this._terminalContributionService.terminalProfiles) {
|
for (const contributed of this._terminalContributionService.terminalProfiles) {
|
||||||
dropdownActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createContributedTerminalProfile(contributed.extensionIdentifier, contributed.id, {
|
dropdownActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createTerminal({
|
||||||
isSplitTerminal: false,
|
config: {
|
||||||
|
extensionIdentifier: contributed.extensionIdentifier,
|
||||||
|
id: contributed.id,
|
||||||
|
title: contributed.title.replace(/[\n\r\t]/g, '')
|
||||||
|
},
|
||||||
target: TerminalLocation.Editor
|
target: TerminalLocation.Editor
|
||||||
})));
|
})));
|
||||||
submenuActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createContributedTerminalProfile(contributed.extensionIdentifier, contributed.id, {
|
submenuActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createTerminal({
|
||||||
|
config: {
|
||||||
|
extensionIdentifier: contributed.extensionIdentifier,
|
||||||
|
id: contributed.id,
|
||||||
|
title: contributed.title.replace(/[\n\r\t]/g, '')
|
||||||
|
},
|
||||||
isSplitTerminal: true,
|
isSplitTerminal: true,
|
||||||
target: TerminalLocation.Editor
|
target: TerminalLocation.Editor
|
||||||
})));
|
})));
|
||||||
|
|
|
@ -629,7 +629,7 @@ export class TerminalService implements ITerminalService {
|
||||||
|
|
||||||
const contributedDefaultProfile = await this._getContributedDefaultProfile(shellLaunchConfig);
|
const contributedDefaultProfile = await this._getContributedDefaultProfile(shellLaunchConfig);
|
||||||
if (contributedDefaultProfile) {
|
if (contributedDefaultProfile) {
|
||||||
await this.createContributedTerminalProfile(contributedDefaultProfile.extensionIdentifier, contributedDefaultProfile.id, { isSplitTerminal: true, icon: contributedDefaultProfile.icon, color: contributedDefaultProfile.color });
|
await this._createContributedTerminalProfile(contributedDefaultProfile.extensionIdentifier, contributedDefaultProfile.id, { isSplitTerminal: true, icon: contributedDefaultProfile.icon, color: contributedDefaultProfile.color });
|
||||||
return this._terminalGroupService.instances[this._terminalGroupService.instances.length - 1];
|
return this._terminalGroupService.instances[this._terminalGroupService.instances.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -934,7 +934,7 @@ export class TerminalService implements ITerminalService {
|
||||||
let instance;
|
let instance;
|
||||||
|
|
||||||
if ('id' in value.profile) {
|
if ('id' in value.profile) {
|
||||||
await this.createContributedTerminalProfile(value.profile.extensionIdentifier, value.profile.id, {
|
await this._createContributedTerminalProfile(value.profile.extensionIdentifier, value.profile.id, {
|
||||||
isSplitTerminal: !!(keyMods?.alt && activeInstance),
|
isSplitTerminal: !!(keyMods?.alt && activeInstance),
|
||||||
icon: value.profile.icon
|
icon: value.profile.icon
|
||||||
});
|
});
|
||||||
|
@ -948,7 +948,7 @@ export class TerminalService implements ITerminalService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance && this.configHelper.config.defaultLocation === TerminalLocation.TerminalView) {
|
if (instance && this.configHelper.config.defaultLocation !== TerminalLocation.Editor) {
|
||||||
this._terminalGroupService.showPanel(true);
|
this._terminalGroupService.showPanel(true);
|
||||||
this.setActiveInstance(instance);
|
this.setActiveInstance(instance);
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -1009,9 +1009,9 @@ export class TerminalService implements ITerminalService {
|
||||||
return instance?.target === TerminalLocation.Editor ? this._terminalEditorService : this._terminalGroupService;
|
return instance?.target === TerminalLocation.Editor ? this._terminalEditorService : this._terminalGroupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
async createContributedTerminalProfile(extensionIdentifierentifier: string, id: string, options: ICreateContributedTerminalProfileOptions): Promise<void> {
|
private async _createContributedTerminalProfile(extensionIdentifier: string, id: string, options: ICreateContributedTerminalProfileOptions): Promise<void> {
|
||||||
await this._extensionService.activateByEvent(`onTerminalProfile:${id}`);
|
await this._extensionService.activateByEvent(`onTerminalProfile:${id}`);
|
||||||
const extMap = this._profileProviders.get(extensionIdentifierentifier);
|
const extMap = this._profileProviders.get(extensionIdentifier);
|
||||||
const profileProvider = extMap?.get(id);
|
const profileProvider = extMap?.get(id);
|
||||||
if (!profileProvider) {
|
if (!profileProvider) {
|
||||||
this._notificationService.error(`No terminal profile provider registered for id "${id}"`);
|
this._notificationService.error(`No terminal profile provider registered for id "${id}"`);
|
||||||
|
@ -1023,16 +1023,15 @@ export class TerminalService implements ITerminalService {
|
||||||
await this.activeInstance?.focusWhenReady();
|
await this.activeInstance?.focusWhenReady();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._notificationService.error(e.message);
|
this._notificationService.error(e.message);
|
||||||
throw new Error('nope');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _registerContributedProfile(extensionIdentifierentifier: string, id: string, title: string, options: ICreateContributedTerminalProfileOptions): Promise<void> {
|
private async _registerContributedProfile(extensionIdentifier: string, id: string, title: string, options: ICreateContributedTerminalProfileOptions): Promise<void> {
|
||||||
const platformKey = await this._getPlatformKey();
|
const platformKey = await this._getPlatformKey();
|
||||||
const profilesConfig = await this._configurationService.getValue(`terminal.integrated.profiles.${platformKey}`);
|
const profilesConfig = await this._configurationService.getValue(`terminal.integrated.profiles.${platformKey}`);
|
||||||
if (typeof profilesConfig === 'object') {
|
if (typeof profilesConfig === 'object') {
|
||||||
const newProfile: IExtensionTerminalProfile = {
|
const newProfile: IExtensionTerminalProfile = {
|
||||||
extensionIdentifier: extensionIdentifierentifier,
|
extensionIdentifier: extensionIdentifier,
|
||||||
icon: options.icon,
|
icon: options.icon,
|
||||||
id,
|
id,
|
||||||
title: title,
|
title: title,
|
||||||
|
@ -1108,6 +1107,15 @@ export class TerminalService implements ITerminalService {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _optionsAreBasic(options?: ICreateTerminalOptions): boolean {
|
||||||
|
if (!options) {
|
||||||
|
return true;
|
||||||
|
} else if (Object.entries(options).length > 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Array.from(Object.keys(options)).filter(k => k !== 'target' && k !== 'isSplitTerminal').length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
async createTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance> {
|
async createTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance> {
|
||||||
const config = options?.config;
|
const config = options?.config;
|
||||||
const shellLaunchConfig = config && 'extensionIdentifier' in config
|
const shellLaunchConfig = config && 'extensionIdentifier' in config
|
||||||
|
@ -1118,19 +1126,21 @@ export class TerminalService implements ITerminalService {
|
||||||
let contributedProfile = config && 'extensionIdentifier' in config ? config : undefined;
|
let contributedProfile = config && 'extensionIdentifier' in config ? config : undefined;
|
||||||
|
|
||||||
// Get the default profile as a contributed profile if it exists
|
// Get the default profile as a contributed profile if it exists
|
||||||
if (!contributedProfile && !options) {
|
if (!contributedProfile && this._optionsAreBasic(options)) {
|
||||||
contributedProfile = await this._getContributedDefaultProfile(shellLaunchConfig);
|
contributedProfile = await this._getContributedDefaultProfile(shellLaunchConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launch the contributed profile
|
// Launch the contributed profile
|
||||||
if (contributedProfile) {
|
if (contributedProfile) {
|
||||||
// TODO: createContributedTerminalProfile should be private if we want all terminal creation to go through createTerminal
|
await this._createContributedTerminalProfile(contributedProfile.extensionIdentifier, contributedProfile.id, {
|
||||||
await this.createContributedTerminalProfile(contributedProfile.extensionIdentifier, contributedProfile.id, {
|
isSplitTerminal: options?.isSplitTerminal || false,
|
||||||
isSplitTerminal: false,
|
icon: contributedProfile.icon,
|
||||||
icon: contributedProfile.icon
|
target: options?.target
|
||||||
});
|
});
|
||||||
// TODO: The extension terminal may be created in the editor area
|
const instanceHost = options?.target === TerminalLocation.Editor ? this._terminalEditorService : this._terminalGroupService;
|
||||||
return this._terminalGroupService.instances[this._terminalGroupService.instances.length - 1];
|
const instance = instanceHost.instances[instanceHost.instances.length - 1];
|
||||||
|
await instance.focusWhenReady();
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.cwd) {
|
if (options?.cwd) {
|
||||||
|
|
|
@ -252,8 +252,22 @@ export class TerminalViewPane extends ViewPane {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const contributed of this._terminalContributionService.terminalProfiles) {
|
for (const contributed of this._terminalContributionService.terminalProfiles) {
|
||||||
dropdownActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createContributedTerminalProfile(contributed.extensionIdentifier, contributed.id, { isSplitTerminal: false })));
|
dropdownActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createTerminal({
|
||||||
submenuActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createContributedTerminalProfile(contributed.extensionIdentifier, contributed.id, { isSplitTerminal: true })));
|
config: {
|
||||||
|
extensionIdentifier: contributed.extensionIdentifier,
|
||||||
|
id: contributed.id,
|
||||||
|
title: contributed.title.replace(/[\n\r\t]/g, '')
|
||||||
|
},
|
||||||
|
isSplitTerminal: false
|
||||||
|
})));
|
||||||
|
submenuActions.push(new Action(TerminalCommandId.NewWithProfile, contributed.title.replace(/[\n\r\t]/g, ''), undefined, true, () => this._terminalService.createTerminal({
|
||||||
|
config: {
|
||||||
|
extensionIdentifier: contributed.extensionIdentifier,
|
||||||
|
id: contributed.id,
|
||||||
|
title: contributed.title.replace(/[\n\r\t]/g, '')
|
||||||
|
},
|
||||||
|
isSplitTerminal: true
|
||||||
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dropdownActions.length > 0) {
|
if (dropdownActions.length > 0) {
|
||||||
|
|
Loading…
Reference in a new issue