Skip to content

temp #20

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

temp #20

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
1 change: 1 addition & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"contribEditSessions",
"contribEditorContentMenu",
"contribMergeEditorMenus",
"contribIssueReporter",
"contribMultiDiffEditorMenus",
"contribSourceControlHistoryItemGroupMenu",
"contribSourceControlHistoryItemMenu",
Expand Down
47 changes: 37 additions & 10 deletions src/vs/code/electron-sandbox/issue/issueReporterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ export class IssueReporter extends Disposable {
}
}

private async sendReporterMenu(extension: IssueReporterExtensionData): Promise<IssueReporterData | undefined> {
try {
const data = await this.issueMainService.$sendReporterMenu(extension.id, extension.name);
return data;
} catch (e) {
console.error(e);
return undefined;
}
}

private setEventHandlers(): void {
this.addEventListener('issue-type', 'change', (event: Event) => {
const issueType = parseInt((<HTMLInputElement>event.target).value);
Expand Down Expand Up @@ -1174,10 +1184,24 @@ export class IssueReporter extends Disposable {
this.issueReporterModel.update({ selectedExtension: matches[0] });
const selectedExtension = this.issueReporterModel.getData().selectedExtension;
if (selectedExtension) {
selectedExtension.data = undefined;
selectedExtension.uri = undefined;
const iconElement = document.createElement('span');
iconElement.classList.add(...ThemeIcon.asClassNameArray(Codicon.loading), 'codicon-modifier-spin');
this.setLoading(iconElement);
const openReporterData = await this.sendReporterMenu(selectedExtension);
this.removeLoading(iconElement);
if (openReporterData) {
this.configuration.data = openReporterData;
} else {
// case when previous extension had command
this.configuration.data.issueBody = undefined;
this.configuration.data.data = undefined;

// case when previous extension was opened from normal openIssueReporter command
selectedExtension.data = undefined;
selectedExtension.uri = undefined;
}
this.updateExtensionStatus(selectedExtension);
}
this.updateExtensionStatus(matches[0]);
} else {
this.issueReporterModel.update({ selectedExtension: undefined });
this.clearSearchResults();
Expand All @@ -1199,6 +1223,8 @@ export class IssueReporter extends Disposable {

private async updateExtensionStatus(extension: IssueReporterExtensionData) {
this.issueReporterModel.update({ selectedExtension: extension });

// uses this.configuuration.data to ensure that data is coming from `openReporter` command.
const template = this.configuration.data.issueBody;
if (template) {
const descriptionTextArea = this.getElementById('description')!;
Expand All @@ -1212,13 +1238,16 @@ export class IssueReporter extends Disposable {

const data = this.configuration.data.data;
if (data) {
this.issueReporterModel.update({ extensionData: data });
extension.data = data;
const extensionDataBlock = mainWindow.document.querySelector('.block-extension-data')!;
show(extensionDataBlock);
this.issueReporterModel.update({ extensionData: data });
this.renderBlocks();
}

const uri = this.configuration.data.uri;
if (uri) {
extension.uri = uri;
this.updateIssueReporterUri(extension);
}

Expand All @@ -1227,7 +1256,6 @@ export class IssueReporter extends Disposable {
const toActivate = await this.getReporterStatus(extension);
extension.hasIssueDataProviders = toActivate[0];
extension.hasIssueUriRequestHandler = toActivate[1];
this.renderBlocks();
}

if (extension.hasIssueUriRequestHandler && extension.hasIssueDataProviders) {
Expand Down Expand Up @@ -1273,13 +1301,12 @@ export class IssueReporter extends Disposable {
this.setLoading(iconElement);
await this.getIssueDataFromExtension(extension);
this.removeLoading(iconElement);
} else {
this.validateSelectedExtension();
this.issueReporterModel.update({ extensionData: extension.data ?? undefined });
const title = (<HTMLInputElement>this.getElementById('issue-title')).value;
this.searchExtensionIssues(title);
}

this.validateSelectedExtension();
const title = (<HTMLInputElement>this.getElementById('issue-title')).value;
this.searchExtensionIssues(title);

this.updatePreviewButtonState();
this.renderBlocks();
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class MenuId {
static readonly InteractiveCellDelete = new MenuId('InteractiveCellDelete');
static readonly InteractiveCellExecute = new MenuId('InteractiveCellExecute');
static readonly InteractiveInputExecute = new MenuId('InteractiveInputExecute');
static readonly IssueReporter = new MenuId('IssueReporter');
static readonly NotebookToolbar = new MenuId('NotebookToolbar');
static readonly NotebookStickyScrollContext = new MenuId('NotebookStickyScrollContext');
static readonly NotebookCellTitle = new MenuId('NotebookCellTitle');
Expand Down
5 changes: 3 additions & 2 deletions src/vs/platform/issue/common/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export interface IssueReporterData extends WindowData {
restrictedMode: boolean;
isUnsupported: boolean;
githubAccessToken: string;
readonly issueTitle?: string;
readonly issueBody?: string;
issueTitle?: string;
issueBody?: string;
data?: string;
uri?: UriComponents;
}
Expand Down Expand Up @@ -138,5 +138,6 @@ export interface IIssueMainService {
$getIssueReporterData(extensionId: string): Promise<string>;
$getIssueReporterTemplate(extensionId: string): Promise<string>;
$getReporterStatus(extensionId: string, extensionName: string): Promise<boolean[]>;
$sendReporterMenu(extensionId: string, extensionName: string): Promise<IssueReporterData | undefined>;
$closeReporter(): Promise<void>;
}
19 changes: 15 additions & 4 deletions src/vs/platform/issue/electron-main/issueMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,21 @@ export class IssueMainService implements IIssueMainService {

this.issueReporterWindow.on('close', () => {
this.issueReporterWindow = null;

issueReporterDisposables.dispose();
});

this.issueReporterParentWindow.on('closed', () => {
if (this.issueReporterWindow) {
this.issueReporterWindow.close();
this.issueReporterWindow = null;

issueReporterDisposables.dispose();
}
});
}
}

if (this.issueReporterWindow) {
this.focusWindow(this.issueReporterWindow);
else if (this.issueReporterWindow) {
this.issueReporterWindow.focus();
}
}

Expand Down Expand Up @@ -455,6 +453,19 @@ export class IssueMainService implements IIssueMainService {
return (result ?? defaultResult) as boolean[];
}


async $sendReporterMenu(extensionId: string, extensionName: string): Promise<IssueReporterData | undefined> {
const window = this.issueReporterWindowCheck();
const replyChannel = `vscode:triggerReporterMenu`;
const cts = new CancellationTokenSource();
window.sendWhenReady(replyChannel, cts.token, { replyChannel, extensionId, extensionName });
const result = await raceTimeout(new Promise(resolve => validatedIpcMain.once('vscode:triggerReporterMenuResponse', (_: unknown, data: IssueReporterData | undefined) => resolve(data))), 2000, () => {
this.logService.error('Error: Extension timed out waiting for menu response');
cts.cancel();
});
return result as IssueReporterData | undefined;
}

async $closeReporter(): Promise<void> {
this.issueReporterWindow?.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.InteractiveCellTitle,
description: localize('interactive.cell.title', "The contributed interactive cell title menu"),
},
{
key: 'issue/reporter',
id: MenuId.IssueReporter,
description: localize('issue.reporter', "The contributed issue reporter menu"),
// proposed: 'contribIssueReporter'
},
{
key: 'testing/item/context',
id: MenuId.TestItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const allApiProposals = Object.freeze({
contribCommentThreadAdditionalMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentThreadAdditionalMenu.d.ts',
contribEditSessions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribEditSessions.d.ts',
contribEditorContentMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribEditorContentMenu.d.ts',
contribIssueReporter: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribIssueReporter.d.ts',
contribLabelFormatterWorkspaceTooltip: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribLabelFormatterWorkspaceTooltip.d.ts',
contribMenuBarHome: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMenuBarHome.d.ts',
contribMergeEditorMenus: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMergeEditorMenus.d.ts',
Expand Down
29 changes: 29 additions & 0 deletions src/vs/workbench/services/issue/electron-sandbox/issueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ import { IIntegrityService } from 'vs/workbench/services/integrity/common/integr
import { ILogService } from 'vs/platform/log/common/log';
import { IIssueDataProvider, IIssueUriRequestHandler, IWorkbenchIssueService } from 'vs/workbench/services/issue/common/issue';
import { mainWindow } from 'vs/base/browser/window';
import { IMenuService, MenuId } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';

export class NativeIssueService implements IWorkbenchIssueService {
declare readonly _serviceBrand: undefined;

private readonly _handlers = new Map<string, IIssueUriRequestHandler>();
private readonly _providers = new Map<string, IIssueDataProvider>();
private readonly _activationEventReader = new ImplicitActivationAwareReader();
private issueReporterData!: IssueReporterData;
private foundExtension = false;

constructor(
@IIssueMainService private readonly issueMainService: IIssueMainService,
Expand All @@ -49,6 +53,8 @@ export class NativeIssueService implements IWorkbenchIssueService {
@IIntegrityService private readonly integrityService: IIntegrityService,
@IExtensionService private readonly extensionService: IExtensionService,
@ILogService private readonly logService: ILogService,
@IMenuService private readonly menuService: IMenuService,
@IContextKeyService private readonly contextKeyService: IContextKeyService
) {
ipcRenderer.on('vscode:triggerIssueUriRequestHandler', async (event: unknown, request: { replyChannel: string; extensionId: string }) => {
const result = await this.getIssueReporterUri(request.extensionId, CancellationToken.None);
Expand Down Expand Up @@ -82,6 +88,24 @@ export class NativeIssueService implements IWorkbenchIssueService {
const result = [this._providers.has(extensionId.toLowerCase()), this._handlers.has(extensionId.toLowerCase())];
ipcRenderer.send('vscode:triggerReporterStatusResponse', result);
});
ipcRenderer.on('vscode:triggerReporterMenu', async (event, arg) => {
const extensionId = arg.extensionId;

// creates menu from contributed
const menu = this.menuService.createMenu(MenuId.IssueReporter, this.contextKeyService);

// render menu and dispose
const actions = menu.getActions({ renderShortTitle: true }).flatMap(entry => entry[1]);
actions.forEach(action => {
if (action.item && 'source' in action.item && action.item.source?.id === extensionId) {
this.foundExtension = true;
action.run();
} else {
ipcRenderer.send('vscode:triggerReporterMenuResponse', undefined);
}
});
menu.dispose();
});
}

async openReporter(dataOverrides: Partial<IssueReporterData> = {}): Promise<void> {
Expand Down Expand Up @@ -154,6 +178,11 @@ export class NativeIssueService implements IWorkbenchIssueService {
isUnsupported,
githubAccessToken
}, dataOverrides);

this.issueReporterData = issueReporterData;
if (this.foundExtension) {
ipcRenderer.send('vscode:triggerReporterMenuResponse', this.issueReporterData);
}
return this.issueMainService.openReporter(issueReporterData);
}

Expand Down
7 changes: 7 additions & 0 deletions src/vscode-dts/vscode.proposed.contribIssueReporter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `issue reporter`-submenu contribution point
// https://github.com/microsoft/vscode/issues/196863