File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2035,4 +2035,33 @@ namespace ts.projectSystem {
20352035 checkProjectActualFiles ( projectService . configuredProjects [ 0 ] , [ f1 . path , t2 . path ] ) ;
20362036 } ) ;
20372037 } ) ;
2038+
2039+ describe ( "Open-file" , ( ) => {
2040+ it ( "can be reloaded with empty content" , ( ) => {
2041+ const f = {
2042+ path : "/a/b/app.ts" ,
2043+ content : "let x = 1"
2044+ } ;
2045+ const projectFileName = "externalProject" ;
2046+ const host = createServerHost ( [ f ] ) ;
2047+ const projectService = createProjectService ( host ) ;
2048+ // create a project
2049+ projectService . openExternalProject ( { projectFileName, rootFiles : [ toExternalFile ( f . path ) ] , options : { } } ) ;
2050+ projectService . checkNumberOfProjects ( { externalProjects : 1 } ) ;
2051+
2052+ const p = projectService . externalProjects [ 0 ] ;
2053+ // force to load the content of the file
2054+ p . updateGraph ( ) ;
2055+
2056+ const scriptInfo = p . getScriptInfo ( f . path ) ;
2057+ checkSnapLength ( scriptInfo . snap ( ) , f . content . length ) ;
2058+
2059+ // open project and replace its content with empty string
2060+ projectService . openClientFile ( f . path , "" ) ;
2061+ checkSnapLength ( scriptInfo . snap ( ) , 0 ) ;
2062+ } ) ;
2063+ function checkSnapLength ( snap : server . LineIndexSnapshot , expectedLength : number ) {
2064+ assert . equal ( snap . getLength ( ) , expectedLength , "Incorrect snapshot size" ) ;
2065+ }
2066+ } ) ;
20382067}
Original file line number Diff line number Diff line change @@ -990,7 +990,7 @@ namespace ts.server {
990990 }
991991 }
992992 if ( info ) {
993- if ( fileContent ) {
993+ if ( fileContent !== undefined ) {
994994 info . reload ( fileContent ) ;
995995 }
996996 if ( openedByClient ) {
You can’t perform that action at this time.
0 commit comments