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

removing issue reporter API #209125

Merged
merged 4 commits into from
Apr 4, 2024
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
137 changes: 2 additions & 135 deletions src/vs/code/electron-sandbox/issue/issueReporterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class IssueReporter extends Disposable {
private readonly issueReporterModel: IssueReporterModel;
private numberOfSearchResultsDisplayed = 0;
private receivedSystemInfo = false;
private receivedExtensionData = false;
private receivedPerformanceInfo = false;
private shouldQueueSearch = false;
private hasBeenSubmitted = false;
Expand Down Expand Up @@ -264,50 +263,9 @@ export class IssueReporter extends Disposable {
if (extension.uri) {
const uri = URI.revive(extension.uri);
extension.bugsUrl = uri.toString();
} else {
const uri = await this.issueMainService.$getIssueReporterUri(extension.id);
extension.bugsUrl = uri.toString(true);
}

} catch (e) {
extension.hasIssueUriRequestHandler = false;
// The issue handler failed so fall back to old issue reporter experience.
this.renderBlocks();
}
}

private async getIssueDataFromExtension(extension: IssueReporterExtensionData): Promise<string> {
try {
const data = await this.issueMainService.$getIssueReporterData(extension.id);
extension.extensionData = data;
this.receivedExtensionData = true;
this.issueReporterModel.update({ extensionData: data });
return data;
} catch (e) {
extension.hasIssueDataProviders = false;
// The issue handler failed so fall back to old issue reporter experience.
this.renderBlocks();
throw e;
}
}

private async getIssueTemplateFromExtension(extension: IssueReporterExtensionData): Promise<string> {
try {
const data = await this.issueMainService.$getIssueReporterTemplate(extension.id);
extension.extensionTemplate = data;
return data;
} catch (e) {
throw e;
}
}

private async getReporterStatus(extension: IssueReporterExtensionData): Promise<boolean[]> {
try {
const data = await this.issueMainService.$getReporterStatus(extension.id, extension.name);
return data;
} catch (e) {
console.error(e);
return [false, false];
}
}

Expand Down Expand Up @@ -540,10 +498,6 @@ export class IssueReporter extends Disposable {
private isPreviewEnabled() {
const issueType = this.issueReporterModel.getData().issueType;

if (this.issueReporterModel.getData().selectedExtension?.hasIssueDataProviders && !this.receivedExtensionData) {
return false;
}

if (this.loadingExtensionData) {
return false;
}
Expand Down Expand Up @@ -573,10 +527,6 @@ export class IssueReporter extends Disposable {
return selectedExtension && selectedExtension.bugsUrl;
}

private getExtensionData(): string | undefined {
return this.issueReporterModel.getData().selectedExtension?.extensionData;
}

private searchVSCodeIssues(title: string, issueDescription?: string): void {
if (title) {
this.searchDuplicates(title, issueDescription);
Expand Down Expand Up @@ -850,24 +800,6 @@ export class IssueReporter extends Disposable {
show(extensionSelector);
}

if (fileOnExtension && selectedExtension?.hasIssueUriRequestHandler && !selectedExtension.hasIssueDataProviders) {
hide(titleTextArea);
hide(descriptionTextArea);
reset(descriptionTitle, localize('handlesIssuesElsewhere', "This extension handles issues outside of VS Code"));
reset(descriptionSubtitle, localize('elsewhereDescription', "The '{0}' extension prefers to use an external issue reporter. To be taken to that issue reporting experience, click the button below.", selectedExtension.displayName));
this.previewButton.label = localize('openIssueReporter', "Open External Issue Reporter");
return;
}

if (fileOnExtension && selectedExtension?.hasIssueDataProviders) {
const data = this.getExtensionData();
if (data) {
(extensionDataTextArea as HTMLElement).innerText = data.toString();
}
(extensionDataTextArea as HTMLTextAreaElement).readOnly = true;
show(extensionDataBlock);
}

if (fileOnExtension && selectedExtension?.data) {
const data = selectedExtension?.data;
(extensionDataTextArea as HTMLElement).innerText = data.toString();
Expand Down Expand Up @@ -986,18 +918,6 @@ export class IssueReporter extends Disposable {

private async createIssue(): Promise<boolean> {
const selectedExtension = this.issueReporterModel.getData().selectedExtension;
const hasUri = selectedExtension?.hasIssueUriRequestHandler;
const hasData = selectedExtension?.hasIssueDataProviders;
// Short circuit if the extension provides a custom issue handler
if (hasUri && !hasData) {
const url = this.getExtensionBugsUrl();
if (url) {
this.hasBeenSubmitted = true;
await this.nativeHostService.openExternal(url);
return true;
}
}

if (!this.validateInputs()) {
// If inputs are invalid, set focus to the first one and add listeners on them
// to detect further changes
Expand Down Expand Up @@ -1032,7 +952,7 @@ export class IssueReporter extends Disposable {
const issueTitle = (<HTMLInputElement>this.getElementById('issue-title')).value;
const issueBody = this.issueReporterModel.serialize();

let issueUrl = hasUri ? this.getExtensionBugsUrl() : this.getIssueUrl();
let issueUrl = this.getIssueUrl();
if (!issueUrl) {
console.error('No issue url found');
return false;
Expand Down Expand Up @@ -1338,58 +1258,6 @@ export class IssueReporter extends Disposable {
this.updateIssueReporterUri(extension);
}

// if extension does not have provider/handles, will check for either. If extension is already active, IPC will return [false, false] and will proceed as normal.
if (!extension.hasIssueDataProviders && !extension.hasIssueUriRequestHandler) {
const toActivate = await this.getReporterStatus(extension);
extension.hasIssueDataProviders = toActivate[0];
extension.hasIssueUriRequestHandler = toActivate[1];
}

if (extension.hasIssueUriRequestHandler && extension.hasIssueDataProviders) {
// update this first
const template = await this.getIssueTemplateFromExtension(extension);
const descriptionTextArea = this.getElementById('description')!;
const descriptionText = (descriptionTextArea as HTMLTextAreaElement).value;
if (descriptionText === '' || !descriptionText.includes(template)) {
const fullTextArea = descriptionText + (descriptionText === '' ? '' : '\n') + template;
(descriptionTextArea as HTMLTextAreaElement).value = fullTextArea;
this.issueReporterModel.update({ issueDescription: fullTextArea });
}
const extensionDataBlock = mainWindow.document.querySelector('.block-extension-data')!;
show(extensionDataBlock);

// Start loading for extension data.
const iconElement = document.createElement('span');
iconElement.classList.add(...ThemeIcon.asClassNameArray(Codicon.loading), 'codicon-modifier-spin');
this.setLoading(iconElement);
await this.getIssueDataFromExtension(extension);
this.removeLoading(iconElement);

// then update this
this.updateIssueReporterUri(extension);

} else if (extension.hasIssueUriRequestHandler) {
this.updateIssueReporterUri(extension);
} else if (extension.hasIssueDataProviders) {
const template = await this.getIssueTemplateFromExtension(extension);
const descriptionTextArea = this.getElementById('description')!;
const descriptionText = (descriptionTextArea as HTMLTextAreaElement).value;
if (descriptionText === '' || !descriptionText.includes(template)) {
const fullTextArea = descriptionText + (descriptionText === '' ? '' : '\n') + template;
(descriptionTextArea as HTMLTextAreaElement).value = fullTextArea;
this.issueReporterModel.update({ issueDescription: fullTextArea });
}
const extensionDataBlock = mainWindow.document.querySelector('.block-extension-data')!;
show(extensionDataBlock);

// Start loading for extension data.
const iconElement = document.createElement('span');
iconElement.classList.add(...ThemeIcon.asClassNameArray(Codicon.loading), 'codicon-modifier-spin');
this.setLoading(iconElement);
await this.getIssueDataFromExtension(extension);
this.removeLoading(iconElement);
}

this.validateSelectedExtension();
const title = (<HTMLInputElement>this.getElementById('issue-title')).value;
this.searchExtensionIssues(title);
Expand All @@ -1415,7 +1283,7 @@ export class IssueReporter extends Disposable {
}

const hasValidGitHubUrl = this.getExtensionGitHubUrl();
if (hasValidGitHubUrl || (extension.hasIssueUriRequestHandler && !extension.hasIssueDataProviders)) {
if (hasValidGitHubUrl) {
this.previewButton.enabled = true;
} else {
this.setExtensionValidationMessage();
Expand All @@ -1425,7 +1293,6 @@ export class IssueReporter extends Disposable {

private setLoading(element: HTMLElement) {
// Show loading
this.receivedExtensionData = false;
this.openReporter = true;
this.loadingExtensionData = true;
this.updatePreviewButtonState();
Expand Down
8 changes: 1 addition & 7 deletions src/vs/platform/issue/common/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { URI, UriComponents } from 'vs/base/common/uri';
import { UriComponents } from 'vs/base/common/uri';
import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';
import { PerformanceInfo, SystemInfo } from 'vs/platform/diagnostics/common/diagnostics';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
Expand Down Expand Up @@ -61,8 +61,6 @@ export interface IssueReporterExtensionData {
bugsUrl: string | undefined;
extensionData?: string;
extensionTemplate?: string;
hasIssueUriRequestHandler?: boolean;
hasIssueDataProviders?: boolean;
data?: string;
uri?: UriComponents;
}
Expand Down Expand Up @@ -141,10 +139,6 @@ export interface IIssueMainService {
$reloadWithExtensionsDisabled(): Promise<void>;
$showConfirmCloseDialog(): Promise<void>;
$showClipboardDialog(): Promise<boolean>;
$getIssueReporterUri(extensionId: string): Promise<URI>;
$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>;
}
83 changes: 1 addition & 82 deletions src/vs/platform/issue/electron-main/issueMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

import { BrowserWindow, BrowserWindowConstructorOptions, contentTracing, Display, IpcMainEvent, screen } from 'electron';
import { arch, release, type } from 'os';
import { Promises, raceTimeout, timeout } from 'vs/base/common/async';
import { raceTimeout } from 'vs/base/common/async';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { randomPath } from 'vs/base/common/extpath';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { FileAccess } from 'vs/base/common/network';
import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { listProcesses } from 'vs/base/node/ps';
import { validatedIpcMain } from 'vs/base/parts/ipc/electron-main/ipcMain';
import { localize } from 'vs/nls';
Expand Down Expand Up @@ -374,86 +373,6 @@ export class IssueMainService implements IIssueMainService {
return window;
}

async $getIssueReporterUri(extensionId: string): Promise<URI> {
const window = this.issueReporterWindowCheck();
const replyChannel = `vscode:triggerIssueUriRequestHandlerResponse${window.id}`;
return Promises.withAsyncBody<URI>(async (resolve, reject) => {

const cts = new CancellationTokenSource();
window.sendWhenReady('vscode:triggerIssueUriRequestHandler', cts.token, { replyChannel, extensionId });

validatedIpcMain.once(replyChannel, (_: unknown, data: string) => {
resolve(URI.parse(data));
});

try {
await timeout(5000);
cts.cancel();
reject(new Error('Timed out waiting for issue reporter URI'));
} finally {
validatedIpcMain.removeHandler(replyChannel);
}
});
}

async $getIssueReporterData(extensionId: string): Promise<string> {
const window = this.issueReporterWindowCheck();
const replyChannel = `vscode:triggerIssueDataProviderResponse${window.id}`;
return Promises.withAsyncBody<string>(async (resolve) => {

const cts = new CancellationTokenSource();
window.sendWhenReady('vscode:triggerIssueDataProvider', cts.token, { replyChannel, extensionId });

validatedIpcMain.once(replyChannel, (_: unknown, data: string) => {
resolve(data);
});

try {
await timeout(5000);
cts.cancel();
resolve('Error: Extension timed out waiting for issue reporter data');
} finally {
validatedIpcMain.removeHandler(replyChannel);
}
});
}

async $getIssueReporterTemplate(extensionId: string): Promise<string> {
const window = this.issueReporterWindowCheck();
const replyChannel = `vscode:triggerIssueDataTemplateResponse${window.id}`;
return Promises.withAsyncBody<string>(async (resolve) => {

const cts = new CancellationTokenSource();
window.sendWhenReady('vscode:triggerIssueDataTemplate', cts.token, { replyChannel, extensionId });

validatedIpcMain.once(replyChannel, (_: unknown, data: string) => {
resolve(data);
});

try {
await timeout(5000);
cts.cancel();
resolve('Error: Extension timed out waiting for issue reporter template');
} finally {
validatedIpcMain.removeHandler(replyChannel);
}
});
}

async $getReporterStatus(extensionId: string, extensionName: string): Promise<boolean[]> {
const defaultResult = [false, false];
const window = this.issueReporterWindowCheck();
const replyChannel = `vscode:triggerReporterStatus`;
const cts = new CancellationTokenSource();
window.sendWhenReady(replyChannel, cts.token, { replyChannel, extensionId, extensionName });
const result = await raceTimeout(new Promise(resolve => validatedIpcMain.once('vscode:triggerReporterStatusResponse', (_: unknown, data: boolean[]) => resolve(data))), 2000, () => {
this.logService.error('Error: Extension timed out waiting for reporter status');
cts.cancel();
});
return (result ?? defaultResult) as boolean[];
}


async $sendReporterMenu(extensionId: string, extensionName: string): Promise<IssueReporterData | undefined> {
const window = this.issueReporterWindowCheck();
const replyChannel = `vscode:triggerReporterMenu`;
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/api/browser/extensionHost.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ import './mainThreadShare';
import './mainThreadProfileContentHandlers';
import './mainThreadAiRelatedInformation';
import './mainThreadAiEmbeddingVector';
import './mainThreadIssueReporter';

export class ExtensionPoints implements IWorkbenchContribution {

Expand Down
Loading
Loading