@@ -26,9 +26,11 @@ import queryParent = require('../../worker/queryParent');
26
26
// pushed in by child.ts
27
27
// If we are in a child context we patch the functions to execute via IPC.
28
28
// Otherwise we would call them directly.
29
- export var child : workerLib . Child ;
30
- if ( child ) {
31
- queryParent . echoNumWithModification = child . sendToIpc ( queryParent . echoNumWithModification )
29
+ var child : workerLib . Child ;
30
+ export function fixChild ( childInjected : typeof child ) {
31
+ child = childInjected ;
32
+ queryParent . echoNumWithModification = child . sendToIpc ( queryParent . echoNumWithModification ) ;
33
+ queryParent . getUpdatedTextForUnsavedEditors = child . sendToIpc ( queryParent . getUpdatedTextForUnsavedEditors ) ;
32
34
}
33
35
34
36
////////////////////////////////////////////////////////////////////////////////////////
@@ -39,12 +41,22 @@ var projectByProjectPath: { [projectDir: string]: Project } = {}
39
41
/** the project file path or any source ts file path */
40
42
var projectByFilePath : { [ filePath : string ] : Project } = { }
41
43
42
- /** Warning: we are loading the project from file system. This might not match what we have in the editor memory
43
- This is the reason why we aggresively send text to the worker on *Tab Change* and other places
44
+ /** We are loading the project from file system.
45
+ This might not match what we have in the editor memory, so query those as well
44
46
*/
45
47
function cacheAndCreateProject ( projectFile : tsconfig . TypeScriptProjectFileDetails ) {
46
48
var project = projectByProjectPath [ projectFile . projectFileDirectory ] = new Project ( projectFile ) ;
47
49
projectFile . project . files . forEach ( ( file ) => projectByFilePath [ file ] = project ) ;
50
+
51
+ // query the parent for unsaved changes
52
+ // We do this lazily
53
+ queryParent . getUpdatedTextForUnsavedEditors ( { } )
54
+ . then ( resp => {
55
+ resp . editors . forEach ( e => {
56
+ project . languageServiceHost . updateScript ( e . filePath , e . text ) ;
57
+ } ) ;
58
+ } ) ;
59
+
48
60
return project ;
49
61
}
50
62
0 commit comments