@opensumi/ide-workspace 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/browser/index.js.map +1 -1
- package/lib/browser/workspace-contextkey.js.map +1 -1
- package/lib/browser/workspace-contribution.js.map +1 -1
- package/lib/browser/workspace-preferences.d.ts +1 -1
- package/lib/browser/workspace-preferences.d.ts.map +1 -1
- package/lib/browser/workspace-service.d.ts +4 -1
- package/lib/browser/workspace-service.d.ts.map +1 -1
- package/lib/browser/workspace-service.js +18 -7
- package/lib/browser/workspace-service.js.map +1 -1
- package/lib/browser/workspace-storage-service.js.map +1 -1
- package/lib/browser/workspace-variable-contribution.js.map +1 -1
- package/lib/common/mocks/workspace-service.d.ts +4 -1
- package/lib/common/mocks/workspace-service.d.ts.map +1 -1
- package/lib/common/mocks/workspace-service.js.map +1 -1
- package/lib/common/workspace.interface.d.ts +5 -2
- package/lib/common/workspace.interface.d.ts.map +1 -1
- package/lib/common/workspace.interface.js.map +1 -1
- package/package.json +10 -9
- package/src/browser/index.ts +31 -0
- package/src/browser/workspace-contextkey.ts +18 -0
- package/src/browser/workspace-contribution.ts +103 -0
- package/src/browser/workspace-data.ts +144 -0
- package/src/browser/workspace-preferences.ts +45 -0
- package/src/browser/workspace-service.ts +809 -0
- package/src/browser/workspace-storage-service.ts +64 -0
- package/src/browser/workspace-variable-contribution.ts +133 -0
- package/src/common/constants.ts +4 -0
- package/src/common/index.ts +2 -0
- package/src/common/mocks/index.ts +1 -0
- package/src/common/mocks/workspace-service.ts +132 -0
- package/src/common/workspace.interface.ts +75 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { URI, Schemes } from '@opensumi/ide-core-common';
|
|
2
|
+
import { FileStat } from '@opensumi/ide-file-service';
|
|
3
|
+
|
|
4
|
+
export interface WorkspaceData {
|
|
5
|
+
folders: Array<{ path: string; name?: string }>;
|
|
6
|
+
settings?: { [id: string]: any };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const workspaceSchema = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
folders: {
|
|
13
|
+
description: 'Root folders in the workspace',
|
|
14
|
+
type: 'array',
|
|
15
|
+
items: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
path: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
required: ['path'],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
settings: {
|
|
26
|
+
description: 'Workspace preferences',
|
|
27
|
+
type: 'object',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ['folders'],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export namespace WorkspaceData {
|
|
34
|
+
let validateSchema;
|
|
35
|
+
|
|
36
|
+
export function is(data: any): data is WorkspaceData {
|
|
37
|
+
if (!validateSchema) {
|
|
38
|
+
// 避免一开始就加载 ajv,初始化和 compile 都会花费大量的时间进行编译
|
|
39
|
+
const Ajv = require('ajv');
|
|
40
|
+
validateSchema = new Ajv().compile(workspaceSchema);
|
|
41
|
+
}
|
|
42
|
+
return !!validateSchema(data);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function buildWorkspaceData(
|
|
46
|
+
folders: string[] | FileStat[],
|
|
47
|
+
settings: { [id: string]: any } | undefined,
|
|
48
|
+
): WorkspaceData {
|
|
49
|
+
let roots: string[] = [];
|
|
50
|
+
if (folders.length > 0) {
|
|
51
|
+
if (typeof folders[0] !== 'string') {
|
|
52
|
+
roots = (folders as FileStat[]).map((folder) => folder.uri);
|
|
53
|
+
} else {
|
|
54
|
+
roots = folders as string[];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const data: WorkspaceData = {
|
|
58
|
+
folders: roots.map((folder) => ({ path: folder })),
|
|
59
|
+
};
|
|
60
|
+
if (settings) {
|
|
61
|
+
data.settings = settings;
|
|
62
|
+
}
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 存储时需要将 {workspace}.sumi-workspace 内容存储为相对路径存储
|
|
68
|
+
* 1. 如果可用相对路径表示,则存储为:
|
|
69
|
+
* {
|
|
70
|
+
* "folders": [
|
|
71
|
+
* {
|
|
72
|
+
* "path": "folder1"
|
|
73
|
+
* },
|
|
74
|
+
* {
|
|
75
|
+
* "path": "folder2"
|
|
76
|
+
* }
|
|
77
|
+
* ],
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* 2. 如果不可用相对路径表示,则存储绝对路径:
|
|
81
|
+
* {
|
|
82
|
+
* "folders": [
|
|
83
|
+
* {
|
|
84
|
+
* "path": "file://abc/folder1"
|
|
85
|
+
* },
|
|
86
|
+
* {
|
|
87
|
+
* "path": "file://cdf/folder2"
|
|
88
|
+
* }
|
|
89
|
+
* ],
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* @export
|
|
93
|
+
* @param {WorkspaceData} data
|
|
94
|
+
* @param {FileStat} [workspaceFile]
|
|
95
|
+
* @returns {WorkspaceData}
|
|
96
|
+
*/
|
|
97
|
+
export function transformToRelative(data: WorkspaceData, workspaceFile?: FileStat): WorkspaceData {
|
|
98
|
+
const folderUris: string[] = [];
|
|
99
|
+
const workspaceFileUri = new URI(workspaceFile ? workspaceFile.uri : '').withScheme(Schemes.file);
|
|
100
|
+
for (const { path } of data.folders) {
|
|
101
|
+
const folderUri = new URI(path).withScheme(Schemes.file);
|
|
102
|
+
if (workspaceFileUri.parent.isEqualOrParent(folderUri)) {
|
|
103
|
+
if (workspaceFileUri.parent.isEqual(folderUri)) {
|
|
104
|
+
folderUris.push('.');
|
|
105
|
+
} else {
|
|
106
|
+
const rel = workspaceFileUri.parent.relative(folderUri);
|
|
107
|
+
folderUris.push(rel!.toString() || '.');
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
folderUris.push(folderUri.toString());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return buildWorkspaceData(folderUris, data.settings);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 将 {workspace}.sumi-workspace 中存储的相对路径转换为绝对路径
|
|
118
|
+
*
|
|
119
|
+
* @export
|
|
120
|
+
* @param {WorkspaceData} data
|
|
121
|
+
* @param {FileStat} [workspaceFile]
|
|
122
|
+
* @returns {WorkspaceData}
|
|
123
|
+
*/
|
|
124
|
+
export function transformToAbsolute(data: WorkspaceData, workspaceFile?: FileStat): WorkspaceData {
|
|
125
|
+
if (workspaceFile) {
|
|
126
|
+
const folders: string[] = [];
|
|
127
|
+
for (const folder of data.folders) {
|
|
128
|
+
const path = folder.path;
|
|
129
|
+
// 判断是否为绝对路径
|
|
130
|
+
if (/^.+:\//.test(path)) {
|
|
131
|
+
folders.push(path);
|
|
132
|
+
} else {
|
|
133
|
+
if (path === '.') {
|
|
134
|
+
folders.push(new URI(workspaceFile.uri).parent.toString());
|
|
135
|
+
} else {
|
|
136
|
+
folders.push(new URI(workspaceFile.uri).parent.resolve(path).toString());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return Object.assign(data, buildWorkspaceData(folders, data.settings));
|
|
141
|
+
}
|
|
142
|
+
return data;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Injector } from '@opensumi/di';
|
|
2
|
+
import {
|
|
3
|
+
createPreferenceProxy,
|
|
4
|
+
PreferenceProxy,
|
|
5
|
+
PreferenceService,
|
|
6
|
+
PreferenceSchema,
|
|
7
|
+
} from '@opensumi/ide-core-browser';
|
|
8
|
+
|
|
9
|
+
export const workspacePreferenceSchema: PreferenceSchema = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
'workspace.preserveWindow': {
|
|
13
|
+
description: 'Enable opening workspaces in current window',
|
|
14
|
+
type: 'boolean',
|
|
15
|
+
default: false,
|
|
16
|
+
},
|
|
17
|
+
'workspace.supportMultiRootWorkspace': {
|
|
18
|
+
description: 'Enable the multi-root workspace support to test this feature internally',
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
default: false,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export interface WorkspaceConfiguration {
|
|
26
|
+
'workspace.preserveWindow': boolean;
|
|
27
|
+
'workspace.supportMultiRootWorkspace': boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const WorkspacePreferences = Symbol('WorkspacePreferences');
|
|
31
|
+
export type WorkspacePreferences = PreferenceProxy<WorkspaceConfiguration>;
|
|
32
|
+
|
|
33
|
+
export function createWorkspacePreferencesProvider(inject: Injector) {
|
|
34
|
+
return {
|
|
35
|
+
token: WorkspacePreferences,
|
|
36
|
+
useFactory: () => {
|
|
37
|
+
const preferences = inject.get(PreferenceService);
|
|
38
|
+
return createPreferenceProxy(preferences, workspacePreferenceSchema);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function injectWorkspacePreferences(inject: Injector) {
|
|
44
|
+
inject.addProviders(createWorkspacePreferencesProvider(inject));
|
|
45
|
+
}
|