Merge pull request #2125 from Microsoft/updateProjectStructure

Update project structure on idle after change
This commit is contained in:
Steve Lucco 2015-02-25 21:58:46 -08:00
commit 42bc64b168
3 changed files with 60 additions and 28 deletions

View file

@ -101,13 +101,7 @@ module ts.server {
}
getScriptFileNames() {
var filenames: string[] = [];
for (var filename in this.filenameToScript) {
if (this.filenameToScript[filename] && this.filenameToScript[filename].isOpen) {
filenames.push(filename);
}
}
return filenames;
return this.roots.map(root => root.fileName);
}
getScriptVersion(filename: string) {
@ -536,15 +530,35 @@ module ts.server {
updateProjectStructure() {
this.log("updating project structure from ...", "Info");
this.printProjects();
// First loop through all open files that are referenced by projects but are not
// project roots. For each referenced file, see if the default project still
// references that file. If so, then just keep the file in the referenced list.
// If not, add the file to an unattached list, to be rechecked later.
var openFilesReferenced: ScriptInfo[] = [];
var unattachedOpenFiles: ScriptInfo[] = [];
for (var i = 0, len = this.openFilesReferenced.length; i < len; i++) {
var refdFile = this.openFilesReferenced[i];
refdFile.defaultProject.updateGraph();
var sourceFile = refdFile.defaultProject.getSourceFile(refdFile);
if (!sourceFile) {
this.openFilesReferenced = copyListRemovingItem(refdFile, this.openFilesReferenced);
this.addOpenFile(refdFile);
var referencedFile = this.openFilesReferenced[i];
referencedFile.defaultProject.updateGraph();
var sourceFile = referencedFile.defaultProject.getSourceFile(referencedFile);
if (sourceFile) {
openFilesReferenced.push(referencedFile);
}
else {
unattachedOpenFiles.push(referencedFile);
}
}
this.openFilesReferenced = openFilesReferenced;
// Then, loop through all of the open files that are project roots.
// For each root file, note the project that it roots. Then see if
// any other projects newly reference the file. If zero projects
// newly reference the file, keep it as a root. If one or more
// projects newly references the file, remove its project from the
// inferred projects list (since it is no longer a root) and add
// the file to the open, referenced file list.
var openFileRoots: ScriptInfo[] = [];
for (var i = 0, len = this.openFileRoots.length; i < len; i++) {
var rootFile = this.openFileRoots[i];
@ -555,12 +569,19 @@ module ts.server {
openFileRoots.push(rootFile);
}
else {
// remove project from inferred projects list
// remove project from inferred projects list because root captured
this.inferredProjects = copyListRemovingItem(rootedProject, this.inferredProjects);
this.openFilesReferenced.push(rootFile);
}
}
this.openFileRoots = openFileRoots;
// Finally, if we found any open, referenced files that are no longer
// referenced by their default project, treat them as newly opened
// by the editor.
for (var i = 0, len = unattachedOpenFiles.length; i < len; i++) {
this.addOpenFile(unattachedOpenFiles[i]);
}
this.printProjects();
}

View file

@ -206,7 +206,10 @@ module ts.server {
}
};
var ioSession = new IOSession(ts.sys, logger);
process.on('uncaughtException', function(err: Error) {
ioSession.logError(err, "unknown");
});
// Start listening
new IOSession(ts.sys, logger).listen();
ioSession.listen();
}

View file

@ -181,18 +181,29 @@ module ts.server {
}
semanticCheck(file: string, project: Project) {
var diags = project.compilerService.languageService.getSemanticDiagnostics(file);
if (diags) {
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag");
try {
var diags = project.compilerService.languageService.getSemanticDiagnostics(file);
if (diags) {
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
this.event({ file: file, diagnostics: bakedDiags }, "semanticDiag");
}
}
catch (err) {
this.logError(err, "semantic check");
}
}
syntacticCheck(file: string, project: Project) {
var diags = project.compilerService.languageService.getSyntacticDiagnostics(file);
if (diags) {
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag");
try {
var diags = project.compilerService.languageService.getSyntacticDiagnostics(file);
if (diags) {
var bakedDiags = diags.map((diag) => formatDiag(file, project, diag));
this.event({ file: file, diagnostics: bakedDiags }, "syntaxDiag");
}
}
catch (err) {
this.logError(err, "syntactic check");
}
}
@ -553,10 +564,7 @@ module ts.server {
compilerService.host.editScript(file, start, end, insertString);
this.changeSeq++;
}
// update project structure on idle commented out
// until we can have the host return only the root files
// from getScriptFileNames()
//this.updateProjectStructure(this.changeSeq, (n) => n == this.changeSeq);
this.updateProjectStructure(this.changeSeq, (n) => n == this.changeSeq);
}
}