Skip to content

Commit e66a868

Browse files
committed
Remove all double work for type fetching
1 parent 4ffe382 commit e66a868

File tree

4 files changed

+73
-43
lines changed

4 files changed

+73
-43
lines changed

packages/app/src/app/vscode/metadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const METADATA = {
22
CORE: {
33
paths: {
4-
src: process.env.VSCODE ? '/vscode/out/vs' : '/public/vscode8/vs',
4+
src: '/public/vscode8/vs',
55
'npm/dev': 'node_modules/monaco-editor-core/dev/vs',
66
'npm/min': 'node_modules/monaco-editor-core/min/vs',
77
built: '/vscode/out-monaco-editor-core/min/vs',

standalone-packages/monaco-editor/test/samples-all.generated.js

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

standalone-packages/monaco-typescript/release/dev/tsWorker.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
8181
this._languageService = ts.createLanguageService(this);
8282
this.files = new Map();
8383
this.typesLoaded = false;
84+
this.fetchingTypes = false;
85+
this.fetchedTypes = [];
8486
this._ctx = ctx;
8587
this._compilerOptions = createData.compilerOptions;
8688
this._extraLibs = createData.extraLibs;
@@ -106,6 +108,10 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
106108
}
107109
TypeScriptWorker.prototype.getTypings = function () {
108110
var _this = this;
111+
if (this.fetchingTypes) {
112+
return;
113+
}
114+
this.fetchingTypes = true;
109115
var ensureDirectoryExistence = function (filePath, cb) {
110116
var dirname = BrowserFS.BFSRequire("path").dirname(filePath);
111117
_this.fs.stat(dirname, function (err, exists) {
@@ -124,10 +130,16 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
124130
}
125131
var code = data.toString();
126132
try {
127-
var p_1 = JSON.parse(code);
128-
var devDependencies_1 = p_1.devDependencies || {};
129-
Promise.join(__spread(Object.keys(p_1.dependencies), Object.keys(devDependencies_1).filter(function (p) { return p.indexOf("@types/") === 0; })).map(function (depName) {
130-
var version = p_1.dependencies[depName] || devDependencies_1[depName];
133+
var p = JSON.parse(code);
134+
var dependencies_1 = p.dependencies || {};
135+
var devDependencies_1 = p.devDependencies || {};
136+
Promise.join(__spread(Object.keys(dependencies_1), Object.keys(devDependencies_1).filter(function (p) { return p.indexOf("@types/") === 0; })).map(function (depName) {
137+
var version = dependencies_1[depName] || devDependencies_1[depName];
138+
var key = depName + "@" + version;
139+
if (_this.fetchedTypes.indexOf(key) > -1) {
140+
return Promise.as(void 0);
141+
}
142+
_this.fetchedTypes.push(key);
131143
return fetchTypings
132144
.fetchAndAddDependencies(depName, version)
133145
.then(function (paths) {
@@ -143,8 +155,7 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
143155
});
144156
}
145157
});
146-
})
147-
.catch(function () { });
158+
}).catch(function () { });
148159
})).then(function () {
149160
_this._languageService.cleanupSemanticCache();
150161
setTimeout(function () {
@@ -155,6 +166,9 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
155166
catch (e) {
156167
return;
157168
}
169+
finally {
170+
_this.fetchingTypes = false;
171+
}
158172
});
159173
};
160174
TypeScriptWorker.prototype.syncFile = function (path) {

standalone-packages/monaco-typescript/src/tsWorker.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
7474
private fs: any;
7575
private files: Map<string, string> = new Map();
7676
private typesLoaded: boolean = false;
77+
private fetchingTypes: boolean = false;
78+
private fetchedTypes: string[] = [];
7779

7880
constructor(ctx: IWorkerContext, createData: ICreateData) {
7981
this._ctx = ctx;
@@ -112,6 +114,12 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
112114
}
113115

114116
getTypings() {
117+
if (this.fetchingTypes) {
118+
return;
119+
}
120+
121+
this.fetchingTypes = true;
122+
115123
const ensureDirectoryExistence = (filePath, cb) => {
116124
const dirname = BrowserFS.BFSRequire("path").dirname(filePath);
117125
this.fs.stat(dirname, (err, exists) => {
@@ -134,17 +142,24 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
134142
const code = data.toString();
135143
try {
136144
const p = JSON.parse(code);
137-
145+
const dependencies = p.dependencies || {};
138146
const devDependencies = p.devDependencies || {};
139147

140148
Promise.join(
141149
[
142-
...Object.keys(p.dependencies),
150+
...Object.keys(dependencies),
143151
...Object.keys(devDependencies).filter(
144152
p => p.indexOf("@types/") === 0
145153
)
146154
].map(depName => {
147-
const version = p.dependencies[depName] || devDependencies[depName];
155+
const version = dependencies[depName] || devDependencies[depName];
156+
157+
const key = `${depName}@${version}`;
158+
if (this.fetchedTypes.indexOf(key) > -1) {
159+
return Promise.as(void 0);
160+
}
161+
162+
this.fetchedTypes.push(key);
148163

149164
return fetchTypings
150165
.fetchAndAddDependencies(depName, version)
@@ -163,8 +178,7 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
163178
});
164179
}
165180
});
166-
})
167-
.catch(() => {});
181+
}).catch(() => {})
168182
})
169183
).then(() => {
170184
this._languageService.cleanupSemanticCache();
@@ -174,6 +188,8 @@ export class TypeScriptWorker implements ts.LanguageServiceHost {
174188
});
175189
} catch (e) {
176190
return;
191+
} finally {
192+
this.fetchingTypes = false;
177193
}
178194
});
179195
}

0 commit comments

Comments
 (0)