Skip to content

Commit d387050

Browse files
author
zhengbli
committed
Fix merging issues and multiple project scenario
1 parent 94d44ad commit d387050

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ namespace ts {
12191219
(oldOptions.noLib !== options.noLib) ||
12201220
(oldOptions.jsx !== options.jsx) ||
12211221
(oldOptions.allowJs !== options.allowJs) ||
1222-
(oldOptions.disableSizeLimit !== options.disableSizeLimit) ||
1222+
(oldOptions.disableSizeLimit !== options.disableSizeLimit) ||
12231223
(oldOptions.rootDir !== options.rootDir) ||
12241224
(oldOptions.typesSearchPaths !== options.typesSearchPaths) ||
12251225
(oldOptions.configFilePath !== options.configFilePath) ||

src/compiler/sys.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace ts {
2828
getDirectories(path: string): string[];
2929
readDirectory(path: string, extension?: string, exclude?: string[]): string[];
3030
readDirectoryWithMultipleExtensions?(path: string, extensions: string[], exclude?: string[]): string[];
31-
getModifiedTime?(path: string): Date;
31+
getModifiedTime?(path: string): Date;
3232
createHash?(data: string): string;
3333
getMemoryUsage?(): number;
3434
exit(exitCode?: number): void;
@@ -549,7 +549,7 @@ namespace ts {
549549
getDirectories,
550550
readDirectory,
551551
readDirectoryWithMultipleExtensions,
552-
getModifiedTime(path) {
552+
getModifiedTime(path) {
553553
try {
554554
return _fs.statSync(path).mtime;
555555
}

src/server/editorServices.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ namespace ts.server {
12171217
else {
12181218
this.log("No config files found.");
12191219
}
1220-
this.log("end openOrUpdateConfiguredProjectForFile: " + new Date().getTime());
1220+
this.log("end openOrUpdateConfiguredProjectForFile: " + new Date().getTime());
12211221
return configFileName ? { configFileName } : {};
12221222
}
12231223

@@ -1398,7 +1398,7 @@ namespace ts.server {
13981398
}
13991399
}
14001400

1401-
updateConfiguredProject(project: Project) {
1401+
updateConfiguredProject(project: Project): Diagnostic[] {
14021402
if (!this.host.fileExists(project.projectFilename)) {
14031403
this.log("Config file deleted");
14041404
this.removeProject(project);
@@ -1434,9 +1434,6 @@ namespace ts.server {
14341434
const info = this.openFile(rootFilename, /*openedByClient*/ false);
14351435
project.addRoot(info);
14361436
}
1437-
else {
1438-
return { errorMsg: "specified file " + rootFilename + " not found" };
1439-
}
14401437
}
14411438
project.finishGraph();
14421439
return;
@@ -1460,9 +1457,6 @@ namespace ts.server {
14601457
for (const fileName of fileNamesToAdd) {
14611458
let info = this.getScriptInfo(fileName);
14621459
if (!info) {
1463-
if (!this.host.fileExists(info.fileName)) {
1464-
return { errorMsg: "specified file " + info.fileName + " not found" };
1465-
}
14661460
info = this.openFile(fileName, /*openedByClient*/ false);
14671461
}
14681462
else {

src/server/session.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,12 @@ namespace ts.server {
444444
const file = ts.normalizePath(fileName);
445445
const info = this.projectService.getScriptInfo(file);
446446
const projects = this.projectService.findReferencingProjects(info);
447-
if (!projects.length) {
447+
const projectsWithLanguageServiceEnabeld = ts.filter(projects, p => !p.languageServiceDiabled);
448+
if (projects.length === 0 || projectsWithLanguageServiceEnabeld.length === 0) {
448449
throw Errors.NoProject;
449450
}
450451

451-
const defaultProject = projects[0];
452+
const defaultProject = projectsWithLanguageServiceEnabeld[0];
452453
// The rename info should be the same for every project
453454
const defaultProjectCompilerService = defaultProject.compilerService;
454455
const position = defaultProjectCompilerService.host.lineOffsetToPosition(file, line, offset);
@@ -465,7 +466,7 @@ namespace ts.server {
465466
}
466467

467468
const fileSpans = combineProjectOutput(
468-
projects,
469+
projectsWithLanguageServiceEnabeld,
469470
(project: Project) => {
470471
const compilerService = project.compilerService;
471472
const renameLocations = compilerService.languageService.findRenameLocations(file, position, findInStrings, findInComments);
@@ -526,11 +527,12 @@ namespace ts.server {
526527
const file = ts.normalizePath(fileName);
527528
const info = this.projectService.getScriptInfo(file);
528529
const projects = this.projectService.findReferencingProjects(info);
529-
if (!projects.length) {
530+
const projectsWithLanguageServiceEnabeld = ts.filter(projects, p => !p.languageServiceDiabled);
531+
if (projects.length === 0 || projectsWithLanguageServiceEnabeld.length === 0) {
530532
throw Errors.NoProject;
531533
}
532534

533-
const defaultProject = projects[0];
535+
const defaultProject = projectsWithLanguageServiceEnabeld[0];
534536
const position = defaultProject.compilerService.host.lineOffsetToPosition(file, line, offset);
535537
const nameInfo = defaultProject.compilerService.languageService.getQuickInfoAtPosition(file, position);
536538
if (!nameInfo) {
@@ -542,7 +544,7 @@ namespace ts.server {
542544
const nameColStart = defaultProject.compilerService.host.positionToLineOffset(file, nameSpan.start).offset;
543545
const nameText = defaultProject.compilerService.host.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan));
544546
const refs = combineProjectOutput<protocol.ReferencesResponseItem>(
545-
projects,
547+
projectsWithLanguageServiceEnabeld,
546548
(project: Project) => {
547549
const compilerService = project.compilerService;
548550
const references = compilerService.languageService.getReferencesAtPosition(file, position);
@@ -902,13 +904,13 @@ namespace ts.server {
902904
const file = ts.normalizePath(fileName);
903905
const info = this.projectService.getScriptInfo(file);
904906
const projects = this.projectService.findReferencingProjects(info);
905-
const defaultProject = projects[0];
906-
if (!defaultProject) {
907+
const projectsWithLanguageServiceEnabeld = ts.filter(projects, p => !p.languageServiceDiabled);
908+
if (projects.length === 0 || projectsWithLanguageServiceEnabeld.length === 0) {
907909
throw Errors.NoProject;
908910
}
909911

910912
const allNavToItems = combineProjectOutput(
911-
projects,
913+
projectsWithLanguageServiceEnabeld,
912914
(project: Project) => {
913915
const compilerService = project.compilerService;
914916
const navItems = compilerService.languageService.getNavigateToItems(searchValue, maxResultCount);

0 commit comments

Comments
 (0)