Skip to content

Commit df4c40b

Browse files
author
Loïc Mangeonjean
committed
feat: allow to override startupKind on lifecycle service
1 parent 2faf6c8 commit df4c40b

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/service-override/lifecycle.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,48 @@
11
import { type IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
22
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
3+
import { ILogService } from 'vs/platform/log/common/log.service'
4+
import { IStorageService } from 'vs/platform/storage/common/storage.service'
35
import { BrowserLifecycleService } from 'vs/workbench/services/lifecycle/browser/lifecycleService'
6+
import { StartupKind } from 'vs/workbench/services/lifecycle/common/lifecycle'
47
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle.service'
58
import { TimerService } from 'vs/workbench/services/timer/browser/timerService'
69
import { ITimerService } from 'vs/workbench/services/timer/browser/timerService.service'
710

8-
export default function getServiceOverride(): IEditorOverrideServices {
11+
interface StartupKindResolver {
12+
(resolveDefault: () => StartupKind | undefined): StartupKind | undefined
13+
}
14+
export interface LifecycleServiceParams {
15+
/**
16+
* Allows to force the startup kind
17+
*/
18+
resolveStartupKind?: StartupKindResolver
19+
}
20+
21+
const DEFAULT_RESOLVE_STARTUP_KIND: StartupKindResolver = (resolveDefault) => resolveDefault()
22+
23+
class BrowserLifecycleServiceOverride extends BrowserLifecycleService {
24+
constructor(
25+
private params: LifecycleServiceParams,
26+
@ILogService logService: ILogService,
27+
@IStorageService storageService: IStorageService
28+
) {
29+
super(logService, storageService)
30+
}
31+
32+
protected override doResolveStartupKind(): StartupKind | undefined {
33+
return (this.params.resolveStartupKind ?? DEFAULT_RESOLVE_STARTUP_KIND)(() =>
34+
super.doResolveStartupKind()
35+
)
36+
}
37+
}
38+
39+
export default function getServiceOverride(
40+
options: LifecycleServiceParams = {}
41+
): IEditorOverrideServices {
942
return {
10-
[ILifecycleService.toString()]: new SyncDescriptor(BrowserLifecycleService),
43+
[ILifecycleService.toString()]: new SyncDescriptor(BrowserLifecycleServiceOverride, [options]),
1144
[ITimerService.toString()]: new SyncDescriptor(TimerService)
1245
}
1346
}
47+
48+
export { StartupKind }

0 commit comments

Comments
 (0)