Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/issue/electron-browser/issueService.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { getZoomLevel } from '../../../../base/browser/browser.js';
7
import { mainWindow } from '../../../../base/browser/window.js';
8
import { IExtensionManagementService } from '../../../../platform/extensionManagement/common/extensionManagement.js';
9
import { ExtensionType } from '../../../../platform/extensions/common/extensions.js';
10
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
11
import { buttonBackground, buttonForeground, buttonHoverBackground, foreground, inputActiveOptionBorder, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, scrollbarSliderActiveBackground, scrollbarSliderHoverBackground, textLinkActiveForeground, textLinkForeground } from '../../../../platform/theme/common/colorRegistry.js';
12
import { IColorTheme, IThemeService } from '../../../../platform/theme/common/themeService.js';
13
import { IWorkspaceTrustManagementService } from '../../../../platform/workspace/common/workspaceTrust.js';
14
import { SIDE_BAR_BACKGROUND } from '../../../common/theme.js';
15
import { IIssueFormService, IssueReporterData, IssueReporterExtensionData, IssueReporterStyles, IWorkbenchIssueService } from '../common/issue.js';
16
import { IWorkbenchAssignmentService } from '../../../services/assignment/common/assignmentService.js';
17
import { IAuthenticationService } from '../../../services/authentication/common/authentication.js';
18
import { IWorkbenchExtensionEnablementService } from '../../../services/extensionManagement/common/extensionManagement.js';
19
import { IIntegrityService } from '../../../services/integrity/common/integrity.js';
20
21
export class NativeIssueService implements IWorkbenchIssueService {
22
declare readonly _serviceBrand: undefined;
23
24
constructor(
25
@IIssueFormService private readonly issueFormService: IIssueFormService,
26
@IThemeService private readonly themeService: IThemeService,
27
@IExtensionManagementService private readonly extensionManagementService: IExtensionManagementService,
28
@IWorkbenchExtensionEnablementService private readonly extensionEnablementService: IWorkbenchExtensionEnablementService,
29
@IWorkspaceTrustManagementService private readonly workspaceTrustManagementService: IWorkspaceTrustManagementService,
30
@IWorkbenchAssignmentService private readonly experimentService: IWorkbenchAssignmentService,
31
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
32
@IIntegrityService private readonly integrityService: IIntegrityService,
33
) { }
34
35
async openReporter(dataOverrides: Partial<IssueReporterData> = {}): Promise<void> {
36
const extensionData: IssueReporterExtensionData[] = [];
37
try {
38
const extensions = await this.extensionManagementService.getInstalled();
39
const enabledExtensions = extensions.filter(extension => this.extensionEnablementService.isEnabled(extension) || (dataOverrides.extensionId && extension.identifier.id === dataOverrides.extensionId));
40
extensionData.push(...enabledExtensions.map((extension): IssueReporterExtensionData => {
41
const { manifest } = extension;
42
const manifestKeys = manifest.contributes ? Object.keys(manifest.contributes) : [];
43
const isTheme = !manifest.main && !manifest.browser && manifestKeys.length === 1 && manifestKeys[0] === 'themes';
44
const isBuiltin = extension.type === ExtensionType.System;
45
return {
46
name: manifest.name,
47
publisher: manifest.publisher,
48
version: manifest.version,
49
repositoryUrl: manifest.repository && manifest.repository.url,
50
bugsUrl: manifest.bugs && manifest.bugs.url,
51
displayName: manifest.displayName,
52
id: extension.identifier.id,
53
data: dataOverrides.data,
54
uri: dataOverrides.uri,
55
isTheme,
56
isBuiltin,
57
extensionData: 'Extensions data loading',
58
};
59
}));
60
} catch (e) {
61
extensionData.push({
62
name: 'Workbench Issue Service',
63
publisher: 'Unknown',
64
version: '0.0.0',
65
repositoryUrl: undefined,
66
bugsUrl: undefined,
67
extensionData: 'Extensions data loading',
68
displayName: `Extensions not loaded: ${e}`,
69
id: 'workbench.issue',
70
isTheme: false,
71
isBuiltin: true
72
});
73
}
74
const experiments = await this.experimentService.getCurrentExperiments();
75
76
let githubAccessToken = '';
77
try {
78
const githubSessions = await this.authenticationService.getSessions('github');
79
const potentialSessions = githubSessions.filter(session => session.scopes.includes('repo'));
80
githubAccessToken = potentialSessions[0]?.accessToken;
81
} catch (e) {
82
// Ignore
83
}
84
85
// air on the side of caution and have false be the default
86
let isUnsupported = false;
87
try {
88
isUnsupported = !(await this.integrityService.isPure()).isPure;
89
} catch (e) {
90
// Ignore
91
}
92
93
const theme = this.themeService.getColorTheme();
94
const issueReporterData: IssueReporterData = Object.assign({
95
styles: getIssueReporterStyles(theme),
96
zoomLevel: getZoomLevel(mainWindow),
97
enabledExtensions: extensionData,
98
experiments: experiments?.join('\n'),
99
restrictedMode: !this.workspaceTrustManagementService.isWorkspaceTrusted(),
100
isUnsupported,
101
githubAccessToken
102
}, dataOverrides);
103
104
return this.issueFormService.openReporter(issueReporterData);
105
}
106
107
}
108
109
export function getIssueReporterStyles(theme: IColorTheme): IssueReporterStyles {
110
return {
111
backgroundColor: getColor(theme, SIDE_BAR_BACKGROUND),
112
color: getColor(theme, foreground),
113
textLinkColor: getColor(theme, textLinkForeground),
114
textLinkActiveForeground: getColor(theme, textLinkActiveForeground),
115
inputBackground: getColor(theme, inputBackground),
116
inputForeground: getColor(theme, inputForeground),
117
inputBorder: getColor(theme, inputBorder),
118
inputActiveBorder: getColor(theme, inputActiveOptionBorder),
119
inputErrorBorder: getColor(theme, inputValidationErrorBorder),
120
inputErrorBackground: getColor(theme, inputValidationErrorBackground),
121
inputErrorForeground: getColor(theme, inputValidationErrorForeground),
122
buttonBackground: getColor(theme, buttonBackground),
123
buttonForeground: getColor(theme, buttonForeground),
124
buttonHoverBackground: getColor(theme, buttonHoverBackground),
125
sliderActiveColor: getColor(theme, scrollbarSliderActiveBackground),
126
sliderBackgroundColor: getColor(theme, SIDE_BAR_BACKGROUND),
127
sliderHoverColor: getColor(theme, scrollbarSliderHoverBackground),
128
};
129
}
130
131
function getColor(theme: IColorTheme, key: string): string | undefined {
132
const color = theme.getColor(key);
133
return color ? color.toString() : undefined;
134
}
135
136
registerSingleton(IWorkbenchIssueService, NativeIssueService, InstantiationType.Delayed);
137
138