Skip to content

Commit 4d16043

Browse files
committed
Improve typing handling + typescript projects
1 parent 67bab31 commit 4d16043

File tree

12 files changed

+1016
-884
lines changed

12 files changed

+1016
-884
lines changed

packages/app/src/app/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ window.BrowserFS.configure(
148148
manager: controller,
149149
},
150150
},
151+
'/sandbox/node_modules': {
152+
fs: 'InMemory',
153+
},
151154
'/vscode': {
152155
fs: 'LocalStorage',
153156
},

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
4545
this._extraLibs = Object.create(null);
4646
this._languageService = ts.createLanguageService(this);
4747
this.files = {};
48+
this.typesLoaded = false;
4849
this._ctx = ctx;
4950
this._compilerOptions = createData.compilerOptions;
5051
this._extraLibs = createData.extraLibs;
@@ -68,6 +69,18 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
6869
}
6970
TypeScriptWorker.prototype.getTypings = function () {
7071
var _this = this;
72+
var ensureDirectoryExistence = function (filePath, cb) {
73+
var dirname = BrowserFS.BFSRequire('path').dirname(filePath);
74+
_this.fs.stat(dirname, function (err, exists) {
75+
if (!!exists) {
76+
cb(true);
77+
return;
78+
}
79+
ensureDirectoryExistence(dirname, function () {
80+
_this.fs.mkdir(dirname, cb);
81+
});
82+
});
83+
};
7184
this.fs.readFile('/sandbox/package.json', function (e, data) {
7285
if (e) {
7386
return;
@@ -77,8 +90,15 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
7790
var p = JSON.parse(code);
7891
fetchTypings.fetchAndAddDependencies(p.dependencies, function (paths) {
7992
Object.keys(paths).forEach(function (p) {
80-
_this.files['/' + p] = paths[p];
93+
var pathToWrite = '/sandbox/' + p;
94+
_this.files[pathToWrite] = paths[p];
95+
ensureDirectoryExistence(pathToWrite, function () {
96+
_this.fs.writeFile(pathToWrite, paths[p], function () { });
97+
});
8198
});
99+
}).then(function () {
100+
_this.typesLoaded = true;
101+
_this._languageService.cleanupSemanticCache();
82102
});
83103
}
84104
catch (e) {
@@ -245,11 +265,17 @@ define(["require", "exports", "./lib/typescriptServices", "./lib/lib", "./fetchD
245265
});
246266
};
247267
TypeScriptWorker.prototype.getSyntacticDiagnostics = function (fileName) {
268+
if (!this.typesLoaded) {
269+
return Promise.as([]);
270+
}
248271
var diagnostics = this._languageService.getSyntacticDiagnostics(fileName);
249272
TypeScriptWorker.clearFiles(diagnostics);
250273
return Promise.as(diagnostics);
251274
};
252275
TypeScriptWorker.prototype.getSemanticDiagnostics = function (fileName) {
276+
if (!this.typesLoaded) {
277+
return Promise.as([]);
278+
}
253279
var diagnostics = this._languageService.getSemanticDiagnostics(fileName);
254280
TypeScriptWorker.clearFiles(diagnostics);
255281
return Promise.as(diagnostics);

0 commit comments

Comments
 (0)