Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/language-service/src/ts_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ export function getExternalFiles(project: tss.server.Project): string[] {
return [];
}
const ngLsHost = PROJECT_MAP.get(project);
ngLsHost?.getAnalyzedModules();
return ngLsHost?.getExternalTemplates() || [];
if (ngLsHost === undefined) {
return [];
}
ngLsHost.getAnalyzedModules();
return ngLsHost.getExternalTemplates().filter(fileName => {
// TODO(kyliau): Remove this when the following PR lands on the version of
// TypeScript used in this repo.
// https://github.com/microsoft/TypeScript/pull/41737
return project.fileExists(fileName);
});
}

export function create(info: tss.server.PluginCreateInfo): tss.LanguageService {
Expand Down
7 changes: 7 additions & 0 deletions packages/language-service/test/ts_plugin_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const mockProject = {
},
},
hasRoots: () => true,
fileExists: () => true,
} as any;

describe('plugin', () => {
Expand Down Expand Up @@ -136,6 +137,12 @@ describe('plugin', () => {
'/app/test.ng',
]);
});

it('should not return external template that does not exist', () => {
spyOn(mockProject, 'fileExists').and.returnValue(false);
const externalTemplates = getExternalFiles(mockProject);
expect(externalTemplates.length).toBe(0);
});
});

describe(`with config 'angularOnly = true`, () => {
Expand Down