@@ -304,26 +304,7 @@ namespace ts.server {
304304 return normalizePath ( name ) ;
305305 }
306306
307- // TODO: delete if unused
308- // private releaseNonReferencedConfiguredProjects() {
309- // if (this.configuredProjects.every(p => p.openRefCount > 0)) {
310- // return;
311- // }
312-
313- // const configuredProjects: ConfiguredProject[] = [];
314- // for (const proj of this.configuredProjects) {
315- // if (proj.openRefCount > 0) {
316- // configuredProjects.push(proj);
317- // }
318- // else {
319- // proj.close();
320- // }
321- // }
322-
323- // this.configuredProjects = configuredProjects;
324- // }
325-
326- private removeProject ( project : Project ) {
307+ private removeProject ( project : Project ) {
327308 this . log ( `remove project: ${ project . getRootFiles ( ) . toString ( ) } ` ) ;
328309
329310 project . close ( ) ;
@@ -430,7 +411,7 @@ namespace ts.server {
430411 // collect all projects that should be removed
431412 let projectsToRemove : Project [ ] ;
432413 for ( const p of info . containingProjects ) {
433- if ( p . projectKind === ProjectKind . Configured ) {
414+ if ( p . projectKind === ProjectKind . Configured ) {
434415 // last open file in configured project - close it
435416 if ( ( < ConfiguredProject > p ) . deleteOpenRef ( ) === 0 ) {
436417 ( projectsToRemove || ( projectsToRemove = [ ] ) ) . push ( p ) ;
@@ -761,7 +742,7 @@ namespace ts.server {
761742 if ( contains ( this . openFilesReferenced , info ) ) {
762743 removeItemFromSet ( this . openFilesReferenced , info ) ;
763744 }
764- if ( project . projectKind === ProjectKind . Configured ) {
745+ if ( project . projectKind === ProjectKind . Configured ) {
765746 this . openFileRootsConfigured . push ( info ) ;
766747 }
767748 }
@@ -1115,27 +1096,35 @@ namespace ts.server {
11151096 }
11161097
11171098 applyChangesInOpenFiles ( openFiles : protocol . NewOpenFile [ ] , changedFiles : protocol . ChangedOpenFile [ ] , closedFiles : string [ ] ) : void {
1118- for ( const file of openFiles ) {
1119- const scriptInfo = this . getScriptInfo ( file . fileName ) ;
1120- Debug . assert ( ! scriptInfo || ! scriptInfo . isOpen ) ;
1121- this . openClientFileWithNormalizedPath ( toNormalizedPath ( file . fileName ) , file . content ) ;
1122- }
1123-
1124- for ( const file of changedFiles ) {
1125- const scriptInfo = this . getScriptInfo ( file . fileName ) ;
1126- Debug . assert ( ! ! scriptInfo ) ;
1127- // apply changes in reverse order
1128- for ( let i = file . changes . length - 1 ; i >= 0 ; i -- ) {
1129- const change = file . changes [ i ] ;
1130- scriptInfo . editContent ( change . span . start , change . span . start + change . span . length , change . newText ) ;
1099+ if ( openFiles ) {
1100+ for ( const file of openFiles ) {
1101+ const scriptInfo = this . getScriptInfo ( file . fileName ) ;
1102+ Debug . assert ( ! scriptInfo || ! scriptInfo . isOpen ) ;
1103+ this . openClientFileWithNormalizedPath ( toNormalizedPath ( file . fileName ) , file . content ) ;
11311104 }
11321105 }
11331106
1134- for ( const file of closedFiles ) {
1135- this . closeClientFile ( file ) ;
1107+ if ( changedFiles ) {
1108+ for ( const file of changedFiles ) {
1109+ const scriptInfo = this . getScriptInfo ( file . fileName ) ;
1110+ Debug . assert ( ! ! scriptInfo ) ;
1111+ // apply changes in reverse order
1112+ for ( let i = file . changes . length - 1 ; i >= 0 ; i -- ) {
1113+ const change = file . changes [ i ] ;
1114+ scriptInfo . editContent ( change . span . start , change . span . start + change . span . length , change . newText ) ;
1115+ }
1116+ }
11361117 }
11371118
1138- this . updateProjectStructure ( ) ;
1119+ if ( closedFiles ) {
1120+ for ( const file of closedFiles ) {
1121+ this . closeClientFile ( file ) ;
1122+ }
1123+ }
1124+
1125+ if ( openFiles || changedFiles || closedFiles ) {
1126+ this . updateProjectStructure ( ) ;
1127+ }
11391128 }
11401129
11411130 closeExternalProject ( uncheckedFileName : string ) : void {
0 commit comments