@@ -8,9 +8,8 @@ import { VSBuffer } from 'vs/base/common/buffer';
8
8
import { JSONPath , parse , ParseError } from 'vs/base/common/json' ;
9
9
import { setProperty } from 'vs/base/common/jsonEdit' ;
10
10
import { Edit , FormattingOptions } from 'vs/base/common/jsonFormatter' ;
11
- import { URI } from 'vs/base/common/uri' ;
12
11
import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
13
- import { FileOperationError , FileOperationResult , IFileService } from 'vs/platform/files/common/files' ;
12
+ import { FileOperationError , FileOperationResult , IFileService , IWriteFileOptions } from 'vs/platform/files/common/files' ;
14
13
import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
15
14
import { ILogService } from 'vs/platform/log/common/log' ;
16
15
@@ -31,6 +30,7 @@ export interface IUserConfigurationFileService {
31
30
readonly _serviceBrand : undefined ;
32
31
33
32
updateSettings ( value : IJSONValue , formattingOptions : FormattingOptions ) : Promise < void > ;
33
+ write ( value : VSBuffer , options ?: IWriteFileOptions ) : Promise < void > ;
34
34
}
35
35
36
36
export class UserConfigurationFileService implements IUserConfigurationFileService {
@@ -48,12 +48,12 @@ export class UserConfigurationFileService implements IUserConfigurationFileServi
48
48
}
49
49
50
50
async updateSettings ( value : IJSONValue , formattingOptions : FormattingOptions ) : Promise < void > {
51
- return this . queue . queue ( ( ) => this . doWrite ( this . environmentService . settingsResource , value , formattingOptions ) ) ; // queue up writes to prevent race conditions
51
+ return this . queue . queue ( ( ) => this . doWrite ( value , formattingOptions ) ) ; // queue up writes to prevent race conditions
52
52
}
53
53
54
- private async doWrite ( resource : URI , jsonValue : IJSONValue , formattingOptions : FormattingOptions ) : Promise < void > {
55
- this . logService . trace ( `${ UserConfigurationFileServiceId } #write` , resource . toString ( ) , jsonValue ) ;
56
- const { value, mtime, etag } = await this . fileService . readFile ( resource , { atomic : true } ) ;
54
+ private async doWrite ( jsonValue : IJSONValue , formattingOptions : FormattingOptions ) : Promise < void > {
55
+ this . logService . trace ( `${ UserConfigurationFileServiceId } #write` , this . environmentService . settingsResource . toString ( ) , jsonValue ) ;
56
+ const { value, mtime, etag } = await this . fileService . readFile ( this . environmentService . settingsResource , { atomic : true } ) ;
57
57
let content = value . toString ( ) ;
58
58
59
59
const parseErrors : ParseError [ ] = [ ] ;
@@ -66,7 +66,7 @@ export class UserConfigurationFileService implements IUserConfigurationFileServi
66
66
if ( edit ) {
67
67
content = content . substring ( 0 , edit . offset ) + edit . content + content . substring ( edit . offset + edit . length ) ;
68
68
try {
69
- await this . fileService . writeFile ( resource , VSBuffer . fromString ( content ) , { etag, mtime } ) ;
69
+ await this . write ( VSBuffer . fromString ( content ) , { etag, mtime } ) ;
70
70
} catch ( error ) {
71
71
if ( ( < FileOperationError > error ) . fileOperationResult === FileOperationResult . FILE_MODIFIED_SINCE ) {
72
72
throw new Error ( UserConfigurationErrorCode . ERROR_FILE_MODIFIED_SINCE ) ;
@@ -75,6 +75,10 @@ export class UserConfigurationFileService implements IUserConfigurationFileServi
75
75
}
76
76
}
77
77
78
+ async write ( content : VSBuffer , options ?: IWriteFileOptions ) : Promise < void > {
79
+ await this . fileService . writeFile ( this . environmentService . settingsResource , content , options ) ;
80
+ }
81
+
78
82
private getEdits ( { value, path } : IJSONValue , modelContent : string , formattingOptions : FormattingOptions ) : Edit [ ] {
79
83
if ( path . length ) {
80
84
return setProperty ( modelContent , path , value , formattingOptions ) ;
0 commit comments