Skip to content

Commit c852787

Browse files
committed
feat: support custom workspaceSuffixName
1 parent f571511 commit c852787

8 files changed

Lines changed: 41 additions & 18 deletions

File tree

packages/core-browser/src/react-providers/config-provider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ export interface AppConfig {
177177
* vscode-oniguruma-wasm 资源地址
178178
*/
179179
onigWasmPath?: string;
180+
/**
181+
* 工作区文件后缀,默认后缀为 `sumi-workspace`
182+
*/
183+
workspaceSuffixName?: string;
180184
}
181185

182186
export const ConfigContext = React.createContext<AppConfig>({

packages/extension-storage/src/browser/storage-path.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import crypto from 'crypto';
22
import { Injectable, Autowired } from '@opensumi/di';
33
import { isWindows, URI, Deferred, StoragePaths } from '@opensumi/ide-core-common';
44
import { IExtensionStoragePathServer } from '../common';
5-
import { KAITIAN_MULTI_WORKSPACE_EXT, WORKSPACE_USER_STORAGE_FOLDER_NAME, UNTITLED_WORKSPACE } from '@opensumi/ide-workspace';
5+
import { DEFAULT_WORKSPACE_SUFFIX_NAME, WORKSPACE_USER_STORAGE_FOLDER_NAME, UNTITLED_WORKSPACE } from '@opensumi/ide-workspace';
66
import { IFileServiceClient, FileStat } from '@opensumi/ide-file-service';
77
import { ILoggerManagerClient } from '@opensumi/ide-logs';
88
import { Path } from '@opensumi/ide-core-common/lib/path';
9+
import { AppConfig } from '@opensumi/ide-core-browser';
910

1011
@Injectable()
1112
export class ExtensionStoragePathServer implements IExtensionStoragePathServer {
@@ -26,12 +27,19 @@ export class ExtensionStoragePathServer implements IExtensionStoragePathServer {
2627
@Autowired(ILoggerManagerClient)
2728
private readonly loggerManager: ILoggerManagerClient;
2829

30+
@Autowired(AppConfig)
31+
private readonly appConfig: AppConfig;
32+
2933
constructor() {
3034
this.deferredWorkspaceStoragePath = new Deferred();
3135
this.deferredStoragePath = new Deferred();
3236
this.storagePathInitialized = false;
3337
}
3438

39+
get workspaceSuffixName() {
40+
return this.appConfig.workspaceSuffixName || DEFAULT_WORKSPACE_SUFFIX_NAME;
41+
}
42+
3543
async provideHostLogPath(): Promise<URI> {
3644
const parentLogsDir = await this.getLogsDirPath();
3745
if (!parentLogsDir) {
@@ -109,7 +117,7 @@ export class ExtensionStoragePathServer implements IExtensionStoragePathServer {
109117
async buildWorkspaceId(workspace: FileStat, roots: FileStat[], extensionStorageDirName: string): Promise<string> {
110118
const homeDir = await this.getUserHomeDir();
111119
const getTemporaryWorkspaceFileUri = (home: URI): URI => {
112-
return home.resolve(extensionStorageDirName || WORKSPACE_USER_STORAGE_FOLDER_NAME).resolve(`${UNTITLED_WORKSPACE}.${KAITIAN_MULTI_WORKSPACE_EXT}`).withScheme('file');
120+
return home.resolve(extensionStorageDirName || WORKSPACE_USER_STORAGE_FOLDER_NAME).resolve(`${UNTITLED_WORKSPACE}.${this.workspaceSuffixName}`).withScheme('file');
113121
};
114122
const untitledWorkspace = getTemporaryWorkspaceFileUri(new URI(homeDir));
115123

@@ -123,7 +131,7 @@ export class ExtensionStoragePathServer implements IExtensionStoragePathServer {
123131
const uri = new URI(workspace.uri);
124132
let displayName = uri.displayName;
125133

126-
if ((!workspace || !workspace.isDirectory) && (displayName.endsWith(`.${KAITIAN_MULTI_WORKSPACE_EXT}`))) {
134+
if ((!workspace || !workspace.isDirectory) && (displayName.endsWith(`.${this.workspaceSuffixName}`))) {
127135
displayName = displayName.slice(0, displayName.lastIndexOf('.'));
128136
}
129137

packages/file-tree-next/__tests__/browser/file-tree.service.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FileTreeService } from '../../src/browser/file-tree.service';
33
import { createBrowserInjector } from '../../../../tools/dev-tool/src/injector-helper';
44
import { IContextKeyService, CorePreferences, Disposable, URI, EDITOR_COMMANDS, FILE_COMMANDS, ILoggerManagerClient, IApplicationService, isWindows, OS, isLinux } from '@opensumi/ide-core-browser';
55
import { MockContextKeyService } from '@opensumi/ide-core-browser/__mocks__/context-key';
6-
import { IWorkspaceService, KAITIAN_MULTI_WORKSPACE_EXT } from '@opensumi/ide-workspace';
6+
import { IWorkspaceService, DEFAULT_WORKSPACE_SUFFIX_NAME } from '@opensumi/ide-workspace';
77
import { MockWorkspaceService } from '@opensumi/ide-workspace/lib/common/mocks';
88
import { IFileServiceClient, FileChangeType } from '@opensumi/ide-file-service';
99
import { FileTreeContribution } from '../../src/browser/file-tree-contribution';
@@ -374,7 +374,7 @@ describe('FileTree Service should be work alone on multiple workspace mode', ()
374374
await workspaceService.setWorkspace({
375375
isDirectory: false,
376376
lastModification: 0,
377-
uri: URI.file('folder1').resolve(`test.${KAITIAN_MULTI_WORKSPACE_EXT}`).toString(),
377+
uri: URI.file('folder1').resolve(`test.${DEFAULT_WORKSPACE_SUFFIX_NAME}`).toString(),
378378
});
379379
await workspaceService.spliceRoots(0, undefined, undefined, URI.file('folder1'), URI.file('folder2'));
380380
const path = await fileTreeService.getFileTreeNodePathByUri(URI.file('folder1').resolve('test'));

packages/file-tree-next/src/browser/file-tree-contribution.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { IApplicationService, URI, ClientAppContribution, localize, CommandContribution, KeybindingContribution, TabBarToolbarContribution, FILE_COMMANDS, CommandRegistry, CommandService, SEARCH_COMMANDS, IElectronNativeDialogService, ToolbarRegistry, KeybindingRegistry, IWindowService, IClipboardService, PreferenceService, formatLocalize, OS, isElectronRenderer, WORKSPACE_COMMANDS } from '@opensumi/ide-core-browser';
1+
import { IApplicationService, URI, ClientAppContribution, localize, CommandContribution, KeybindingContribution, TabBarToolbarContribution, FILE_COMMANDS, CommandRegistry, CommandService, SEARCH_COMMANDS, IElectronNativeDialogService, ToolbarRegistry, KeybindingRegistry, IWindowService, IClipboardService, PreferenceService, formatLocalize, OS, isElectronRenderer, WORKSPACE_COMMANDS, AppConfig } from '@opensumi/ide-core-browser';
22
import { Domain } from '@opensumi/ide-core-common/lib/di-helper';
33
import { Autowired, INJECTOR_TOKEN, Injector } from '@opensumi/di';
44
import { FileTreeService } from './file-tree.service';
55
import { IMainLayoutService, IViewsRegistry, MainLayoutContribution } from '@opensumi/ide-main-layout';
66
import { ExplorerContainerId } from '@opensumi/ide-explorer/lib/browser/explorer-contribution';
7-
import { KAITIAN_MULTI_WORKSPACE_EXT, IWorkspaceService, UNTITLED_WORKSPACE } from '@opensumi/ide-workspace';
7+
import { DEFAULT_WORKSPACE_SUFFIX_NAME, IWorkspaceService, UNTITLED_WORKSPACE } from '@opensumi/ide-workspace';
88
import { FileTree } from './file-tree';
99
import { SymlinkDecorationsProvider } from './symlink-file-decoration';
1010
import { IDecorationsService } from '@opensumi/ide-decoration';
@@ -63,8 +63,15 @@ export class FileTreeContribution implements MenuContribution, CommandContributi
6363
@Autowired(IApplicationService)
6464
private readonly appService: IApplicationService;
6565

66+
@Autowired(AppConfig)
67+
private readonly appConfig: AppConfig;
68+
6669
private isRendered = false;
6770

71+
get workspaceSuffixName() {
72+
return this.appConfig.workspaceSuffixName || DEFAULT_WORKSPACE_SUFFIX_NAME;
73+
}
74+
6875
initialize() {
6976
// 等待排除配置初始化结束后再初始化文件树
7077
this.workspaceService.initFileServiceExclude().then(() => {
@@ -122,7 +129,7 @@ export class FileTreeContribution implements MenuContribution, CommandContributi
122129
const uri = new URI(workspace.uri);
123130
resourceTitle = uri.displayName;
124131
if (!workspace.isDirectory &&
125-
(resourceTitle.endsWith(`.${KAITIAN_MULTI_WORKSPACE_EXT}`))) {
132+
(resourceTitle.endsWith(`.${this.workspaceSuffixName}`))) {
126133
resourceTitle = resourceTitle.slice(0, resourceTitle.lastIndexOf('.'));
127134
if (resourceTitle === UNTITLED_WORKSPACE) {
128135
return localize('file.workspace.defaultTip');
@@ -639,7 +646,7 @@ export class FileTreeContribution implements MenuContribution, CommandContributi
639646
],
640647
filters: [{
641648
name: localize('workspace.openWorkspaceTitle'),
642-
extensions: [KAITIAN_MULTI_WORKSPACE_EXT],
649+
extensions: [this.workspaceSuffixName],
643650
}],
644651
}).then((paths) => {
645652
if (paths && paths.length > 0) {

packages/preferences/__tests__/common/workspace-defination.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { URI, FileStat } from '@opensumi/ide-core-browser';
2-
import { KAITIAN_MULTI_WORKSPACE_EXT, WorkspaceData } from '@opensumi/ide-workspace';
2+
import { DEFAULT_WORKSPACE_SUFFIX_NAME, WorkspaceData } from '@opensumi/ide-workspace';
33

44
describe('WorkspaceData methods', () => {
55

@@ -39,7 +39,7 @@ describe('WorkspaceData methods', () => {
3939

4040
it('transformToRelative method should be work', () => {
4141
const workspaceFile = {
42-
uri: URI.file('home').resolve(`workspace.${KAITIAN_MULTI_WORKSPACE_EXT}`).toString(),
42+
uri: URI.file('home').resolve(`workspace.${DEFAULT_WORKSPACE_SUFFIX_NAME}`).toString(),
4343
isDirectory: false,
4444
lastModification: new Date().getTime(),
4545
};
@@ -58,7 +58,7 @@ describe('WorkspaceData methods', () => {
5858

5959
it('transformToAbsolute method should be work', () => {
6060
const workspaceFile = {
61-
uri: URI.file('home').resolve(`workspace.${KAITIAN_MULTI_WORKSPACE_EXT}`).toString(),
61+
uri: URI.file('home').resolve(`workspace.${DEFAULT_WORKSPACE_SUFFIX_NAME}`).toString(),
6262
isDirectory: false,
6363
lastModification: new Date().getTime(),
6464
};

packages/workspace/src/browser/workspace-contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
URI,
1414
} from '@opensumi/ide-core-browser';
1515

16-
import { IWorkspaceService, KAITIAN_MULTI_WORKSPACE_EXT } from '../common';
16+
import { IWorkspaceService, DEFAULT_WORKSPACE_SUFFIX_NAME } from '../common';
1717
import { workspacePreferenceSchema } from './workspace-preferences';
1818
import { WorkspaceService } from './workspace-service';
1919
import { IWindowDialogService } from '@opensumi/ide-overlay';
@@ -74,7 +74,7 @@ export class WorkspaceContribution implements ClientAppContribution, PreferenceC
7474
const folder = await this.windowDialogService.showSaveDialog({
7575
saveLabel: localize('workspace.saveWorkspaceAsFile'),
7676
showNameInput: true,
77-
defaultFileName: `workspace.${KAITIAN_MULTI_WORKSPACE_EXT}`,
77+
defaultFileName: `workspace.${DEFAULT_WORKSPACE_SUFFIX_NAME}`,
7878
});
7979
if (folder) {
8080
await this.workspaceService.save(folder);

packages/workspace/src/browser/workspace-service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import { Injectable, Autowired } from '@opensumi/di';
33
import {
4-
KAITIAN_MULTI_WORKSPACE_EXT,
4+
DEFAULT_WORKSPACE_SUFFIX_NAME,
55
IWorkspaceService,
66
WorkspaceData,
77
WorkspaceInput,
@@ -68,6 +68,10 @@ export class WorkspaceService implements IWorkspaceService {
6868
@Autowired(IClientApp)
6969
private readonly clientApp: IClientApp;
7070

71+
get workspaceSuffixName() {
72+
return this.appConfig.workspaceSuffixName || DEFAULT_WORKSPACE_SUFFIX_NAME;
73+
}
74+
7175
protected applicationName: string;
7276

7377
private _whenReady: Deferred<void> = new Deferred();
@@ -113,7 +117,7 @@ export class WorkspaceService implements IWorkspaceService {
113117
}
114118

115119
protected getTemporaryWorkspaceFileUri(home: URI): URI {
116-
return home.resolve(this.appConfig.storageDirName || WORKSPACE_USER_STORAGE_FOLDER_NAME).resolve(`${UNTITLED_WORKSPACE}.${KAITIAN_MULTI_WORKSPACE_EXT}`).withScheme('file');
120+
return home.resolve(this.appConfig.storageDirName || WORKSPACE_USER_STORAGE_FOLDER_NAME).resolve(`${UNTITLED_WORKSPACE}.${this.workspaceSuffixName}`).withScheme('file');
117121
}
118122

119123
protected listenPreference() {
@@ -339,7 +343,7 @@ export class WorkspaceService implements IWorkspaceService {
339343
const uri = new URI(this._workspace.uri);
340344
const displayName = uri.displayName;
341345
if (!this._workspace.isDirectory &&
342-
(displayName.endsWith(`.${KAITIAN_MULTI_WORKSPACE_EXT}`))) {
346+
(displayName.endsWith(`.${this.workspaceSuffixName}`))) {
343347
title = formatLocalize('file.workspace.defaultWorkspaceTip', displayName.slice(0, displayName.lastIndexOf('.')));
344348
} else {
345349
title = displayName;

packages/workspace/src/common/workspace-defination.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { FileStat } from '@opensumi/ide-file-service';
33
import Ajv from 'ajv';
44
import { StorageService } from '@opensumi/ide-core-browser/lib/services';
55

6-
export const KAITIAN_MULTI_WORKSPACE_EXT = 'sumi-workspace';
6+
export const DEFAULT_WORKSPACE_SUFFIX_NAME = 'sumi-workspace';
77
export const WORKSPACE_USER_STORAGE_FOLDER_NAME = '.sumi';
88
export const WORKSPACE_RECENT_DATA_FILE = 'recentdata.json';
99
export const UNTITLED_WORKSPACE = 'Untitled';

0 commit comments

Comments
 (0)