@codingame/monaco-vscode-api 5.1.2 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -198,6 +198,8 @@ Additionally, several packages that include the VSCode version of some services
198
198
  - Support for [viewsWelcome contribution point](https://code.visualstudio.com/api/references/contribution-points#contributes.viewsWelcome). *Hint*: It only makes sense to enable it when *Views* or *Workbench* service are used.
199
199
  - **Walkthrough**: `@codingame/monaco-vscode-walkthrough-service-override`
200
200
  - Getting Started page and support for [walkthrough contribution point](https://code.visualstudio.com/api/references/contribution-points#contributes.walkthroughs). *Hint*: It only makes sense to enable it when *Views* or *Workbench* service are used.
201
+ - **User data profile**: `@codingame/monaco-vscode-user-data-profile-service-override`
202
+ - User profiles support
201
203
  - **User data sync**: `@codingame/monaco-vscode-user-data-sync-service-override`
202
204
  - Support for user data sync. ⚠️ It can't really be used as it relies on a [closed source backend from microsoft](https://code.visualstudio.com/docs/editor/settings-sync#_can-i-use-a-different-backend-or-service-for-settings-sync) for the moment ⚠️
203
205
  - **Ai**: `@codingame/monaco-vscode-ai-service-override`
package/extensions.d.ts CHANGED
@@ -100,6 +100,7 @@ export { IExtensionContributions } from './vscode/src/vs/platform/extensions/com
100
100
  import { IDisposable } from './vscode/src/vs/base/common/lifecycle.js';
101
101
  export { ITranslations } from './vscode/src/vs/platform/extensionManagement/common/extensionNls.js';
102
102
  import { ExtensionHostKind } from './vscode/src/vs/workbench/services/extensions/common/extensionHostKind.js';
103
+ export { ExtensionFileMetadata } from './service-override/files.js';
103
104
 
104
105
  type ApiFactory = (extensionId?: string) => Promise<typeof vscode>;
105
106
  declare function registerLocalApiFactory(_apiFactory: ApiFactory): void;
package/extensions.js CHANGED
@@ -13,31 +13,20 @@ import { IWorkbenchExtensionEnablementService } from './vscode/src/vs/workbench/
13
13
  import { StandaloneServices } from './vscode/src/vs/editor/standalone/browser/standaloneServices.js';
14
14
  import { ExtensionManifestTranslator } from './vscode/src/vs/platform/extensionManagement/common/extensionsScannerService.js';
15
15
  import { language } from './vscode/src/vs/base/common/platform.js';
16
- import { CustomSchemas, registerExtensionFile } from '@codingame/monaco-vscode-files-service-override';
16
+ import { CustomSchemas, registerExtensionFile, RegisteredUriFile } from '@codingame/monaco-vscode-files-service-override';
17
17
  import { waitServicesReady } from './lifecycle.js';
18
- import { throttle, memoized } from './tools.js';
18
+ import { throttle } from './tools.js';
19
19
  import { setDefaultApi } from './api.js';
20
20
  import { getBuiltInExtensionTranslationsUris } from './l10n.js';
21
21
  let apiFactory;
22
22
  function registerLocalApiFactory(_apiFactory) {
23
23
  apiFactory = _apiFactory;
24
24
  }
25
- function registerExtensionFileUrl(extensionLocation, filePath, url, mimeType) {
25
+ function registerExtensionFileUrl(extensionLocation, filePath, url, metadataOrMimeType) {
26
26
  const fileDisposable = new DisposableStore();
27
27
  fileDisposable.add(FileAccess.registerStaticBrowserUri(joinPath(extensionLocation, filePath), ( URI.parse(url))));
28
- fileDisposable.add(registerExtensionFile(extensionLocation, filePath, memoized(async () => {
29
- const response = await fetch(url, {
30
- headers: mimeType != null
31
- ? {
32
- Accept: mimeType
33
- }
34
- : {}
35
- });
36
- if (response.status !== 200) {
37
- throw new Error(response.statusText);
38
- }
39
- return new Uint8Array(await response.arrayBuffer());
40
- })));
28
+ const metadata = typeof metadataOrMimeType === 'string' ? { mimeType: metadataOrMimeType } : metadataOrMimeType;
29
+ fileDisposable.add(registerExtensionFile(new RegisteredUriFile(joinPath(extensionLocation, filePath), url, metadata)));
41
30
  return fileDisposable;
42
31
  }
43
32
  const deltaExtensions = throttle(async ({ toAdd, toRemove }) => {
@@ -129,8 +118,8 @@ function registerExtension(manifest, extHostKind, { path = '/', system = false,
129
118
  }
130
119
  };
131
120
  if (extHostKind !== 3 ) {
132
- function registerFileUrl(path, url, mimeType) {
133
- return registerExtensionFileUrl(location, path, url, mimeType);
121
+ function registerFileUrl(path, url, metadataOrMimeType) {
122
+ return registerExtensionFileUrl(location, path, url, metadataOrMimeType);
134
123
  }
135
124
  api = {
136
125
  ...api,
@@ -206,6 +206,7 @@ import { NullExtensionService } from './vscode/src/vs/workbench/services/extensi
206
206
  import { toUserDataProfile } from './vscode/src/vs/platform/userDataProfile/common/userDataProfile.js';
207
207
  import { ILanguageModelStatsService } from './vscode/src/vs/workbench/contrib/chat/common/languageModelStats.service.js';
208
208
  import { IAccessibleViewInformationService } from './vscode/src/vs/workbench/services/accessibility/common/accessibleViewInformationService.service.js';
209
+ import { IUserDataProfileStorageService } from './vscode/src/vs/platform/userDataProfile/common/userDataProfileStorageService.service.js';
209
210
  import { getExtensionIdProvidingCurrentLocale, getBuiltInExtensionTranslationsUris } from './l10n.js';
210
211
  import { unsupported } from './tools.js';
211
212
  var _a;
@@ -722,6 +723,14 @@ UserDataProfilesService = __decorate([
722
723
  ( __param(0, IUserDataProfileService))
723
724
  ], UserDataProfilesService);
724
725
  registerSingleton(IUserDataProfilesService, UserDataProfilesService, 0 );
726
+ registerSingleton(IUserDataProfileStorageService, class UserDataProfileStorageService {
727
+ constructor() {
728
+ this.onDidChange = Event.None;
729
+ this.readStorageData = unsupported;
730
+ this.updateStorageData = unsupported;
731
+ this.withProfileScopedStorageService = unsupported;
732
+ }
733
+ }, 0 );
725
734
  let InjectedUserDataProfileService = class InjectedUserDataProfileService extends UserDataProfileService {
726
735
  constructor(environmentService) {
727
736
  super({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-api",
3
- "version": "5.1.2",
3
+ "version": "5.3.0",
4
4
  "description": "VSCode public API plugged on the monaco editor",
5
5
  "keywords": [],
6
6
  "author": {
@@ -99,12 +99,12 @@
99
99
  "dependencies": {
100
100
  "@vscode/iconv-lite-umd": "0.7.0",
101
101
  "jschardet": "3.0.0",
102
- "@codingame/monaco-vscode-quickaccess-service-override": "5.1.2",
103
- "@codingame/monaco-vscode-files-service-override": "5.1.2",
104
- "@codingame/monaco-vscode-extensions-service-override": "5.1.2",
105
- "@codingame/monaco-vscode-environment-service-override": "5.1.2",
106
- "@codingame/monaco-vscode-layout-service-override": "5.1.2",
107
- "@codingame/monaco-vscode-host-service-override": "5.1.2",
108
- "@codingame/monaco-vscode-base-service-override": "5.1.2"
102
+ "@codingame/monaco-vscode-files-service-override": "5.3.0",
103
+ "@codingame/monaco-vscode-quickaccess-service-override": "5.3.0",
104
+ "@codingame/monaco-vscode-extensions-service-override": "5.3.0",
105
+ "@codingame/monaco-vscode-environment-service-override": "5.3.0",
106
+ "@codingame/monaco-vscode-layout-service-override": "5.3.0",
107
+ "@codingame/monaco-vscode-host-service-override": "5.3.0",
108
+ "@codingame/monaco-vscode-base-service-override": "5.3.0"
109
109
  }
110
110
  }
@@ -1,72 +1,120 @@
1
1
  import { IEditorOverrideServices } from '../vscode/src/vs/editor/standalone/browser/standaloneServices.js';
2
2
  export { InMemoryFileSystemProvider } from '../vscode/src/vs/platform/files/common/inMemoryFilesystemProvider.js';
3
3
  import { URI } from '../vscode/src/vs/base/common/uri.js';
4
- import { FileType, IStat, IFileSystemProviderWithFileReadWriteCapability, IFileChange, IWatchOptions, IFileWriteOptions, IFileDeleteOptions, IFileOverwriteOptions, IFileSystemProvider, FileSystemProviderCapabilities, FileChangeType } from '../vscode/src/vs/platform/files/common/files.js';
4
+ import { FileType, IStat, IFileSystemProviderWithFileReadWriteCapability, IFileSystemProviderWithOpenReadWriteCloseCapability, IFileSystemProviderWithFileReadStreamCapability, IFileSystemProviderWithFileAtomicReadCapability, IFileSystemProviderWithFileAtomicWriteCapability, IFileSystemProviderWithFileAtomicDeleteCapability, IFileChange, IFileReadStreamOptions, IFileWriteOptions, IWatchOptions, IFileDeleteOptions, IFileOverwriteOptions, IFileSystemProvider, FileSystemProviderCapabilities, FileChangeType } from '../vscode/src/vs/platform/files/common/files.js';
5
5
  export { FilePermission, FileSystemProviderError, FileSystemProviderErrorCode } from '../vscode/src/vs/platform/files/common/files.js';
6
6
  import { Disposable, IDisposable } from '../vscode/src/vs/base/common/lifecycle.js';
7
7
  import { Emitter, Event } from '../vscode/src/vs/base/common/event.js';
8
8
  export { HTMLFileSystemProvider } from '../vscode/src/vs/platform/files/browser/htmlFileSystemProvider.js';
9
9
  import { IndexedDBFileSystemProvider } from '../vscode/src/vs/platform/files/browser/indexedDBFileSystemProvider.js';
10
10
  export { IndexedDB } from '../vscode/src/vs/base/browser/indexedDB.js';
11
+ import { ReadableStreamEvents } from '../vscode/src/vs/base/common/stream.js';
12
+ import { CancellationToken } from '../vscode/src/vs/base/common/cancellation.js';
11
13
 
12
- declare abstract class RegisteredFile {
14
+ interface _RegisteredNode {
15
+ type: FileType;
16
+ stats(): Promise<IStat>;
17
+ onDidDelete: Event<void>;
18
+ onDidChange: Event<void>;
19
+ }
20
+ interface RegisteredFileNode extends _RegisteredNode {
21
+ type: FileType.File;
22
+ uri: URI;
23
+ read(): Promise<Uint8Array>;
24
+ readStream?(): Promise<ReadableStream<Uint8Array>>;
25
+ write(content: Uint8Array): Promise<void>;
26
+ delete(): void;
27
+ }
28
+ interface RegisteredDirectoryNode extends _RegisteredNode {
29
+ type: FileType.Directory;
30
+ addChild(name: string, node: RegisteredNode): IDisposable;
31
+ deleteChild(name: string): boolean;
32
+ getChildren(name: string): RegisteredNode | undefined;
33
+ read(): [string, FileType][];
34
+ }
35
+ type RegisteredNode = RegisteredFileNode | RegisteredDirectoryNode;
36
+ declare abstract class RegisteredFile implements RegisteredFileNode {
13
37
  uri: URI;
14
38
  private readonly;
15
39
  protected ctime: number;
16
40
  protected mtime: number;
17
- readonly type: FileType;
41
+ readonly type = FileType.File;
18
42
  protected _onDidChange: Emitter<void>;
19
43
  onDidChange: Event<void>;
20
44
  protected _onDidDelete: Emitter<void>;
21
45
  onDidDelete: Event<void>;
22
- protected _onDidRename: Emitter<{
23
- from: URI;
24
- to: URI;
25
- }>;
26
- onDidRename: Event<{
27
- from: URI;
28
- to: URI;
29
- }>;
30
46
  constructor(uri: URI, readonly: boolean);
31
47
  stats(): Promise<IStat>;
32
- getSize(): Promise<number>;
33
- abstract read(): Promise<string | Uint8Array>;
34
- abstract write(content: string): Promise<void>;
48
+ abstract getSize(): Promise<number>;
35
49
  delete(): Promise<void>;
36
- rename(to: URI): Promise<void>;
50
+ abstract read(): Promise<Uint8Array>;
51
+ abstract write(content: Uint8Array): Promise<void>;
37
52
  }
38
53
  declare class RegisteredReadOnlyFile extends RegisteredFile {
39
- read: () => Promise<string | Uint8Array>;
40
- constructor(uri: URI, read: () => Promise<string | Uint8Array>);
54
+ read: () => Promise<Uint8Array>;
55
+ private size;
56
+ constructor(uri: URI, read: () => Promise<Uint8Array>, size: number);
57
+ getSize(): Promise<number>;
58
+ write(): Promise<void>;
59
+ delete(): Promise<void>;
60
+ }
61
+ interface ExtensionFileMetadata {
62
+ mimeType?: string;
63
+ size?: number;
64
+ }
65
+ declare class RegisteredUriFile extends RegisteredFile {
66
+ private url;
67
+ private metadata?;
68
+ constructor(location: URI, url: string, metadata?: ExtensionFileMetadata | undefined);
69
+ private fetch;
70
+ getSize(): Promise<number>;
71
+ read(): Promise<Uint8Array>;
72
+ readStream(): Promise<ReadableStream<Uint8Array>>;
41
73
  write(): Promise<void>;
42
74
  delete(): Promise<void>;
43
- rename(): Promise<void>;
44
75
  }
45
76
  declare class RegisteredMemoryFile extends RegisteredFile {
46
77
  private content;
47
- constructor(uri: URI, content: string);
48
- read(): Promise<string | Uint8Array>;
49
- write(content: string): Promise<void>;
78
+ constructor(uri: URI, content: string | Uint8Array);
79
+ getSize(): Promise<number>;
80
+ read(): Promise<Uint8Array>;
81
+ write(content: Uint8Array): Promise<void>;
50
82
  }
51
- declare class RegisteredFileSystemProvider extends Disposable implements IFileSystemProviderWithFileReadWriteCapability {
52
- private files;
53
- capabilities: number;
54
- constructor(readonly: boolean);
83
+ declare class RegisteredFileSystemProvider extends Disposable implements IFileSystemProviderWithFileReadWriteCapability, IFileSystemProviderWithOpenReadWriteCloseCapability, IFileSystemProviderWithFileReadStreamCapability, IFileSystemProviderWithFileAtomicReadCapability, IFileSystemProviderWithFileAtomicWriteCapability, IFileSystemProviderWithFileAtomicDeleteCapability {
84
+ private memoryFdCounter;
85
+ private readonly fdMemory;
86
+ private rootByAuthority;
55
87
  onDidChangeCapabilities: Event<any>;
56
88
  _onDidChangeFile: Emitter<readonly IFileChange[]>;
57
89
  onDidChangeFile: Event<readonly IFileChange[]>;
58
- private formatUri;
59
- registerFile(file: RegisteredFile): IDisposable;
90
+ capabilities: number;
91
+ constructor(readonly: boolean);
92
+ open(resource: URI): Promise<number>;
93
+ close(fd: number): Promise<void>;
94
+ read(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number>;
95
+ write(fd: number, pos: number, data: Uint8Array, offset: number, length: number): Promise<number>;
96
+ private _lookupRoot;
97
+ private _lookup;
98
+ private _lookupAsDirectory;
99
+ private _lookupAsFile;
100
+ registerFile(file: RegisteredFileNode): IDisposable;
60
101
  stat(resource: URI): Promise<IStat>;
102
+ readdirSync(resource: URI): [string, FileType][];
61
103
  readdir(resource: URI): Promise<[string, FileType][]>;
62
104
  readFile(resource: URI): Promise<Uint8Array>;
105
+ readFileStream(resource: URI, opts: IFileReadStreamOptions, token: CancellationToken): ReadableStreamEvents<Uint8Array>;
63
106
  watch(): IDisposable;
64
- writeFile(resource: URI, content: Uint8Array): Promise<void>;
107
+ writeFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void>;
108
+ rename(): Promise<void>;
109
+ mkdirSync(resource: URI): RegisteredDirectoryNode;
110
+ mkdir(): Promise<void>;
111
+ private deleteSync;
65
112
  delete(resource: URI): Promise<void>;
66
- rename(from: URI, to: URI): Promise<void>;
67
- mkdir(): Promise<never>;
113
+ private _bufferedChanges;
114
+ private _fireSoonHandle?;
115
+ private _fireSoon;
68
116
  }
69
- declare class OverlayFileSystemProvider implements IFileSystemProviderWithFileReadWriteCapability {
117
+ declare class OverlayFileSystemProvider implements IFileSystemProviderWithFileReadWriteCapability, IFileSystemProviderWithFileReadStreamCapability, IFileSystemProviderWithFileAtomicReadCapability, IFileSystemProviderWithFileAtomicWriteCapability, IFileSystemProviderWithFileAtomicDeleteCapability {
70
118
  private providers;
71
119
  register(priority: number, provider: IFileSystemProviderWithFileReadWriteCapability): IDisposable;
72
120
  get delegates(): IFileSystemProviderWithFileReadWriteCapability[];
@@ -77,9 +125,11 @@ declare class OverlayFileSystemProvider implements IFileSystemProviderWithFileRe
77
125
  onDidChangeOverlays: Event<void>;
78
126
  capabilities: number;
79
127
  private readFromDelegates;
128
+ private readFromDelegatesSync;
80
129
  private writeToDelegates;
81
130
  stat(resource: URI): Promise<IStat>;
82
131
  readFile(resource: URI): Promise<Uint8Array>;
132
+ readFileStream(resource: URI, opts: IFileReadStreamOptions, token: CancellationToken): ReadableStreamEvents<Uint8Array>;
83
133
  readdir(resource: URI): Promise<[string, FileType][]>;
84
134
  watch(resource: URI, opts: IWatchOptions): IDisposable;
85
135
  writeFile(resource: URI, content: Uint8Array, opts: IFileWriteOptions): Promise<void>;
@@ -135,7 +185,7 @@ declare function getServiceOverride(): IEditorOverrideServices;
135
185
  * the default file system provider for a given scheme.
136
186
  */
137
187
  declare function registerCustomProvider(scheme: string, provider: IFileSystemProvider): void;
138
- declare function registerExtensionFile(extensionLocation: URI, filePath: string, getContent: () => Promise<string | Uint8Array>): IDisposable;
188
+ declare function registerExtensionFile(file: RegisteredFileNode): IDisposable;
139
189
  /**
140
190
  * Can be used to create a file before the fileService is initialized
141
191
  */
@@ -162,4 +212,4 @@ declare function registerHTMLFileSystemProvider(): void;
162
212
  */
163
213
  declare function registerFileSystemOverlay(priority: number, provider: IFileSystemProviderWithFileReadWriteCapability): IDisposable;
164
214
 
165
- export { CustomSchemas, DelegateFileSystemProvider, EmptyFileSystemProvider, FileChangeType, FileSystemProviderCapabilities, FileType, IFileChange, IFileDeleteOptions, IFileOverwriteOptions, IFileSystemProviderWithFileReadWriteCapability, IFileWriteOptions, IStat, IWatchOptions, IndexedDBFileSystemProvider, OverlayFileSystemProvider, RegisteredFile, RegisteredFileSystemProvider, RegisteredMemoryFile, RegisteredReadOnlyFile, createIndexedDBProviders, getServiceOverride as default, initFile, registerCustomProvider, registerExtensionFile, registerFileSystemOverlay, registerHTMLFileSystemProvider };
215
+ export { CustomSchemas, DelegateFileSystemProvider, EmptyFileSystemProvider, type ExtensionFileMetadata, FileChangeType, FileSystemProviderCapabilities, FileType, IFileChange, IFileDeleteOptions, IFileOverwriteOptions, IFileSystemProviderWithFileReadWriteCapability, IFileWriteOptions, IStat, IWatchOptions, IndexedDBFileSystemProvider, OverlayFileSystemProvider, RegisteredFile, RegisteredFileSystemProvider, RegisteredMemoryFile, RegisteredReadOnlyFile, RegisteredUriFile, createIndexedDBProviders, getServiceOverride as default, initFile, registerCustomProvider, registerExtensionFile, registerFileSystemOverlay, registerHTMLFileSystemProvider };
@@ -0,0 +1,5 @@
1
+ import { IEditorOverrideServices } from '../vscode/src/vs/editor/standalone/browser/standaloneServices.js';
2
+
3
+ declare function getServiceOverride(): IEditorOverrideServices;
4
+
5
+ export { getServiceOverride as default };
@@ -6839,19 +6839,56 @@ export namespace languages {
6839
6839
  * current position itself.
6840
6840
  */
6841
6841
  range?: IRange;
6842
+ /**
6843
+ * Can increase the verbosity of the hover
6844
+ */
6845
+ canIncreaseVerbosity?: boolean;
6846
+ /**
6847
+ * Can decrease the verbosity of the hover
6848
+ */
6849
+ canDecreaseVerbosity?: boolean;
6842
6850
  }
6843
6851
 
6844
6852
  /**
6845
6853
  * The hover provider interface defines the contract between extensions and
6846
6854
  * the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
6847
6855
  */
6848
- export interface HoverProvider {
6856
+ export interface HoverProvider<THover = Hover> {
6849
6857
  /**
6850
- * Provide a hover for the given position and document. Multiple hovers at the same
6858
+ * Provide a hover for the given position, context and document. Multiple hovers at the same
6851
6859
  * position will be merged by the editor. A hover can have a range which defaults
6852
6860
  * to the word range at the position when omitted.
6853
6861
  */
6854
- provideHover(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Hover>;
6862
+ provideHover(model: editor.ITextModel, position: Position, token: CancellationToken, context?: HoverContext<THover>): ProviderResult<THover>;
6863
+ }
6864
+
6865
+ export interface HoverContext<THover = Hover> {
6866
+ /**
6867
+ * Hover verbosity request
6868
+ */
6869
+ verbosityRequest?: HoverVerbosityRequest<THover>;
6870
+ }
6871
+
6872
+ export interface HoverVerbosityRequest<THover = Hover> {
6873
+ /**
6874
+ * Whether to increase or decrease the hover's verbosity
6875
+ */
6876
+ action: HoverVerbosityAction;
6877
+ /**
6878
+ * The previous hover for the same position
6879
+ */
6880
+ previousHover: THover;
6881
+ }
6882
+
6883
+ export enum HoverVerbosityAction {
6884
+ /**
6885
+ * Increase the verbosity of the hover
6886
+ */
6887
+ Increase = 0,
6888
+ /**
6889
+ * Decrease the verbosity of the hover
6890
+ */
6891
+ Decrease = 1
6855
6892
  }
6856
6893
 
6857
6894
  export enum CompletionItemKind {
@@ -7862,13 +7899,19 @@ export namespace languages {
7862
7899
  AIGenerated = 1
7863
7900
  }
7864
7901
 
7902
+ export enum NewSymbolNameTriggerKind {
7903
+ Invoke = 0,
7904
+ Automatic = 1
7905
+ }
7906
+
7865
7907
  export interface NewSymbolName {
7866
7908
  readonly newSymbolName: string;
7867
7909
  readonly tags?: readonly NewSymbolNameTag[];
7868
7910
  }
7869
7911
 
7870
7912
  export interface NewSymbolNamesProvider {
7871
- provideNewSymbolNames(model: editor.ITextModel, range: IRange, token: CancellationToken): ProviderResult<NewSymbolName[]>;
7913
+ supportsAutomaticNewSymbolNamesTriggerKind?: Promise<boolean | undefined>;
7914
+ provideNewSymbolNames(model: editor.ITextModel, range: IRange, triggerKind: NewSymbolNameTriggerKind, token: CancellationToken): ProviderResult<NewSymbolName[]>;
7872
7915
  }
7873
7916
 
7874
7917
  export interface Command {
@@ -0,0 +1,3 @@
1
+ import { createDecorator } from '../../instantiation/common/instantiation.js';
2
+ const IUserDataProfileStorageService = ( createDecorator('IUserDataProfileStorageService'));
3
+ export { IUserDataProfileStorageService };
@@ -0,0 +1,290 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { BroadcastDataChannel } from '../../../../base/browser/broadcast.js';
3
+ import { isSafari } from '../../../../base/browser/browser.js';
4
+ import { getActiveWindow } from '../../../../base/browser/dom.js';
5
+ import { IndexedDB } from '../../../../base/browser/indexedDB.js';
6
+ import { DeferredPromise, Promises } from '../../../../base/common/async.js';
7
+ import { toErrorMessage } from '../../../../base/common/errorMessage.js';
8
+ import { Emitter } from '../../../../base/common/event.js';
9
+ import { DisposableStore, Disposable } from '../../../../base/common/lifecycle.js';
10
+ import { assertIsDefined } from '../../../../base/common/types.js';
11
+ import { Storage, isStorageItemsChangeEvent, InMemoryStorageDatabase } from '../../../../base/parts/storage/common/storage.js';
12
+ import { ILogService } from '../../../../platform/log/common/log.service.js';
13
+ import { AbstractStorageService, isProfileUsingDefaultStorage, IS_NEW_KEY } from '../../../../platform/storage/common/storage.js';
14
+ import { isUserDataProfile } from '../../../../platform/userDataProfile/common/userDataProfile.js';
15
+ var BrowserStorageService_1;
16
+ let BrowserStorageService = class BrowserStorageService extends AbstractStorageService {
17
+ static { BrowserStorageService_1 = this; }
18
+ static { this.BROWSER_DEFAULT_FLUSH_INTERVAL = 5 * 1000; }
19
+ get hasPendingUpdate() {
20
+ return Boolean(this.applicationStorageDatabase?.hasPendingUpdate ||
21
+ this.profileStorageDatabase?.hasPendingUpdate ||
22
+ this.workspaceStorageDatabase?.hasPendingUpdate);
23
+ }
24
+ constructor(workspace, userDataProfileService, logService) {
25
+ super({ flushInterval: BrowserStorageService_1.BROWSER_DEFAULT_FLUSH_INTERVAL });
26
+ this.workspace = workspace;
27
+ this.userDataProfileService = userDataProfileService;
28
+ this.logService = logService;
29
+ this.applicationStoragePromise = ( new DeferredPromise());
30
+ this.profileStorageProfile = this.userDataProfileService.currentProfile;
31
+ this.profileStorageDisposables = this._register(( new DisposableStore()));
32
+ this.workspaceStorageDisposables = this._register(( new DisposableStore()));
33
+ this.registerListeners();
34
+ }
35
+ registerListeners() {
36
+ this._register(this.userDataProfileService.onDidChangeCurrentProfile(e => e.join(this.switchToProfile(e.profile))));
37
+ }
38
+ async doInitialize() {
39
+ await Promises.settled([
40
+ this.createApplicationStorage(),
41
+ this.createProfileStorage(this.profileStorageProfile),
42
+ this.createWorkspaceStorage()
43
+ ]);
44
+ }
45
+ async createApplicationStorage() {
46
+ const applicationStorageIndexedDB = await IndexedDBStorageDatabase.createApplicationStorage(this.logService);
47
+ this.applicationStorageDatabase = this._register(applicationStorageIndexedDB);
48
+ this.applicationStorage = this._register(( new Storage(this.applicationStorageDatabase)));
49
+ this._register(this.applicationStorage.onDidChangeStorage(e => this.emitDidChangeValue(-1 , e)));
50
+ await this.applicationStorage.init();
51
+ this.updateIsNew(this.applicationStorage);
52
+ this.applicationStoragePromise.complete({ indexedDb: applicationStorageIndexedDB, storage: this.applicationStorage });
53
+ }
54
+ async createProfileStorage(profile) {
55
+ this.profileStorageDisposables.clear();
56
+ this.profileStorageProfile = profile;
57
+ if (isProfileUsingDefaultStorage(this.profileStorageProfile)) {
58
+ const { indexedDb: applicationStorageIndexedDB, storage: applicationStorage } = await this.applicationStoragePromise.p;
59
+ this.profileStorageDatabase = applicationStorageIndexedDB;
60
+ this.profileStorage = applicationStorage;
61
+ this.profileStorageDisposables.add(this.profileStorage.onDidChangeStorage(e => this.emitDidChangeValue(0 , e)));
62
+ }
63
+ else {
64
+ const profileStorageIndexedDB = await IndexedDBStorageDatabase.createProfileStorage(this.profileStorageProfile, this.logService);
65
+ this.profileStorageDatabase = this.profileStorageDisposables.add(profileStorageIndexedDB);
66
+ this.profileStorage = this.profileStorageDisposables.add(( new Storage(this.profileStorageDatabase)));
67
+ this.profileStorageDisposables.add(this.profileStorage.onDidChangeStorage(e => this.emitDidChangeValue(0 , e)));
68
+ await this.profileStorage.init();
69
+ this.updateIsNew(this.profileStorage);
70
+ }
71
+ }
72
+ async createWorkspaceStorage() {
73
+ this.workspaceStorageDisposables.clear();
74
+ const workspaceStorageIndexedDB = await IndexedDBStorageDatabase.createWorkspaceStorage(this.workspace.id, this.logService);
75
+ this.workspaceStorageDatabase = this.workspaceStorageDisposables.add(workspaceStorageIndexedDB);
76
+ this.workspaceStorage = this.workspaceStorageDisposables.add(( new Storage(this.workspaceStorageDatabase)));
77
+ this.workspaceStorageDisposables.add(this.workspaceStorage.onDidChangeStorage(e => this.emitDidChangeValue(1 , e)));
78
+ await this.workspaceStorage.init();
79
+ this.updateIsNew(this.workspaceStorage);
80
+ }
81
+ updateIsNew(storage) {
82
+ const firstOpen = storage.getBoolean(IS_NEW_KEY);
83
+ if (firstOpen === undefined) {
84
+ storage.set(IS_NEW_KEY, true);
85
+ }
86
+ else if (firstOpen) {
87
+ storage.set(IS_NEW_KEY, false);
88
+ }
89
+ }
90
+ getStorage(scope) {
91
+ switch (scope) {
92
+ case -1 :
93
+ return this.applicationStorage;
94
+ case 0 :
95
+ return this.profileStorage;
96
+ default:
97
+ return this.workspaceStorage;
98
+ }
99
+ }
100
+ getLogDetails(scope) {
101
+ switch (scope) {
102
+ case -1 :
103
+ return this.applicationStorageDatabase?.name;
104
+ case 0 :
105
+ return this.profileStorageDatabase?.name;
106
+ default:
107
+ return this.workspaceStorageDatabase?.name;
108
+ }
109
+ }
110
+ async switchToProfile(toProfile) {
111
+ if (!this.canSwitchProfile(this.profileStorageProfile, toProfile)) {
112
+ return;
113
+ }
114
+ const oldProfileStorage = assertIsDefined(this.profileStorage);
115
+ const oldItems = oldProfileStorage.items;
116
+ if (oldProfileStorage !== this.applicationStorage) {
117
+ await oldProfileStorage.close();
118
+ }
119
+ await this.createProfileStorage(toProfile);
120
+ this.switchData(oldItems, assertIsDefined(this.profileStorage), 0 );
121
+ }
122
+ async switchToWorkspace(toWorkspace, preserveData) {
123
+ const oldWorkspaceStorage = assertIsDefined(this.workspaceStorage);
124
+ const oldItems = preserveData ? oldWorkspaceStorage.items : ( new Map());
125
+ await oldWorkspaceStorage.close();
126
+ this.workspace = toWorkspace;
127
+ await this.createWorkspaceStorage();
128
+ this.switchData(oldItems, assertIsDefined(this.workspaceStorage), 1 );
129
+ }
130
+ shouldFlushWhenIdle() {
131
+ return getActiveWindow().document.hasFocus() && !this.hasPendingUpdate;
132
+ }
133
+ close() {
134
+ if (isSafari) {
135
+ this.applicationStorage?.close();
136
+ this.profileStorageDatabase?.close();
137
+ this.workspaceStorageDatabase?.close();
138
+ }
139
+ this.dispose();
140
+ }
141
+ async clear() {
142
+ for (const scope of [-1 , 0 , 1 ]) {
143
+ for (const target of [0 , 1 ]) {
144
+ for (const key of ( this.keys(scope, target))) {
145
+ this.remove(key, scope);
146
+ }
147
+ }
148
+ await this.getStorage(scope)?.whenFlushed();
149
+ }
150
+ await Promises.settled([
151
+ this.applicationStorageDatabase?.clear() ?? Promise.resolve(),
152
+ this.profileStorageDatabase?.clear() ?? Promise.resolve(),
153
+ this.workspaceStorageDatabase?.clear() ?? Promise.resolve()
154
+ ]);
155
+ }
156
+ hasScope(scope) {
157
+ if (isUserDataProfile(scope)) {
158
+ return this.profileStorageProfile.id === scope.id;
159
+ }
160
+ return this.workspace.id === scope.id;
161
+ }
162
+ };
163
+ BrowserStorageService = BrowserStorageService_1 = ( __decorate([
164
+ ( __param(2, ILogService))
165
+ ], BrowserStorageService));
166
+ class InMemoryIndexedDBStorageDatabase extends InMemoryStorageDatabase {
167
+ constructor() {
168
+ super(...arguments);
169
+ this.hasPendingUpdate = false;
170
+ this.name = 'in-memory-indexedb-storage';
171
+ }
172
+ async clear() {
173
+ (await this.getItems()).clear();
174
+ }
175
+ dispose() {
176
+ }
177
+ }
178
+ class IndexedDBStorageDatabase extends Disposable {
179
+ static async createApplicationStorage(logService) {
180
+ return IndexedDBStorageDatabase.create({ id: 'global', broadcastChanges: true }, logService);
181
+ }
182
+ static async createProfileStorage(profile, logService) {
183
+ return IndexedDBStorageDatabase.create({ id: `global-${profile.id}`, broadcastChanges: true }, logService);
184
+ }
185
+ static async createWorkspaceStorage(workspaceId, logService) {
186
+ return IndexedDBStorageDatabase.create({ id: workspaceId }, logService);
187
+ }
188
+ static async create(options, logService) {
189
+ try {
190
+ const database = ( new IndexedDBStorageDatabase(options, logService));
191
+ await database.whenConnected;
192
+ return database;
193
+ }
194
+ catch (error) {
195
+ logService.error(`[IndexedDB Storage ${options.id}] create(): ${toErrorMessage(error, true)}`);
196
+ return ( new InMemoryIndexedDBStorageDatabase());
197
+ }
198
+ }
199
+ static { this.STORAGE_DATABASE_PREFIX = 'vscode-web-state-db-'; }
200
+ static { this.STORAGE_OBJECT_STORE = 'ItemTable'; }
201
+ get hasPendingUpdate() { return !!this.pendingUpdate; }
202
+ constructor(options, logService) {
203
+ super();
204
+ this.logService = logService;
205
+ this._onDidChangeItemsExternal = this._register(( new Emitter()));
206
+ this.onDidChangeItemsExternal = this._onDidChangeItemsExternal.event;
207
+ this.pendingUpdate = undefined;
208
+ this.name = `${IndexedDBStorageDatabase.STORAGE_DATABASE_PREFIX}${options.id}`;
209
+ this.broadcastChannel = options.broadcastChanges ? this._register(( new BroadcastDataChannel(this.name))) : undefined;
210
+ this.whenConnected = this.connect();
211
+ this.registerListeners();
212
+ }
213
+ registerListeners() {
214
+ if (this.broadcastChannel) {
215
+ this._register(this.broadcastChannel.onDidReceiveData(data => {
216
+ if (isStorageItemsChangeEvent(data)) {
217
+ this._onDidChangeItemsExternal.fire(data);
218
+ }
219
+ }));
220
+ }
221
+ }
222
+ async connect() {
223
+ try {
224
+ return await IndexedDB.create(this.name, undefined, [IndexedDBStorageDatabase.STORAGE_OBJECT_STORE]);
225
+ }
226
+ catch (error) {
227
+ this.logService.error(`[IndexedDB Storage ${this.name}] connect() error: ${toErrorMessage(error)}`);
228
+ throw error;
229
+ }
230
+ }
231
+ async getItems() {
232
+ const db = await this.whenConnected;
233
+ function isValid(value) {
234
+ return typeof value === 'string';
235
+ }
236
+ return db.getKeyValues(IndexedDBStorageDatabase.STORAGE_OBJECT_STORE, isValid);
237
+ }
238
+ async updateItems(request) {
239
+ let didUpdate = false;
240
+ this.pendingUpdate = this.doUpdateItems(request);
241
+ try {
242
+ didUpdate = await this.pendingUpdate;
243
+ }
244
+ finally {
245
+ this.pendingUpdate = undefined;
246
+ }
247
+ if (this.broadcastChannel && didUpdate) {
248
+ const event = {
249
+ changed: request.insert,
250
+ deleted: request.delete
251
+ };
252
+ this.broadcastChannel.postData(event);
253
+ }
254
+ }
255
+ async doUpdateItems(request) {
256
+ const toInsert = request.insert;
257
+ const toDelete = request.delete;
258
+ if ((!toInsert && !toDelete) || (toInsert?.size === 0 && toDelete?.size === 0)) {
259
+ return false;
260
+ }
261
+ const db = await this.whenConnected;
262
+ await db.runInTransaction(IndexedDBStorageDatabase.STORAGE_OBJECT_STORE, 'readwrite', objectStore => {
263
+ const requests = [];
264
+ if (toInsert) {
265
+ for (const [key, value] of toInsert) {
266
+ requests.push(objectStore.put(value, key));
267
+ }
268
+ }
269
+ if (toDelete) {
270
+ for (const key of toDelete) {
271
+ requests.push(objectStore.delete(key));
272
+ }
273
+ }
274
+ return requests;
275
+ });
276
+ return true;
277
+ }
278
+ async optimize() {
279
+ }
280
+ async close() {
281
+ const db = await this.whenConnected;
282
+ await this.pendingUpdate;
283
+ return db.close();
284
+ }
285
+ async clear() {
286
+ const db = await this.whenConnected;
287
+ await db.runInTransaction(IndexedDBStorageDatabase.STORAGE_OBJECT_STORE, 'readwrite', objectStore => objectStore.clear());
288
+ }
289
+ }
290
+ export { BrowserStorageService, IndexedDBStorageDatabase };
@@ -1,5 +1,5 @@
1
1
  import { localizeWithPath, localize2WithPath } from '../../../../nls.js';
2
- import '../../../../platform/actions/common/actions.js';
2
+ import { MenuId } from '../../../../platform/actions/common/actions.js';
3
3
  import { RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
4
4
  import { URI } from '../../../../base/common/uri.js';
5
5
  import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
@@ -16,11 +16,16 @@ function toUserDataProfileUri(path, productService) {
16
16
  );
17
17
  }
18
18
  const defaultUserDataProfileIcon = registerIcon('defaultProfile-icon', Codicon.settings, ( localizeWithPath(_moduleId, 0, 'Icon for Default Profile.')));
19
+ const ProfilesMenu = ( (new MenuId('Profiles')));
20
+ const MANAGE_PROFILES_ACTION_ID = 'workbench.profiles.actions.manage';
19
21
  const PROFILES_TITLE = ( localize2WithPath(_moduleId, 1, 'Profiles'));
20
22
  const PROFILES_CATEGORY = { ...PROFILES_TITLE };
21
23
  const PROFILE_EXTENSION = 'code-profile';
22
24
  const PROFILE_FILTER = [{ name: ( localizeWithPath(_moduleId, 2, "Profile")), extensions: [PROFILE_EXTENSION] }];
25
+ const PROFILES_ENABLEMENT_CONTEXT = ( (new RawContextKey('profiles.enabled', true)));
23
26
  const CURRENT_PROFILE_CONTEXT = ( (new RawContextKey('currentProfile', '')));
27
+ const IS_CURRENT_PROFILE_TRANSIENT_CONTEXT = ( (new RawContextKey('isCurrentProfileTransient', false)));
28
+ const HAS_PROFILES_CONTEXT = ( (new RawContextKey('hasProfiles', false)));
24
29
  const IS_PROFILE_EXPORT_IN_PROGRESS_CONTEXT = ( (new RawContextKey('isProfileExportInProgress', false)));
25
30
  const IS_PROFILE_IMPORT_IN_PROGRESS_CONTEXT = ( (new RawContextKey('isProfileImportInProgress', false)));
26
- export { CURRENT_PROFILE_CONTEXT, IS_PROFILE_EXPORT_IN_PROGRESS_CONTEXT, IS_PROFILE_IMPORT_IN_PROGRESS_CONTEXT, PROFILES_CATEGORY, PROFILES_TITLE, PROFILE_EXTENSION, PROFILE_FILTER, PROFILE_URL_AUTHORITY, defaultUserDataProfileIcon, toUserDataProfileUri };
31
+ export { CURRENT_PROFILE_CONTEXT, HAS_PROFILES_CONTEXT, IS_CURRENT_PROFILE_TRANSIENT_CONTEXT, IS_PROFILE_EXPORT_IN_PROGRESS_CONTEXT, IS_PROFILE_IMPORT_IN_PROGRESS_CONTEXT, MANAGE_PROFILES_ACTION_ID, PROFILES_CATEGORY, PROFILES_ENABLEMENT_CONTEXT, PROFILES_TITLE, PROFILE_EXTENSION, PROFILE_FILTER, PROFILE_URL_AUTHORITY, ProfilesMenu, defaultUserDataProfileIcon, toUserDataProfileUri };