2
2
* Copyright (C) Microsoft Corporation. All rights reserved.
3
3
*--------------------------------------------------------*/
4
4
5
+ import os = require( 'os' ) ;
5
6
import path = require( 'path' ) ;
6
7
import vscode = require( 'vscode' ) ;
7
8
import { IFeature } from '../feature' ;
@@ -371,13 +372,7 @@ export class ExtensionCommandsFeature implements IFeature {
371
372
372
373
private openFile ( filePath : string ) : Thenable < EditorOperationResponse > {
373
374
374
- // Make sure the file path is absolute
375
- if ( ! path . win32 . isAbsolute ( filePath ) )
376
- {
377
- filePath = path . win32 . resolve (
378
- vscode . workspace . rootPath ,
379
- filePath ) ;
380
- }
375
+ filePath = this . normalizeFilePath ( filePath ) ;
381
376
382
377
var promise =
383
378
vscode . workspace . openTextDocument ( filePath )
@@ -391,18 +386,21 @@ export class ExtensionCommandsFeature implements IFeature {
391
386
392
387
var promise : Thenable < EditorOperationResponse > ;
393
388
394
- // Make sure the file path is absolute
395
- if ( ! path . win32 . isAbsolute ( filePath ) )
396
- {
397
- filePath = path . win32 . resolve (
398
- vscode . workspace . rootPath ,
399
- filePath ) ;
400
- }
389
+ var normalizedFilePath = this . normalizeFilePath ( filePath ) ;
401
390
402
- // Normalize file path case for comparison
403
- var normalizedFilePath = filePath . toLowerCase ( ) ;
391
+ // since Windows is case-insensitive, we need to normalize it differently
392
+ var canFind = vscode . workspace . textDocuments . find ( doc => {
393
+ var docPath ;
394
+ if ( os . platform ( ) == "win32" ) {
395
+ // for windows paths, they are normalized to be lowercase
396
+ docPath = doc . fileName . toLowerCase ( ) ;
397
+ } else {
398
+ docPath = doc . fileName ;
399
+ }
400
+ return docPath == normalizedFilePath ;
401
+ } ) ;
404
402
405
- if ( vscode . workspace . textDocuments . find ( doc => doc . fileName . toLowerCase ( ) == normalizedFilePath ) )
403
+ if ( canFind )
406
404
{
407
405
promise =
408
406
vscode . workspace . openTextDocument ( filePath )
@@ -422,22 +420,29 @@ export class ExtensionCommandsFeature implements IFeature {
422
420
423
421
var promise : Thenable < EditorOperationResponse > ;
424
422
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
- }
423
+ var normalizedFilePath = this . normalizeFilePath ( filePath ) ;
432
424
433
- // Normalize file path case for comparison
434
- var normalizedFilePath = filePath . toLowerCase ( ) ;
425
+ // since Windows is case-insensitive, we need to normalize it differently
426
+ var canFind = vscode . workspace . textDocuments . find ( doc => {
427
+ var docPath ;
428
+ if ( os . platform ( ) == "win32" ) {
429
+ // for windows paths, they are normalized to be lowercase
430
+ docPath = doc . fileName . toLowerCase ( ) ;
431
+ } else {
432
+ docPath = doc . fileName ;
433
+ }
434
+ return docPath == normalizedFilePath ;
435
+ } ) ;
435
436
436
- if ( vscode . workspace . textDocuments . find ( doc => doc . fileName . toLowerCase ( ) == normalizedFilePath ) )
437
+ if ( canFind )
437
438
{
438
439
promise =
439
440
vscode . workspace . openTextDocument ( filePath )
440
- . then ( doc => doc . save ( ) )
441
+ . then ( doc => {
442
+ if ( doc . isDirty ) {
443
+ doc . save ( ) ;
444
+ }
445
+ } )
441
446
. then ( _ => EditorOperationResponse . Completed ) ;
442
447
}
443
448
else
@@ -448,6 +453,31 @@ export class ExtensionCommandsFeature implements IFeature {
448
453
return promise ;
449
454
}
450
455
456
+ private normalizeFilePath ( filePath : string ) : string {
457
+ if ( os . platform ( ) == "win32" ) {
458
+ // Make sure the file path is absolute
459
+ if ( ! path . win32 . isAbsolute ( filePath ) )
460
+ {
461
+ filePath = path . win32 . resolve (
462
+ vscode . workspace . rootPath ,
463
+ filePath ) ;
464
+ }
465
+
466
+ // Normalize file path case for comparison for Windows
467
+ return filePath . toLowerCase ( ) ;
468
+ } else {
469
+ // Make sure the file path is absolute
470
+ if ( ! path . isAbsolute ( filePath ) )
471
+ {
472
+ filePath = path . resolve (
473
+ vscode . workspace . rootPath ,
474
+ filePath ) ;
475
+ }
476
+
477
+ return filePath ;
478
+ }
479
+ }
480
+
451
481
private setSelection ( details : SetSelectionRequestArguments ) : EditorOperationResponse {
452
482
vscode . window . activeTextEditor . selections = [
453
483
new vscode . Selection (
0 commit comments