src/vs/workbench/services/userDataProfile/common/userDataProfile.ts

155 LOC · 139 covered · 16 uncovered · 4 ranges · 983 concepts · 1 introducers · 540 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- userDataProfile.ts ×4
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 { isUndefined } from '../../../../base/common/types.js';
7 > import { Event } from '../../../../base/common/event.js';
8 > import { localize, localize2 } from '../../../../nls.js';
9 > import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
10 > import { IUserDataProfile, IUserDataProfileOptions, IUserDataProfileUpdateOptions, ProfileResourceType, ProfileResourceTypeFlags } from '../../../../platform/userDataProfile/common/userDataProfile.js';
11 > import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
12 > import { URI } from '../../../../base/common/uri.js';
13 > import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
14 > import { Codicon } from '../../../../base/common/codicons.js';
15 > import { ITreeItem, ITreeItemLabel } from '../../../common/views.js';
16 > import { CancellationToken } from '../../../../base/common/cancellation.js';
17 > import { IDisposable } from '../../../../base/common/lifecycle.js';
18 > import { IProductService } from '../../../../platform/product/common/productService.js';
19 >
20 > export interface DidChangeUserDataProfileEvent {
21 > readonly previous: IUserDataProfile;
22 > readonly profile: IUserDataProfile;
23 > join(promise: Promise<void>): void;
24 > }
25 >
26 > export const IUserDataProfileService = createDecorator<IUserDataProfileService>('IUserDataProfileService');
27 > export interface IUserDataProfileService {
28 > readonly _serviceBrand: undefined;
29 > readonly currentProfile: IUserDataProfile;
30 > readonly onDidChangeCurrentProfile: Event<DidChangeUserDataProfileEvent>;
31 > updateCurrentProfile(currentProfile: IUserDataProfile): Promise<void>;
32 > }
33 >
34 > export interface IProfileTemplateInfo {
35 > readonly name: string;
36 > readonly url: string;
37 > }
38 >
39 > export const IUserDataProfileManagementService = createDecorator<IUserDataProfileManagementService>('IUserDataProfileManagementService');
40 > export interface IUserDataProfileManagementService {
41 > readonly _serviceBrand: undefined;
42 >
43 > createProfile(name: string, options?: IUserDataProfileOptions): Promise<IUserDataProfile>;
44 > createAndEnterProfile(name: string, options?: IUserDataProfileOptions): Promise<IUserDataProfile>;
45 > createAndEnterTransientProfile(): Promise<IUserDataProfile>;
46 > removeProfile(profile: IUserDataProfile): Promise<void>;
47 > updateProfile(profile: IUserDataProfile, updateOptions: IUserDataProfileUpdateOptions): Promise<IUserDataProfile>;
48 > switchProfile(profile: IUserDataProfile): Promise<void>;
49 > getBuiltinProfileTemplates(): Promise<IProfileTemplateInfo[]>;
50 > getDefaultProfileToUse(): IUserDataProfile;
51 > }
52 >
53 > export interface IUserDataProfileTemplate {
54 > readonly name: string;
55 > readonly icon?: string;
56 > readonly settings?: string;
57 > readonly keybindings?: string;
58 > readonly tasks?: string;
59 > readonly snippets?: string;
60 > readonly globalState?: string;
61 > readonly extensions?: string;
62 > readonly mcp?: string;
63 > }
64 >
65 > export function isUserDataProfileTemplate(thing: unknown): thing is IUserDataProfileTemplate {
66 const candidate = thing as IUserDataProfileTemplate | undefined;
67
68 return !!(candidate && typeof candidate === 'object'
69 && (isUndefined(candidate.settings) || typeof candidate.settings === 'string')
70 && (isUndefined(candidate.globalState) || typeof candidate.globalState === 'string')
71 && (isUndefined(candidate.extensions) || typeof candidate.extensions === 'string')
72 && (isUndefined(candidate.mcp) || typeof candidate.mcp === 'string'));
73 }
75 > export const PROFILE_URL_AUTHORITY = 'profile';
76 > export function toUserDataProfileUri(path: string, productService: IProductService): URI {
77 return URI.from({
78 scheme: productService.urlProtocol,
79 authority: PROFILE_URL_AUTHORITY,
80 path: path.startsWith('/') ? path : `/${path}`
81 });
82 }
84 > export const PROFILE_URL_AUTHORITY_PREFIX = 'profile-';
85 > export function isProfileURL(uri: URI): boolean {
86 return uri.authority === PROFILE_URL_AUTHORITY || new RegExp(`^${PROFILE_URL_AUTHORITY_PREFIX}`).test(uri.authority);
87 }
89 > export interface IUserDataProfileCreateOptions extends IUserDataProfileOptions {
90 > readonly name?: string;
91 > readonly resourceTypeFlags?: ProfileResourceTypeFlags;
92 > }
93 >
94 > export interface IProfileImportOptions extends IUserDataProfileCreateOptions {
95 > readonly name?: string;
96 > readonly icon?: string;
97 > readonly mode?: 'apply';
98 > }
99 >
100 > export const IUserDataProfileImportExportService = createDecorator<IUserDataProfileImportExportService>('IUserDataProfileImportExportService');
101 > export interface IUserDataProfileImportExportService {
102 > readonly _serviceBrand: undefined;
103 >
104 > registerProfileContentHandler(id: string, profileContentHandler: IUserDataProfileContentHandler): IDisposable;
105 > unregisterProfileContentHandler(id: string): void;
106 >
107 > resolveProfileTemplate(uri: URI): Promise<IUserDataProfileTemplate | null>;
108 > exportProfile(profile: IUserDataProfile, exportFlags?: ProfileResourceTypeFlags): Promise<void>;
109 > createFromProfile(from: IUserDataProfile, options: IUserDataProfileCreateOptions, token: CancellationToken): Promise<IUserDataProfile | undefined>;
110 > createProfileFromTemplate(profileTemplate: IUserDataProfileTemplate, options: IUserDataProfileCreateOptions, token: CancellationToken): Promise<IUserDataProfile | undefined>;
111 > createTroubleshootProfile(): Promise<void>;
112 > }
113 >
114 > export interface IProfileResourceInitializer {
115 > initialize(content: string): Promise<void>;
116 > }
117 >
118 > export interface IProfileResource {
119 > getContent(profile: IUserDataProfile): Promise<string>;
120 > apply(content: string, profile: IUserDataProfile): Promise<void>;
121 > }
122 >
123 > export interface IProfileResourceTreeItem extends ITreeItem {
124 > readonly type: ProfileResourceType;
125 > readonly label: ITreeItemLabel;
126 > isFromDefaultProfile(): boolean;
127 > getChildren(): Promise<IProfileResourceChildTreeItem[] | undefined>;
128 > getContent(): Promise<string>;
129 > }
130 >
131 > export interface IProfileResourceChildTreeItem extends ITreeItem {
132 > parent: IProfileResourceTreeItem;
133 > }
134 >
135 > export interface ISaveProfileResult {
136 > readonly id: string;
137 > readonly link: URI;
138 > }
139 >
140 > export interface IUserDataProfileContentHandler {
141 > readonly name: string;
142 > readonly description?: string;
143 > readonly extensionId?: string;
144 > saveProfile(name: string, content: string, token: CancellationToken): Promise<ISaveProfileResult | null>;
145 > readProfile(idOrUri: string | URI, token: CancellationToken): Promise<string | null>;
146 > }
147 >
148 > export const defaultUserDataProfileIcon = registerIcon('defaultProfile-icon', Codicon.settings, localize('defaultProfileIcon', 'Icon for Default Profile.'));
149 >
150 > export const PROFILES_TITLE = localize2('profiles', 'Profiles');
151 > export const PROFILES_CATEGORY = { ...PROFILES_TITLE };
152 > export const PROFILE_EXTENSION = 'code-profile';
153 > export const PROFILE_FILTER = [{ name: localize('profile', "Profile"), extensions: [PROFILE_EXTENSION] }];
154 > export const CURRENT_PROFILE_CONTEXT = new RawContextKey<string>('currentProfile', '');
155 > export const HAS_PROFILES_CONTEXT = new RawContextKey<boolean>('hasProfiles', false);