@opensumi/ide-core-common 2.21.13 → 2.22.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/lib/command.d.ts +15 -5
- package/lib/command.d.ts.map +1 -1
- package/lib/command.js +11 -1
- package/lib/command.js.map +1 -1
- package/lib/const/application.d.ts +6 -1
- package/lib/const/application.d.ts.map +1 -1
- package/lib/const/application.js +8 -3
- package/lib/const/application.js.map +1 -1
- package/lib/declare.d.ts +2 -2
- package/lib/declare.d.ts.map +1 -1
- package/lib/editor.d.ts +4 -0
- package/lib/editor.d.ts.map +1 -1
- package/lib/electron.d.ts +1 -1
- package/lib/electron.d.ts.map +1 -1
- package/lib/event-bus/event-bus-types.d.ts +1 -1
- package/lib/event-bus/event-bus-types.d.ts.map +1 -1
- package/lib/event-bus/event-bus.js.map +1 -1
- package/lib/event-bus/event-decorator.js.map +1 -1
- package/lib/extension.schema.d.ts +1 -1
- package/lib/extension.schema.d.ts.map +1 -1
- package/lib/hash-calculate/WASMInterface.d.ts +2 -2
- package/lib/hash-calculate/WASMInterface.d.ts.map +1 -1
- package/lib/hash-calculate/hash-calculate.js.map +1 -1
- package/lib/hash-calculate/util.d.ts +2 -2
- package/lib/hash-calculate/util.d.ts.map +1 -1
- package/lib/json-schema.d.ts +9 -0
- package/lib/json-schema.d.ts.map +1 -1
- package/lib/keyboard/keymap.d.ts +1 -1
- package/lib/keyboard/keymap.d.ts.map +1 -1
- package/lib/localize.d.ts +1 -1
- package/lib/localize.d.ts.map +1 -1
- package/lib/log.d.ts +2 -2
- package/lib/log.d.ts.map +1 -1
- package/lib/mime.d.ts +6 -6
- package/lib/module.js.map +1 -1
- package/lib/preferences/preference-schema.d.ts +13 -3
- package/lib/preferences/preference-schema.d.ts.map +1 -1
- package/lib/preferences/preference-schema.js +11 -1
- package/lib/preferences/preference-schema.js.map +1 -1
- package/lib/preferences/preference-scope.d.ts +8 -1
- package/lib/preferences/preference-scope.d.ts.map +1 -1
- package/lib/preferences/preference-scope.js +11 -2
- package/lib/preferences/preference-scope.js.map +1 -1
- package/lib/problem-matcher.d.ts +1 -1
- package/lib/problem-matcher.d.ts.map +1 -1
- package/lib/problem-matcher.js.map +1 -1
- package/lib/problem-pattern.d.ts +4 -2
- package/lib/problem-pattern.d.ts.map +1 -1
- package/lib/problem-pattern.js +24 -1
- package/lib/problem-pattern.js.map +1 -1
- package/lib/reference.d.ts +2 -1
- package/lib/reference.d.ts.map +1 -1
- package/lib/reference.js +11 -6
- package/lib/reference.js.map +1 -1
- package/lib/reporter.js.map +1 -1
- package/lib/storage.d.ts +1 -1
- package/lib/storage.d.ts.map +1 -1
- package/lib/storage.js.map +1 -1
- package/lib/task-definition.js.map +1 -1
- package/lib/types/common.d.ts +1 -1
- package/lib/types/common.d.ts.map +1 -1
- package/lib/types/editor.d.ts +2 -2
- package/lib/types/editor.d.ts.map +1 -1
- package/lib/types/file-watch.d.ts +1 -1
- package/lib/types/file-watch.d.ts.map +1 -1
- package/lib/types/markers/markers-manager.d.ts.map +1 -1
- package/lib/types/markers/markers-manager.js +4 -10
- package/lib/types/markers/markers-manager.js.map +1 -1
- package/lib/types/markers/markers.d.ts +2 -0
- package/lib/types/markers/markers.d.ts.map +1 -1
- package/lib/types/markers/markers.js.map +1 -1
- package/package.json +7 -6
- package/src/LifeCyclePhase.ts +6 -0
- package/src/application-error.ts +77 -0
- package/src/application-props.ts +28 -0
- package/src/application.lifecycle.ts +15 -0
- package/src/browser-fs/ensure-dir.ts +46 -0
- package/src/browser-fs/util.ts +52 -0
- package/src/clipboard.ts +31 -0
- package/src/command.ts +726 -0
- package/src/commands/terminal.ts +0 -0
- package/src/comparers.ts +152 -0
- package/src/connection.ts +7 -0
- package/src/const/application.ts +11 -0
- package/src/const/index.ts +1 -0
- package/src/contribution-provider.ts +47 -0
- package/src/credential.ts +21 -0
- package/src/crypto.ts +8 -0
- package/src/declare.ts +3 -0
- package/src/di-helper/domain-helper.ts +48 -0
- package/src/di-helper/index.ts +1 -0
- package/src/editor.ts +6 -0
- package/src/electron.ts +168 -0
- package/src/env.ts +1 -0
- package/src/event-bus/basic-event.ts +3 -0
- package/src/event-bus/event-bus-types.ts +68 -0
- package/src/event-bus/event-bus.ts +57 -0
- package/src/event-bus/event-decorator.ts +32 -0
- package/src/event-bus/index.ts +4 -0
- package/src/extension.schema.ts +16 -0
- package/src/hash-calculate/WASMInterface.ts +266 -0
- package/src/hash-calculate/hash-calculate.ts +53 -0
- package/src/hash-calculate/lockedCreate.ts +17 -0
- package/src/hash-calculate/md5.wasm.json +1 -0
- package/src/hash-calculate/mutex.ts +30 -0
- package/src/hash-calculate/util.ts +190 -0
- package/src/id-generator.ts +15 -0
- package/src/index.ts +39 -0
- package/src/json-schema.ts +80 -0
- package/src/keyboard/index.ts +2 -0
- package/src/keyboard/keyboard-layout-provider.ts +46 -0
- package/src/keyboard/keymap.ts +224 -0
- package/src/line-text.ts +93 -0
- package/src/localize.ts +203 -0
- package/src/log.ts +338 -0
- package/src/markdown.ts +8 -0
- package/src/menu.ts +31 -0
- package/src/mime.ts +8 -0
- package/src/mocks/electron/browserMock.ts +10 -0
- package/src/mocks/electron/ipcRenderer.ts +30 -0
- package/src/module.ts +31 -0
- package/src/network.ts +47 -0
- package/src/node/cli.ts +5 -0
- package/src/node/port.ts +134 -0
- package/src/preferences/index.ts +2 -0
- package/src/preferences/preference-schema.ts +122 -0
- package/src/preferences/preference-scope.ts +65 -0
- package/src/problem-matcher.ts +389 -0
- package/src/problem-pattern.ts +574 -0
- package/src/range.ts +24 -0
- package/src/reference.ts +141 -0
- package/src/reporter.ts +64 -0
- package/src/settings/general.ts +5 -0
- package/src/settings/index.ts +3 -0
- package/src/settings/search.ts +7 -0
- package/src/settings/terminal.ts +9 -0
- package/src/storage.ts +99 -0
- package/src/task-definition.ts +172 -0
- package/src/theme.ts +7 -0
- package/src/types/accessibility.ts +4 -0
- package/src/types/application.ts +14 -0
- package/src/types/authentication.ts +120 -0
- package/src/types/common.ts +14 -0
- package/src/types/dnd.ts +8 -0
- package/src/types/editor.ts +246 -0
- package/src/types/extension.ts +96 -0
- package/src/types/file-watch.ts +100 -0
- package/src/types/file.ts +262 -0
- package/src/types/index.ts +15 -0
- package/src/types/markdown.ts +10 -0
- package/src/types/markers/index.ts +2 -0
- package/src/types/markers/markers-manager.ts +392 -0
- package/src/types/markers/markers.ts +125 -0
- package/src/types/message.ts +6 -0
- package/src/types/reporter.ts +96 -0
- package/src/types/statusbar.ts +6 -0
- package/src/types/string.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/ipc.ts +28 -0
package/src/reference.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Emitter, Event, Disposable, MaybePromise } from '@opensumi/ide-utils';
|
|
2
|
+
|
|
3
|
+
export interface IRef<T> {
|
|
4
|
+
instance: T;
|
|
5
|
+
reason?: string;
|
|
6
|
+
dispose(): void;
|
|
7
|
+
hold(reason?: string): IRef<T>;
|
|
8
|
+
disposed: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ReferenceManager<T> {
|
|
12
|
+
protected instances: Map<string, T> = new Map();
|
|
13
|
+
|
|
14
|
+
protected refs: Map<string, Array<IRef<T>>> = new Map();
|
|
15
|
+
|
|
16
|
+
protected _onReferenceAllDisposed = new Emitter<string>();
|
|
17
|
+
|
|
18
|
+
protected _onInstanceCreated = new Emitter<T>();
|
|
19
|
+
|
|
20
|
+
public onReferenceAllDisposed: Event<string> = this._onReferenceAllDisposed.event;
|
|
21
|
+
|
|
22
|
+
public onInstanceCreated: Event<T> = this._onInstanceCreated.event;
|
|
23
|
+
|
|
24
|
+
protected _creating: Map<string, Promise<void>> = new Map();
|
|
25
|
+
|
|
26
|
+
constructor(private factory: (key: string) => MaybePromise<T>) {}
|
|
27
|
+
|
|
28
|
+
private getReferenceKey(uri: string) {
|
|
29
|
+
// 部分情况下可能出现类似 `file:///a//b.js` 的路径,此时需要替换路径中的 `//` 为 `/`
|
|
30
|
+
return uri.replace(/\w+\/\/\w+/gi, (match) => match.replace('//', '/'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getReference(uri: string, reason?: string): Promise<IRef<T>> {
|
|
34
|
+
const key = this.getReferenceKey(uri);
|
|
35
|
+
if (!this.instances.has(key)) {
|
|
36
|
+
// 由于创建过程可能为异步,此处标注为 creating, 防止重复创建。
|
|
37
|
+
if (!this._creating.has(key)) {
|
|
38
|
+
const promise = (async () => {
|
|
39
|
+
const instance = await this.factory(key);
|
|
40
|
+
this.instances.set(key, instance);
|
|
41
|
+
this._onInstanceCreated.fire(instance);
|
|
42
|
+
})();
|
|
43
|
+
this._creating.set(key, promise);
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await this._creating.get(key);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
// 出错时需要清除创建中状态
|
|
49
|
+
this._creating.delete(key);
|
|
50
|
+
throw e;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const ref = this.createRef(key, reason);
|
|
54
|
+
// 需要在 ref 被创建后再结束 creating 状态,否则如果在 onInstanceCreated 事件中触发了 removeRef 至 0,
|
|
55
|
+
// 可能导致 instance 意外被删除。
|
|
56
|
+
if (this._creating.get(key)) {
|
|
57
|
+
const creatingPromise = this._creating.get(key);
|
|
58
|
+
this._creating.delete(key);
|
|
59
|
+
creatingPromise?.then(() => {
|
|
60
|
+
// 再触发一次空remove,防止被保护的instance意外残留
|
|
61
|
+
this.removeRef(key, undefined);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return ref;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getReferenceIfHasInstance(key: string, reason?: string): IRef<T> | null {
|
|
68
|
+
if (this.instances.has(key)) {
|
|
69
|
+
return this.createRef(key, reason);
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private createRef(key: string, reason?: string) {
|
|
75
|
+
const instance: T = this.instances.get(key)!;
|
|
76
|
+
const ref = new Ref<T>(instance, reason, (reason?: string) => this.createRef(key, reason));
|
|
77
|
+
ref.addDispose({
|
|
78
|
+
dispose: () => {
|
|
79
|
+
this.removeRef(key, ref);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
this.addRef(key, ref);
|
|
83
|
+
return ref;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private addRef(key: string, ref: Ref<T>) {
|
|
87
|
+
if (!this.refs.get(key)) {
|
|
88
|
+
this.refs.set(key, []);
|
|
89
|
+
}
|
|
90
|
+
this.refs.get(key)!.push(ref);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private removeRef(key: string, ref: Ref<T> | undefined) {
|
|
94
|
+
if (this.refs.get(key)) {
|
|
95
|
+
if (ref) {
|
|
96
|
+
const index = this.refs.get(key)!.indexOf(ref);
|
|
97
|
+
if (index !== -1) {
|
|
98
|
+
this.refs.get(key)!.splice(index, 1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (this.refs.get(key)!.length === 0) {
|
|
102
|
+
if (this._creating.has(key)) {
|
|
103
|
+
return; // 正在被创建, 进行保护
|
|
104
|
+
}
|
|
105
|
+
this.refs.delete(key);
|
|
106
|
+
this.instances.delete(key);
|
|
107
|
+
this._onReferenceAllDisposed.fire(key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export class Ref<T> extends Disposable implements IRef<T> {
|
|
114
|
+
constructor(
|
|
115
|
+
private _instance: T | null,
|
|
116
|
+
public readonly reason: string | undefined,
|
|
117
|
+
private _clone: null | ((reason?: string) => Ref<T>),
|
|
118
|
+
) {
|
|
119
|
+
super();
|
|
120
|
+
this.addDispose({
|
|
121
|
+
dispose: () => {
|
|
122
|
+
this._instance = null;
|
|
123
|
+
this._clone = null;
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
get instance() {
|
|
129
|
+
if (this.disposed) {
|
|
130
|
+
throw new Error('Ref has been disposed!');
|
|
131
|
+
}
|
|
132
|
+
return this._instance!;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
hold(reason?: string): Ref<T> {
|
|
136
|
+
if (this.disposed) {
|
|
137
|
+
throw new Error('Ref has been disposed!');
|
|
138
|
+
}
|
|
139
|
+
return this._clone!(reason);
|
|
140
|
+
}
|
|
141
|
+
}
|
package/src/reporter.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Injectable, Inject } from '@opensumi/di';
|
|
2
|
+
import { IDisposable } from '@opensumi/ide-utils';
|
|
3
|
+
|
|
4
|
+
import { getDebugLogger } from './log';
|
|
5
|
+
import {
|
|
6
|
+
IReporterService,
|
|
7
|
+
ReporterMetadata,
|
|
8
|
+
IReporter,
|
|
9
|
+
PerformanceData,
|
|
10
|
+
PointData,
|
|
11
|
+
IReporterTimer,
|
|
12
|
+
REPORT_NAME,
|
|
13
|
+
} from './types/reporter';
|
|
14
|
+
|
|
15
|
+
class ReporterTimer implements IReporterTimer {
|
|
16
|
+
private now: number;
|
|
17
|
+
constructor(private name: string, private reporter: IReporter, private metadata?: ReporterMetadata) {
|
|
18
|
+
this.now = Date.now();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
timeEnd(msg?: string, extra?: any) {
|
|
22
|
+
const duration = Date.now() - this.now;
|
|
23
|
+
this.reporter.performance(this.name, {
|
|
24
|
+
duration,
|
|
25
|
+
metadata: this.metadata,
|
|
26
|
+
msg,
|
|
27
|
+
extra,
|
|
28
|
+
});
|
|
29
|
+
return duration;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Injectable()
|
|
34
|
+
export class DefaultReporter implements IReporter {
|
|
35
|
+
private logger = getDebugLogger();
|
|
36
|
+
performance(name: string, data: PerformanceData): void {
|
|
37
|
+
this.logger.log(name, data);
|
|
38
|
+
}
|
|
39
|
+
point(name: string, data: PointData): void {
|
|
40
|
+
this.logger.log(name, data);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Injectable()
|
|
45
|
+
export class ReporterService implements IReporterService, IDisposable {
|
|
46
|
+
constructor(
|
|
47
|
+
@Inject(IReporter) private reporter: IReporter,
|
|
48
|
+
@Inject(ReporterMetadata) private metadata?: ReporterMetadata,
|
|
49
|
+
) {}
|
|
50
|
+
|
|
51
|
+
time(name: REPORT_NAME | string): IReporterTimer {
|
|
52
|
+
return new ReporterTimer(name, this.reporter, this.metadata);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
point(name: REPORT_NAME | string, msg?: string, extra?: any): void {
|
|
56
|
+
this.reporter.point(name, {
|
|
57
|
+
metadata: this.metadata,
|
|
58
|
+
msg,
|
|
59
|
+
extra,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
dispose() {}
|
|
64
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const enum TerminalSettingsId {
|
|
2
|
+
Type = 'terminal.type',
|
|
3
|
+
FontFamily = 'terminal.fontFamily',
|
|
4
|
+
FontSize = 'terminal.fontSize',
|
|
5
|
+
FontWeight = 'terminal.fontWeight',
|
|
6
|
+
LineHeight = 'terminal.lineHeight',
|
|
7
|
+
CursorBlink = 'terminal.cursorBlink',
|
|
8
|
+
Scrollback = 'terminal.scrollback',
|
|
9
|
+
}
|
package/src/storage.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Injectable, Autowired } from '@opensumi/di';
|
|
2
|
+
import { IDisposable, MaybePromise, Event, URI } from '@opensumi/ide-utils';
|
|
3
|
+
|
|
4
|
+
import { ContributionProvider } from './contribution-provider';
|
|
5
|
+
|
|
6
|
+
export const StorageProvider = Symbol('StorageProvider');
|
|
7
|
+
export type StorageProvider = (storageId: URI) => Promise<IStorage>;
|
|
8
|
+
|
|
9
|
+
export const StorageResolverContribution = Symbol('StorageResolverContribution');
|
|
10
|
+
|
|
11
|
+
export interface StorageResolverContribution {
|
|
12
|
+
resolve(storageId: URI): MaybePromise<void | IStorage>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IStorage extends IDisposable {
|
|
16
|
+
readonly items: Map<string, string>;
|
|
17
|
+
readonly size: number;
|
|
18
|
+
readonly onDidChangeStorage: Event<string>;
|
|
19
|
+
readonly whenReady: Promise<any>;
|
|
20
|
+
|
|
21
|
+
init(storageId: string): Promise<IStorage | void>;
|
|
22
|
+
|
|
23
|
+
get(key: string, fallbackValue: string): string;
|
|
24
|
+
get(key: string, fallbackValue?: string): string | undefined;
|
|
25
|
+
get<T>(key: string, fallbackValue?: T): T;
|
|
26
|
+
|
|
27
|
+
getBoolean(key: string, fallbackValue: boolean): boolean;
|
|
28
|
+
getBoolean(key: string, fallbackValue?: boolean): boolean | undefined;
|
|
29
|
+
|
|
30
|
+
getNumber(key: string, fallbackValue: number): number;
|
|
31
|
+
getNumber(key: string, fallbackValue?: number): number | undefined;
|
|
32
|
+
|
|
33
|
+
set(key: string, value: object | string | boolean | number | undefined | null): Promise<void>;
|
|
34
|
+
delete(key: string): Promise<void>;
|
|
35
|
+
|
|
36
|
+
close(): Promise<void>;
|
|
37
|
+
reConnectInit(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const STORAGE_SCHEMA = {
|
|
41
|
+
SCOPE: 'wsdb',
|
|
42
|
+
GLOBAL: 'gldb',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 在该对象定义的存储对象在初始化阶段时将默认通过 LocalStorage 缓存
|
|
46
|
+
// ref: https://github.com/opensumi/core/blob/f512897d691f1aa0d89ff6469ff2251ab2124f71/packages/storage/src/browser/storage.contribution.ts#L49
|
|
47
|
+
export const STORAGE_NAMESPACE = {
|
|
48
|
+
// workspace database
|
|
49
|
+
WORKBENCH: new URI('workbench').withScheme(STORAGE_SCHEMA.SCOPE),
|
|
50
|
+
EXTENSIONS: new URI('extensions').withScheme(STORAGE_SCHEMA.SCOPE),
|
|
51
|
+
EXPLORER: new URI('explorer').withScheme(STORAGE_SCHEMA.SCOPE),
|
|
52
|
+
LAYOUT: new URI('layout').withScheme(STORAGE_SCHEMA.SCOPE),
|
|
53
|
+
RECENT_DATA: new URI('recent').withScheme(STORAGE_SCHEMA.SCOPE),
|
|
54
|
+
DEBUG: new URI('debug').withScheme(STORAGE_SCHEMA.SCOPE),
|
|
55
|
+
OUTLINE: new URI('outline').withScheme(STORAGE_SCHEMA.SCOPE),
|
|
56
|
+
// global database
|
|
57
|
+
GLOBAL_LAYOUT: new URI('layout-global').withScheme(STORAGE_SCHEMA.GLOBAL),
|
|
58
|
+
GLOBAL_EXTENSIONS: new URI('extensions').withScheme(STORAGE_SCHEMA.GLOBAL),
|
|
59
|
+
GLOBAL_RECENT_DATA: new URI('recent').withScheme(STORAGE_SCHEMA.GLOBAL),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
@Injectable()
|
|
63
|
+
export class DefaultStorageProvider {
|
|
64
|
+
@Autowired(StorageResolverContribution)
|
|
65
|
+
protected readonly resolversProvider: ContributionProvider<StorageResolverContribution>;
|
|
66
|
+
|
|
67
|
+
private storageCacheMap: Map<string, IStorage> = new Map();
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 返回对应storageId的Storage类
|
|
71
|
+
*/
|
|
72
|
+
async get(storageId: URI): Promise<IStorage | void> {
|
|
73
|
+
if (this.storageCacheMap.has(storageId.toString())) {
|
|
74
|
+
return this.storageCacheMap.get(storageId.toString());
|
|
75
|
+
}
|
|
76
|
+
const resolvers = this.resolversProvider.getContributions();
|
|
77
|
+
return Promise.race(
|
|
78
|
+
resolvers.map(async (resolver) => {
|
|
79
|
+
const storageResolver = await resolver.resolve(storageId);
|
|
80
|
+
if (storageResolver) {
|
|
81
|
+
this.storageCacheMap.set(storageId.toString(), storageResolver);
|
|
82
|
+
return storageResolver;
|
|
83
|
+
}
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export namespace StoragePaths {
|
|
90
|
+
export const WINDOWS_APP_DATA_DIR = 'AppData';
|
|
91
|
+
export const WINDOWS_ROAMING_DIR = 'Roaming';
|
|
92
|
+
// 可通过AppConfig配置替换,目前仅作为默认值使用
|
|
93
|
+
export const DEFAULT_STORAGE_DIR_NAME = '.sumi';
|
|
94
|
+
export const DEFAULT_DATA_DIR_NAME = 'datas';
|
|
95
|
+
export const MARKETPLACE_DIR = 'extensions';
|
|
96
|
+
export const EXTENSIONS_LOGS_DIR = 'extensions';
|
|
97
|
+
export const EXTENSIONS_GLOBAL_STORAGE_DIR = 'extension-storage';
|
|
98
|
+
export const EXTENSIONS_WORKSPACE_STORAGE_DIR = 'workspace-storage';
|
|
99
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Injectable } from '@opensumi/di';
|
|
2
|
+
import { objects, IDisposable, Disposable } from '@opensumi/ide-utils';
|
|
3
|
+
|
|
4
|
+
import { IJSONSchemaMap, IJSONSchema } from './json-schema';
|
|
5
|
+
import { formatLocalize } from './localize';
|
|
6
|
+
import { IStringDictionary } from './types/string';
|
|
7
|
+
|
|
8
|
+
const { deepClone } = objects;
|
|
9
|
+
|
|
10
|
+
interface TaskDefinition {
|
|
11
|
+
extensionId: string;
|
|
12
|
+
taskType: string;
|
|
13
|
+
required: string[];
|
|
14
|
+
properties: IJSONSchemaMap;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TaskIdentifier {
|
|
18
|
+
type: string;
|
|
19
|
+
[name: string]: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface KeyedTaskIdentifier extends TaskIdentifier {
|
|
23
|
+
_key: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export namespace KeyedTaskIdentifier {
|
|
27
|
+
function sortedStringify(literal: any): string {
|
|
28
|
+
const keys = Object.keys(literal).sort();
|
|
29
|
+
let result = '';
|
|
30
|
+
for (const key of keys) {
|
|
31
|
+
let stringified = literal[key];
|
|
32
|
+
if (stringified instanceof Object) {
|
|
33
|
+
stringified = sortedStringify(stringified);
|
|
34
|
+
} else if (typeof stringified === 'string') {
|
|
35
|
+
stringified = stringified.replace(/,/g, ',,');
|
|
36
|
+
}
|
|
37
|
+
result += key + ',' + stringified + ',';
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
export function create(value: TaskIdentifier): KeyedTaskIdentifier {
|
|
42
|
+
const resultKey = sortedStringify(value);
|
|
43
|
+
const result = { _key: resultKey, type: value.taskType };
|
|
44
|
+
Object.assign(result, value);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const ITaskDefinitionRegistry = Symbol('ITaskDefinitionRegistry');
|
|
50
|
+
|
|
51
|
+
export interface ITaskDefinitionRegistry {
|
|
52
|
+
onReady(): Promise<void>;
|
|
53
|
+
register(taskType: string, definition: TaskDefinition): IDisposable;
|
|
54
|
+
get(key: string): TaskDefinition;
|
|
55
|
+
all(): TaskDefinition[];
|
|
56
|
+
getJsonSchema(): IJSONSchema;
|
|
57
|
+
createTaskIdentifier(
|
|
58
|
+
external: TaskIdentifier,
|
|
59
|
+
reporter: { error(message: string): void },
|
|
60
|
+
): KeyedTaskIdentifier | undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Injectable()
|
|
64
|
+
export class TaskDefinitionRegistryImpl implements ITaskDefinitionRegistry {
|
|
65
|
+
private taskTypes: IStringDictionary<TaskDefinition>;
|
|
66
|
+
private readyPromise: Promise<void>;
|
|
67
|
+
private _schema: IJSONSchema;
|
|
68
|
+
|
|
69
|
+
constructor() {
|
|
70
|
+
this.taskTypes = Object.create(null);
|
|
71
|
+
this.readyPromise = new Promise<void>((res, rej) => res(undefined));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public onReady(): Promise<void> {
|
|
75
|
+
return this.readyPromise;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
register(taskType: string, definition: TaskDefinition) {
|
|
79
|
+
this.taskTypes[taskType] = definition;
|
|
80
|
+
return Disposable.create(() => delete this.taskTypes[taskType]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public get(key: string): TaskDefinition {
|
|
84
|
+
return this.taskTypes[key];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public all(): TaskDefinition[] {
|
|
88
|
+
return Object.keys(this.taskTypes).map((key) => this.taskTypes[key]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public createTaskIdentifier = (
|
|
92
|
+
external: TaskIdentifier,
|
|
93
|
+
reporter: { error(message: string): void },
|
|
94
|
+
): KeyedTaskIdentifier | undefined => {
|
|
95
|
+
const definition = this.get(external.type);
|
|
96
|
+
if (definition === undefined) {
|
|
97
|
+
// We have no task definition so we can't sanitize the literal. Take it as is
|
|
98
|
+
const copy = deepClone(external);
|
|
99
|
+
delete copy._key;
|
|
100
|
+
return KeyedTaskIdentifier.create(copy);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const literal: { type: string; [name: string]: any } = Object.create(null);
|
|
104
|
+
literal.type = definition.taskType;
|
|
105
|
+
const required: Set<string> = new Set();
|
|
106
|
+
definition.required.forEach((element) => required.add(element));
|
|
107
|
+
|
|
108
|
+
const properties = definition.properties;
|
|
109
|
+
for (const property of Object.keys(properties)) {
|
|
110
|
+
const value = external[property];
|
|
111
|
+
if (value !== undefined && value !== null) {
|
|
112
|
+
literal[property] = value;
|
|
113
|
+
} else if (required.has(property)) {
|
|
114
|
+
const schema = properties[property];
|
|
115
|
+
if (schema.default !== undefined) {
|
|
116
|
+
literal[property] = deepClone(schema.default);
|
|
117
|
+
} else {
|
|
118
|
+
switch (schema.type) {
|
|
119
|
+
case 'boolean':
|
|
120
|
+
literal[property] = false;
|
|
121
|
+
break;
|
|
122
|
+
case 'number':
|
|
123
|
+
case 'integer':
|
|
124
|
+
literal[property] = 0;
|
|
125
|
+
break;
|
|
126
|
+
case 'string':
|
|
127
|
+
literal[property] = '';
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
reporter.error(
|
|
131
|
+
formatLocalize(
|
|
132
|
+
'TaskDefinition.missingRequiredProperty',
|
|
133
|
+
"Error: the task identifier '{0}' is missing the required property '{1}'. The task identifier will be ignored.",
|
|
134
|
+
JSON.stringify(external, undefined, 0),
|
|
135
|
+
property,
|
|
136
|
+
),
|
|
137
|
+
);
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return KeyedTaskIdentifier.create(literal);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
public getJsonSchema(): IJSONSchema {
|
|
147
|
+
if (this._schema === undefined) {
|
|
148
|
+
const schemas: IJSONSchema[] = [];
|
|
149
|
+
for (const definition of this.all()) {
|
|
150
|
+
const schema: IJSONSchema = {
|
|
151
|
+
type: 'object',
|
|
152
|
+
additionalProperties: false,
|
|
153
|
+
};
|
|
154
|
+
if (definition.required.length > 0) {
|
|
155
|
+
schema.required = definition.required.slice(0);
|
|
156
|
+
}
|
|
157
|
+
if (definition.properties !== undefined) {
|
|
158
|
+
schema.properties = deepClone(definition.properties);
|
|
159
|
+
} else {
|
|
160
|
+
schema.properties = Object.create(null);
|
|
161
|
+
}
|
|
162
|
+
schema.properties!.type = {
|
|
163
|
+
type: 'string',
|
|
164
|
+
enum: [definition.taskType],
|
|
165
|
+
};
|
|
166
|
+
schemas.push(schema);
|
|
167
|
+
}
|
|
168
|
+
this._schema = { oneOf: schemas };
|
|
169
|
+
}
|
|
170
|
+
return this._schema;
|
|
171
|
+
}
|
|
172
|
+
}
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OperatingSystem } from '@opensumi/ide-utils';
|
|
2
|
+
|
|
3
|
+
export const IApplicationService = Symbol('IApplicationService');
|
|
4
|
+
|
|
5
|
+
export interface IApplicationService {
|
|
6
|
+
/** 前端 OS */
|
|
7
|
+
frontendOS: OperatingSystem;
|
|
8
|
+
/** 后端 OS */
|
|
9
|
+
backendOS: OperatingSystem;
|
|
10
|
+
/**
|
|
11
|
+
* 获取后端 OS
|
|
12
|
+
*/
|
|
13
|
+
getBackendOS(): Promise<OperatingSystem>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { IDisposable, Event } from '@opensumi/ide-utils';
|
|
2
|
+
|
|
3
|
+
export const noAccountsId = 'authentication.noAccounts';
|
|
4
|
+
|
|
5
|
+
export const ACCOUNTS_MENU = ['accounts_menu'];
|
|
6
|
+
export const ACCOUNTS_SUBMENU = [...ACCOUNTS_MENU, '1_accounts_submenu'];
|
|
7
|
+
|
|
8
|
+
export interface AllowedExtension {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface AuthenticationSessionsChangeEvent {
|
|
14
|
+
added: ReadonlyArray<AuthenticationSession>;
|
|
15
|
+
removed: ReadonlyArray<AuthenticationSession>;
|
|
16
|
+
changed: ReadonlyArray<AuthenticationSession>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface AuthenticationSession {
|
|
20
|
+
id: string;
|
|
21
|
+
accessToken: string;
|
|
22
|
+
account: {
|
|
23
|
+
label: string;
|
|
24
|
+
id: string;
|
|
25
|
+
};
|
|
26
|
+
scopes: ReadonlyArray<string>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AuthenticationProviderInformation {
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AllowedExtension {
|
|
35
|
+
id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
allowed?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface IAuthenticationProvider {
|
|
41
|
+
id: string;
|
|
42
|
+
label: string;
|
|
43
|
+
supportsMultipleAccounts: boolean;
|
|
44
|
+
manageTrustedExtensions(accountName: string): Promise<void>;
|
|
45
|
+
updateSessionItems(event: AuthenticationSessionsChangeEvent): Promise<void>;
|
|
46
|
+
getSessions(): Promise<ReadonlyArray<AuthenticationSession>>;
|
|
47
|
+
hasSessions(): boolean;
|
|
48
|
+
login(scopes: string[]): Promise<AuthenticationSession>;
|
|
49
|
+
logout(sessionId: string): Promise<void>;
|
|
50
|
+
signOut(accountName: string): Promise<void>;
|
|
51
|
+
dispose(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const IAuthenticationService = Symbol('IAuthenticationService');
|
|
55
|
+
export interface IAuthenticationService {
|
|
56
|
+
readonly onDidRegisterAuthenticationProvider: Event<AuthenticationProviderInformation>;
|
|
57
|
+
readonly onDidUnregisterAuthenticationProvider: Event<AuthenticationProviderInformation>;
|
|
58
|
+
readonly onDidChangeSessions: Event<{ providerId: string; label: string; event: AuthenticationSessionsChangeEvent }>;
|
|
59
|
+
initialize(): Promise<void>;
|
|
60
|
+
isAuthenticationProviderRegistered(id: string): boolean;
|
|
61
|
+
getProviderIds(): string[];
|
|
62
|
+
registerAuthenticationProvider(id: string, provider: IAuthenticationProvider): void;
|
|
63
|
+
unregisterAuthenticationProvider(id: string): void;
|
|
64
|
+
requestNewSession(providerId: string, scopes: string[], extensionId: string, extensionName: string): Promise<void>;
|
|
65
|
+
sessionsUpdate(providerId: string, event: AuthenticationSessionsChangeEvent): void;
|
|
66
|
+
|
|
67
|
+
getSessions(
|
|
68
|
+
id: string,
|
|
69
|
+
scopes?: string[],
|
|
70
|
+
activateImmediate?: boolean,
|
|
71
|
+
): Promise<ReadonlyArray<AuthenticationSession>>;
|
|
72
|
+
getLabel(providerId: string): string;
|
|
73
|
+
supportsMultipleAccounts(providerId: string): boolean;
|
|
74
|
+
login(providerId: string, scopes: string[]): Promise<AuthenticationSession>;
|
|
75
|
+
logout(providerId: string, sessionId: string): Promise<void>;
|
|
76
|
+
|
|
77
|
+
manageTrustedExtensionsForAccount(providerId: string, accountName: string): Promise<void>;
|
|
78
|
+
signOutOfAccount(providerId: string, accountName: string): Promise<void>;
|
|
79
|
+
|
|
80
|
+
getExtensionSessionId(extensionName: string, providerId: string): Promise<string | undefined>;
|
|
81
|
+
setExtensionSessionId(extensionName: string, providerId: string, sessionId: string): Promise<void>;
|
|
82
|
+
removeExtensionSessionId(extensionName: string, providerId: string): Promise<void>;
|
|
83
|
+
updatedAllowedExtension(
|
|
84
|
+
providerId: string,
|
|
85
|
+
accountName: string,
|
|
86
|
+
extensionId: string,
|
|
87
|
+
extensionName: string,
|
|
88
|
+
isAllowed: boolean,
|
|
89
|
+
): Promise<void>;
|
|
90
|
+
getAllowedExtensions(providerId: string, accountName: string): Promise<AllowedExtension[]>;
|
|
91
|
+
setAllowedExtensions(providerId: string, accountName: string, allowList: AllowedExtension[]): Promise<void>;
|
|
92
|
+
removeAllowedExtensions(providerId: any, accountName: string): Promise<void>;
|
|
93
|
+
isAccessAllowed(providerId: string, accountName: string, extensionId: string): Promise<boolean | undefined>;
|
|
94
|
+
|
|
95
|
+
getAccountUsages(providerId: string, accountName: string): Promise<IAccountUsage[]>;
|
|
96
|
+
addAccountUsage(providerId: string, accountName: string, extensionId: string, extensionName: string): Promise<void>;
|
|
97
|
+
removeAccountUsage(providerId: string, accountName: string): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface IAccountUsage {
|
|
101
|
+
extensionId: string;
|
|
102
|
+
extensionName: string;
|
|
103
|
+
lastUsed: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface SessionRequest {
|
|
107
|
+
disposables: IDisposable[];
|
|
108
|
+
requestingExtensionIds: string[];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface SessionRequestInfo {
|
|
112
|
+
[scopes: string]: SessionRequest;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface AuthenticationGetSessionOptions {
|
|
116
|
+
createIfNone: boolean;
|
|
117
|
+
clearSessionPreference: boolean;
|
|
118
|
+
forceNewSession?: boolean | { detail: string };
|
|
119
|
+
silent?: boolean;
|
|
120
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OperatingSystem } from '@opensumi/ide-utils';
|
|
2
|
+
|
|
3
|
+
export const CommonServerPath = 'CommonServerPath';
|
|
4
|
+
|
|
5
|
+
export const ICommonServer = Symbol('ICommonServer');
|
|
6
|
+
|
|
7
|
+
export interface ICommonServer {
|
|
8
|
+
/**
|
|
9
|
+
* 获取后端 OS
|
|
10
|
+
*/
|
|
11
|
+
getBackendOS(): Promise<OperatingSystem>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type UrlProvider = string | (() => string) | (() => Promise<string>);
|