@@ -140,6 +140,12 @@ export namespace CloseFileRequest {
140
140
'editor/closeFile' ) ;
141
141
}
142
142
143
+ export namespace SaveFileRequest {
144
+ export const type =
145
+ new RequestType < string , EditorOperationResponse , void , void > (
146
+ 'editor/saveFile' ) ;
147
+ }
148
+
143
149
export namespace ShowErrorMessageRequest {
144
150
export const type =
145
151
new RequestType < string , EditorOperationResponse , void , void > (
@@ -239,14 +245,18 @@ export class ExtensionCommandsFeature implements IFeature {
239
245
NewFileRequest . type ,
240
246
filePath => this . newFile ( ) ) ;
241
247
242
- this . languageClient . onRequest (
248
+ this . languageClient . onRequest (
243
249
OpenFileRequest . type ,
244
250
filePath => this . openFile ( filePath ) ) ;
245
251
246
252
this . languageClient . onRequest (
247
253
CloseFileRequest . type ,
248
254
filePath => this . closeFile ( filePath ) ) ;
249
255
256
+ this . languageClient . onRequest (
257
+ SaveFileRequest . type ,
258
+ filePath => this . saveFile ( filePath ) ) ;
259
+
250
260
this . languageClient . onRequest (
251
261
ShowInformationMessageRequest . type ,
252
262
message => this . showInformationMessage ( message ) ) ;
@@ -408,6 +418,36 @@ export class ExtensionCommandsFeature implements IFeature {
408
418
return promise ;
409
419
}
410
420
421
+ private saveFile ( filePath : string ) : Thenable < EditorOperationResponse > {
422
+
423
+ var promise : Thenable < EditorOperationResponse > ;
424
+
425
+ // Make sure the file path is absolute
426
+ if ( ! path . win32 . isAbsolute ( filePath ) )
427
+ {
428
+ filePath = path . win32 . resolve (
429
+ vscode . workspace . rootPath ,
430
+ filePath ) ;
431
+ }
432
+
433
+ // Normalize file path case for comparison
434
+ var normalizedFilePath = filePath . toLowerCase ( ) ;
435
+
436
+ if ( vscode . workspace . textDocuments . find ( doc => doc . fileName . toLowerCase ( ) == normalizedFilePath ) )
437
+ {
438
+ promise =
439
+ vscode . workspace . openTextDocument ( filePath )
440
+ . then ( doc => doc . save ( ) )
441
+ . then ( _ => EditorOperationResponse . Completed ) ;
442
+ }
443
+ else
444
+ {
445
+ promise = Promise . resolve ( EditorOperationResponse . Completed ) ;
446
+ }
447
+
448
+ return promise ;
449
+ }
450
+
411
451
private setSelection ( details : SetSelectionRequestArguments ) : EditorOperationResponse {
412
452
vscode . window . activeTextEditor . selections = [
413
453
new vscode . Selection (
0 commit comments