Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(language-service): do not return external template that does not exist #39898

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/language-service/src/ts_plugin.ts
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
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