@@ -67,7 +67,10 @@ namespace ts.server {
6767 this . lineMap = undefined ;
6868 }
6969
70- /** returns true if text changed */
70+ /**
71+ * Set the contents as newText
72+ * returns true if text changed
73+ */
7174 public reload ( newText : string ) {
7275 Debug . assert ( newText !== undefined ) ;
7376
@@ -87,31 +90,31 @@ namespace ts.server {
8790 }
8891 }
8992
90- /** returns true if text changed */
93+ /**
94+ * Reads the contents from tempFile(if supplied) or own file and sets it as contents
95+ * returns true if text changed
96+ */
97+ public reloadWithFileText ( tempFileName ?: string ) {
98+ const reloaded = this . reload ( this . getFileText ( tempFileName ) ) ;
99+ this . ownFileText = ! tempFileName || tempFileName === this . fileName ;
100+ return reloaded ;
101+ }
102+
103+ /**
104+ * Reloads the contents from the file if there is no pending reload from disk or the contents of file are same as file text
105+ * returns true if text changed
106+ */
91107 public reloadFromDisk ( ) {
92- let reloaded = false ;
93108 if ( ! this . pendingReloadFromDisk && ! this . ownFileText ) {
94- reloaded = this . reload ( this . getFileText ( ) ) ;
95- this . ownFileText = true ;
109+ return this . reloadWithFileText ( ) ;
96110 }
97- return reloaded ;
111+ return false ;
98112 }
99113
100114 public delayReloadFromFileIntoText ( ) {
101115 this . pendingReloadFromDisk = true ;
102116 }
103117
104- /** returns true if text changed */
105- public reloadFromFile ( tempFileName : string ) {
106- let reloaded = false ;
107- // Reload if different file or we dont know if we are working with own file text
108- if ( tempFileName !== this . fileName || ! this . ownFileText ) {
109- reloaded = this . reload ( this . getFileText ( tempFileName ) ) ;
110- this . ownFileText = ! tempFileName || tempFileName === this . fileName ;
111- }
112- return reloaded ;
113- }
114-
115118 public getSnapshot ( ) : IScriptSnapshot {
116119 return this . useScriptVersionCacheIfValidOrOpen ( )
117120 ? this . svc . getSnapshot ( )
@@ -180,8 +183,7 @@ namespace ts.server {
180183 private getOrLoadText ( ) {
181184 if ( this . text === undefined || this . pendingReloadFromDisk ) {
182185 Debug . assert ( ! this . svc || this . pendingReloadFromDisk , "ScriptVersionCache should not be set when reloading from disk" ) ;
183- this . reload ( this . getFileText ( ) ) ;
184- this . ownFileText = true ;
186+ this . reloadWithFileText ( ) ;
185187 }
186188 return this . text ;
187189 }
@@ -385,7 +387,7 @@ namespace ts.server {
385387 this . markContainingProjectsAsDirty ( ) ;
386388 }
387389 else {
388- if ( this . textStorage . reloadFromFile ( tempFileName ) ) {
390+ if ( this . textStorage . reloadWithFileText ( tempFileName ) ) {
389391 this . markContainingProjectsAsDirty ( ) ;
390392 }
391393 }
0 commit comments