Skip to content

Commit

Permalink
feat: allow to configure working copy storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Jul 29, 2024
1 parent b6af5e9 commit 801d7fa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo/src/setup.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export const constructOptions: IWorkbenchConstructionOptions = {
export const envOptions: EnvironmentOverride = {
// Otherwise, VSCode detect it as the first open workspace folder
// which make the search result extension fail as it's not able to know what was detected by VSCode
userHome: vscode.Uri.file('/')
// userHome: vscode.Uri.file('/')
}

export const commonServices: IEditorOverrideServices = {
Expand Down
35 changes: 32 additions & 3 deletions src/service-override/workingCopy.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import { IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
import { BrowserWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/browser/workingCopyBackupService'
import { IWorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackup.service'
import { WorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService'
import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/workingCopyService.service'
import { WorkingCopyEditorService } from 'vs/workbench/services/workingCopy/common/workingCopyEditorService'
import { IWorkingCopyEditorService } from 'vs/workbench/services/workingCopy/common/workingCopyEditorService.service'
import { IWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/common/workingCopyHistory.service'
import { BrowserWorkingCopyHistoryService } from 'vs/workbench/services/workingCopy/browser/workingCopyHistoryService'
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace.service'
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService.service'
import { IFileService } from 'vs/platform/files/common/files.service'
import { ILogService } from 'vs/platform/log/common/log.service'
import { joinPath } from 'vs/base/common/resources'
import { WorkingCopyBackupService } from 'vs/workbench/services/workingCopy/common/workingCopyBackupService'
import getFileServiceOverride from './files'

export default function getServiceOverride (): IEditorOverrideServices {
class BrowserWorkingCopyBackupService extends WorkingCopyBackupService {
constructor (
memory: boolean,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
@IFileService fileService: IFileService,
@ILogService logService: ILogService
) {
super(
memory ? undefined : joinPath(environmentService.userRoamingDataHome, 'Backups', contextService.getWorkspace().id),
fileService,
logService
)
}
}

interface WorkingCopyServiceOptions {
storage: 'memory' | 'userData' | null
}

export default function getServiceOverride ({ storage }: WorkingCopyServiceOptions): IEditorOverrideServices {
return {
...getFileServiceOverride(),
[IWorkingCopyBackupService.toString()]: new SyncDescriptor(BrowserWorkingCopyBackupService, [], false),
...(storage != null
? {
[IWorkingCopyBackupService.toString()]: new SyncDescriptor(BrowserWorkingCopyBackupService, [storage === 'memory'], false)
}
: {}),
[IWorkingCopyService.toString()]: new SyncDescriptor(WorkingCopyService, [], false),
[IWorkingCopyEditorService.toString()]: new SyncDescriptor(WorkingCopyEditorService, [], false),
[IWorkingCopyHistoryService.toString()]: new SyncDescriptor(BrowserWorkingCopyHistoryService, [], false)
Expand Down

0 comments on commit 801d7fa

Please sign in to comment.