-
Notifications
You must be signed in to change notification settings - Fork 33
/
theme.ts
47 lines (42 loc) · 1.89 KB
/
theme.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { WorkbenchThemeService } from 'vs/workbench/services/themes/browser/workbenchThemeService'
import { IThemeExtensionPoint } from 'vs/workbench/services/themes/common/workbenchThemeService'
import { IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
import { IThemeService } from 'vs/platform/theme/common/themeService.service'
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
import type { StandaloneThemeService } from 'vs/editor/standalone/browser/standaloneThemeService'
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration'
import { IDisposable } from 'vs/base/common/lifecycle'
import getFileServiceOverride from './files'
import 'vs/workbench/contrib/themes/browser/themes.contribution'
class StandaloneWorkbenchThemeService
extends WorkbenchThemeService
implements Pick<StandaloneThemeService, 'setTheme' | 'registerEditorContainer'>
{
registerEditorContainer(): IDisposable {
// do nothing, it's called by `StandaloneEditor` but we don't care about it
return {
dispose() {}
}
}
// Let's implement setTheme as it's used by `monaco.editor.setTheme`
setTheme(themeName: string): void {
void this.getColorThemes().then((themes) => {
// Run in a timeout so the service is already initialized
setTimeout(() => {
void this.setColorTheme(
themes.find((theme) => theme.settingsId === themeName) ?? themeName,
ConfigurationTarget.MEMORY
)
})
})
}
}
type PartialIThemeExtensionPoint = Partial<IThemeExtensionPoint> &
Pick<IThemeExtensionPoint, 'id' | 'path'>
export default function getServiceOverride(): IEditorOverrideServices {
return {
...getFileServiceOverride(),
[IThemeService.toString()]: new SyncDescriptor(StandaloneWorkbenchThemeService, [], false)
}
}
export { PartialIThemeExtensionPoint as IThemeExtensionPoint }