Skip to content

Commit

Permalink
feat: add onUserConfigurationChange
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Feb 23, 2023
1 parent f93174b commit 42c4a20
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/service-override/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,31 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { setProperty } from 'vs/base/common/jsonEdit'
import { createTextBuffer, TextModel } from 'vs/editor/common/model/textModel'
import { URI } from 'vs/base/common/uri'
import type * as vscode from 'vscode'
import getWorkspaceContextServiceOverride from './workspaceContext'
import getFileServiceOverride from './files'
import { onServicesInitialized } from './tools'
import { IModelService } from '../services'

async function updateUserConfiguration (configurationJson: string): Promise<void> {
const userDataProfilesService: IUserDataProfilesService = StandaloneServices.get(IUserDataProfilesService)
const userDataProfilesService = StandaloneServices.get(IUserDataProfilesService)
await StandaloneServices.get(IFileService).writeFile(userDataProfilesService.defaultProfile.settingsResource, VSBuffer.fromString(configurationJson))
}

async function getUserConfiguration (): Promise<string> {
const userDataProfilesService: IUserDataProfilesService = StandaloneServices.get(IUserDataProfilesService)
const userDataProfilesService = StandaloneServices.get(IUserDataProfilesService)
return (await StandaloneServices.get(IFileService).readFile(userDataProfilesService.defaultProfile.settingsResource)).value.toString()
}

function onUserConfigurationChange (callback: () => void): vscode.Disposable {
const userDataProfilesService = StandaloneServices.get(IUserDataProfilesService)
return StandaloneServices.get(IFileService).onDidFilesChange(e => {
if (e.affects(userDataProfilesService.defaultProfile.settingsResource)) {
callback()
}
})
}

const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)

function updateJsonValue (jsonValue: string, jsonPath: string[], value: unknown, configFileUrl: URI) {
Expand Down Expand Up @@ -107,6 +117,7 @@ export default function getServiceOverride (): IEditorOverrideServices {
export {
updateUserConfiguration,
getUserConfiguration,
onUserConfigurationChange,
configurationRegistry,
ConfigurationScope,
IThemeScopedColorCustomizations,
Expand Down

0 comments on commit 42c4a20

Please sign in to comment.