Path: blob/main/src/vs/workbench/contrib/issue/common/issue.contribution.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable } from '../../../../base/common/lifecycle.js';6import { localize, localize2 } from '../../../../nls.js';7import { ICommandAction } from '../../../../platform/action/common/action.js';8import { Categories } from '../../../../platform/action/common/actionCommonCategories.js';9import { MenuId, MenuRegistry } from '../../../../platform/actions/common/actions.js';10import { CommandsRegistry, ICommandMetadata } from '../../../../platform/commands/common/commands.js';11import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';12import { INotificationService } from '../../../../platform/notification/common/notification.js';13import { IProductService } from '../../../../platform/product/common/productService.js';14import { IWorkbenchContribution } from '../../../common/contributions.js';15import { IssueReporterData, IWorkbenchIssueService } from './issue.js';1617const OpenIssueReporterActionId = 'workbench.action.openIssueReporter';18const OpenIssueReporterApiId = 'vscode.openIssueReporter';1920const OpenIssueReporterCommandMetadata: ICommandMetadata = {21description: 'Open the issue reporter and optionally prefill part of the form.',22args: [23{24name: 'options',25description: 'Data to use to prefill the issue reporter with.',26isOptional: true,27schema: {28oneOf: [29{30type: 'string',31description: 'The extension id to preselect.'32},33{34type: 'object',35properties: {36extensionId: {37type: 'string'38},39issueTitle: {40type: 'string'41},42issueBody: {43type: 'string'44}45}4647}48]49}50},51]52};5354interface OpenIssueReporterArgs {55readonly extensionId?: string;56readonly issueTitle?: string;57readonly issueBody?: string;58readonly extensionData?: string;59}6061export class BaseIssueContribution extends Disposable implements IWorkbenchContribution {62constructor(63@IProductService productService: IProductService,64@IConfigurationService configurationService: IConfigurationService,65) {66super();6768if (!configurationService.getValue<boolean>('telemetry.feedback.enabled')) {69this._register(CommandsRegistry.registerCommand({70id: 'workbench.action.openIssueReporter',71handler: function (accessor) {72const data = accessor.get(INotificationService);73data.info('Feedback is disabled.');7475},76}));77return;78}7980if (!productService.reportIssueUrl) {81return;82}8384this._register(CommandsRegistry.registerCommand({85id: OpenIssueReporterActionId,86handler: function (accessor, args?: string | [string] | OpenIssueReporterArgs) {87const data: Partial<IssueReporterData> =88typeof args === 'string'89? { extensionId: args }90: Array.isArray(args)91? { extensionId: args[0] }92: args ?? {};9394return accessor.get(IWorkbenchIssueService).openReporter(data);95},96metadata: OpenIssueReporterCommandMetadata97}));9899this._register(CommandsRegistry.registerCommand({100id: OpenIssueReporterApiId,101handler: function (accessor, args?: string | [string] | OpenIssueReporterArgs) {102const data: Partial<IssueReporterData> =103typeof args === 'string'104? { extensionId: args }105: Array.isArray(args)106? { extensionId: args[0] }107: args ?? {};108109return accessor.get(IWorkbenchIssueService).openReporter(data);110},111metadata: OpenIssueReporterCommandMetadata112}));113114const reportIssue: ICommandAction = {115id: OpenIssueReporterActionId,116title: localize2({ key: 'reportIssueInEnglish', comment: ['Translate this to "Report Issue in English" in all languages please!'] }, "Report Issue..."),117category: Categories.Help118};119120this._register(MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: reportIssue }));121122this._register(MenuRegistry.appendMenuItem(MenuId.MenubarHelpMenu, {123group: '3_feedback',124command: {125id: OpenIssueReporterActionId,126title: localize({ key: 'miReportIssue', comment: ['&& denotes a mnemonic', 'Translate this to "Report Issue in English" in all languages please!'] }, "Report &&Issue")127},128order: 3129}));130}131}132133134