feat(language-service): provide diagnostic for invalid templateUrls (#32586)
`templateUrls` that do not point to actual files are now diagnosed as such by the Language Service. Support for `styleUrls` will come in a next PR. This introduces a utility method `getPropertyValueOfType` that scans TypeScript ASTs until a property assignment whose initializer of a certain type is found. This PR also notices a couple of things that could be improved in the language-service implementation, such as enumerating directive properties and unifying common logic, that will be fixed in future PRs. Part of #32564. PR Close #32586
This commit is contained in:
@ -37,6 +37,7 @@ class LanguageServiceImpl implements LanguageService {
|
||||
const analyzedModules = this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
|
||||
const results: Diagnostic[] = [];
|
||||
const templates = this.host.getTemplates(fileName);
|
||||
|
||||
for (const template of templates) {
|
||||
const astOrDiagnostic = this.host.getTemplateAst(template);
|
||||
if (isAstResult(astOrDiagnostic)) {
|
||||
@ -45,10 +46,12 @@ class LanguageServiceImpl implements LanguageService {
|
||||
results.push(astOrDiagnostic);
|
||||
}
|
||||
}
|
||||
|
||||
const declarations = this.host.getDeclarations(fileName);
|
||||
if (declarations && declarations.length) {
|
||||
results.push(...getDeclarationDiagnostics(declarations, analyzedModules));
|
||||
results.push(...getDeclarationDiagnostics(declarations, analyzedModules, this.host));
|
||||
}
|
||||
|
||||
const sourceFile = fileName.endsWith('.ts') ? this.host.getSourceFile(fileName) : undefined;
|
||||
return uniqueBySpan(results).map(d => ngDiagnosticToTsDiagnostic(d, sourceFile));
|
||||
}
|
||||
|
Reference in New Issue
Block a user