@@ -424,7 +424,7 @@ namespace ts.server {
424424 this . handleDeletedFile ( info ) ;
425425 }
426426 else {
427- if ( info && ( ! info . isOpen ) ) {
427+ if ( info && ( ! info . isScriptOpen ( ) ) ) {
428428 // file has been changed which might affect the set of referenced files in projects that include
429429 // this file and set of inferred projects
430430 info . reloadFromFile ( ) ;
@@ -440,7 +440,7 @@ namespace ts.server {
440440
441441 // TODO: handle isOpen = true case
442442
443- if ( ! info . isOpen ) {
443+ if ( ! info . isScriptOpen ( ) ) {
444444 this . filenameToScriptInfo . remove ( info . path ) ;
445445 this . lastDeletedFile = info ;
446446
@@ -634,10 +634,9 @@ namespace ts.server {
634634 // Closing file should trigger re-reading the file content from disk. This is
635635 // because the user may chose to discard the buffer content before saving
636636 // to the disk, and the server's version of the file can be out of sync.
637- info . reloadFromFile ( ) ;
637+ info . close ( ) ;
638638
639639 removeItemFromSet ( this . openFiles , info ) ;
640- info . isOpen = false ;
641640
642641 // collect all projects that should be removed
643642 let projectsToRemove : Project [ ] ;
@@ -989,7 +988,7 @@ namespace ts.server {
989988 }
990989 if ( toAdd ) {
991990 for ( const f of toAdd ) {
992- if ( f . isOpen && isRootFileInInferredProject ( f ) ) {
991+ if ( f . isScriptOpen ( ) && isRootFileInInferredProject ( f ) ) {
993992 // if file is already root in some inferred project
994993 // - remove the file from that project and delete the project if necessary
995994 const inferredProject = f . containingProjects [ 0 ] ;
@@ -1089,32 +1088,31 @@ namespace ts.server {
10891088 getOrCreateScriptInfoForNormalizedPath ( fileName : NormalizedPath , openedByClient : boolean , fileContent ?: string , scriptKind ?: ScriptKind , hasMixedContent ?: boolean ) {
10901089 let info = this . getScriptInfoForNormalizedPath ( fileName ) ;
10911090 if ( ! info ) {
1092- let content : string ;
1093- if ( this . host . fileExists ( fileName ) ) {
1094- // by default pick whatever content was supplied as the argument
1095- // if argument was not given - then for mixed content files assume that its content is empty string
1096- content = fileContent || ( hasMixedContent ? "" : this . host . readFile ( fileName ) ) ;
1097- }
1098- if ( ! content ) {
1091+ if ( openedByClient || this . host . fileExists ( fileName ) ) {
1092+ info = new ScriptInfo ( this . host , fileName , scriptKind , hasMixedContent ) ;
1093+
1094+ this . filenameToScriptInfo . set ( info . path , info ) ;
1095+
10991096 if ( openedByClient ) {
1100- content = "" ;
1097+ if ( fileContent === undefined ) {
1098+ // if file is opened by client and its content is not specified - use file text
1099+ fileContent = this . host . readFile ( fileName ) || "" ;
1100+ }
11011101 }
1102- }
1103- if ( content !== undefined ) {
1104- info = new ScriptInfo ( this . host , fileName , content , scriptKind , openedByClient , hasMixedContent ) ;
1105- // do not watch files with mixed content - server doesn't know how to interpret it
1106- this . filenameToScriptInfo . set ( info . path , info ) ;
1107- if ( ! info . isOpen && ! hasMixedContent ) {
1108- info . setWatcher ( this . host . watchFile ( fileName , _ => this . onSourceFileChanged ( fileName ) ) ) ;
1102+ else {
1103+ // do not watch files with mixed content - server doesn't know how to interpret it
1104+ if ( ! hasMixedContent ) {
1105+ info . setWatcher ( this . host . watchFile ( fileName , _ => this . onSourceFileChanged ( fileName ) ) ) ;
1106+ }
11091107 }
11101108 }
11111109 }
11121110 if ( info ) {
1113- if ( fileContent !== undefined ) {
1114- info . reload ( fileContent ) ;
1111+ if ( openedByClient && ! info . isScriptOpen ( ) ) {
1112+ info . open ( fileContent ) ;
11151113 }
1116- if ( openedByClient ) {
1117- info . isOpen = true ;
1114+ else if ( fileContent !== undefined ) {
1115+ info . reload ( fileContent ) ;
11181116 }
11191117 }
11201118 return info ;
@@ -1230,7 +1228,6 @@ namespace ts.server {
12301228 const info = this . getScriptInfoForNormalizedPath ( toNormalizedPath ( uncheckedFileName ) ) ;
12311229 if ( info ) {
12321230 this . closeOpenFile ( info ) ;
1233- info . isOpen = false ;
12341231 }
12351232 this . printProjects ( ) ;
12361233 }
@@ -1255,7 +1252,7 @@ namespace ts.server {
12551252 if ( openFiles ) {
12561253 for ( const file of openFiles ) {
12571254 const scriptInfo = this . getScriptInfo ( file . fileName ) ;
1258- Debug . assert ( ! scriptInfo || ! scriptInfo . isOpen ) ;
1255+ Debug . assert ( ! scriptInfo || ! scriptInfo . isScriptOpen ( ) ) ;
12591256 const normalizedPath = scriptInfo ? scriptInfo . fileName : toNormalizedPath ( file . fileName ) ;
12601257 this . openClientFileWithNormalizedPath ( normalizedPath , file . content , tryConvertScriptKindName ( file . scriptKind ) , file . hasMixedContent ) ;
12611258 }
0 commit comments