@@ -67,7 +67,10 @@ namespace ts.server {
67
67
this . lineMap = undefined ;
68
68
}
69
69
70
- /** returns true if text changed */
70
+ /**
71
+ * Set the contents as newText
72
+ * returns true if text changed
73
+ */
71
74
public reload ( newText : string ) {
72
75
Debug . assert ( newText !== undefined ) ;
73
76
@@ -87,31 +90,31 @@ namespace ts.server {
87
90
}
88
91
}
89
92
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
+ */
91
107
public reloadFromDisk ( ) {
92
- let reloaded = false ;
93
108
if ( ! this . pendingReloadFromDisk && ! this . ownFileText ) {
94
- reloaded = this . reload ( this . getFileText ( ) ) ;
95
- this . ownFileText = true ;
109
+ return this . reloadWithFileText ( ) ;
96
110
}
97
- return reloaded ;
111
+ return false ;
98
112
}
99
113
100
114
public delayReloadFromFileIntoText ( ) {
101
115
this . pendingReloadFromDisk = true ;
102
116
}
103
117
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
-
115
118
public getSnapshot ( ) : IScriptSnapshot {
116
119
return this . useScriptVersionCacheIfValidOrOpen ( )
117
120
? this . svc . getSnapshot ( )
@@ -180,8 +183,7 @@ namespace ts.server {
180
183
private getOrLoadText ( ) {
181
184
if ( this . text === undefined || this . pendingReloadFromDisk ) {
182
185
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 ( ) ;
185
187
}
186
188
return this . text ;
187
189
}
@@ -385,7 +387,7 @@ namespace ts.server {
385
387
this . markContainingProjectsAsDirty ( ) ;
386
388
}
387
389
else {
388
- if ( this . textStorage . reloadFromFile ( tempFileName ) ) {
390
+ if ( this . textStorage . reloadWithFileText ( tempFileName ) ) {
389
391
this . markContainingProjectsAsDirty ( ) ;
390
392
}
391
393
}
0 commit comments