feat(language-service): add definitions for templateUrl (#32238)
Adds support for `getDefinitionAt` when called on a templateUrl property assignment. The currrent architecture for getting definitions is designed to be called on templates, so we have to introduce a new `getTsDefinitionAndBoundSpan` method to get Angular-specific definitions in TypeScript files and pass a `readTemplate` closure that will read the contents of a template using `TypeScriptServiceHost#getTemplates`. We can probably go in and make this nicer in a future PR, though I'm not sure what the best architecture should be yet. Part of angular/vscode-ng-language-service#111 PR Close #32238
This commit is contained in:
@ -10,7 +10,7 @@ import * as tss from 'typescript/lib/tsserverlibrary';
|
||||
|
||||
import {isAstResult} from './common';
|
||||
import {getTemplateCompletions, ngCompletionToTsCompletionEntry} from './completions';
|
||||
import {getDefinitionAndBoundSpan} from './definitions';
|
||||
import {getDefinitionAndBoundSpan, getTsDefinitionAndBoundSpan} from './definitions';
|
||||
import {getDeclarationDiagnostics, getTemplateDiagnostics, ngDiagnosticToTsDiagnostic, uniqueBySpan} from './diagnostics';
|
||||
import {getHover} from './hover';
|
||||
import {Diagnostic, LanguageService} from './types';
|
||||
@ -80,6 +80,15 @@ class LanguageServiceImpl implements LanguageService {
|
||||
if (templateInfo) {
|
||||
return getDefinitionAndBoundSpan(templateInfo, position);
|
||||
}
|
||||
|
||||
// Attempt to get Angular-specific definitions in a TypeScript file, like templates defined
|
||||
// in a `templateUrl` property.
|
||||
if (fileName.endsWith('.ts')) {
|
||||
const sf = this.host.getSourceFile(fileName);
|
||||
if (sf) {
|
||||
return getTsDefinitionAndBoundSpan(sf, position, this.host.host);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getHoverAt(fileName: string, position: number): tss.QuickInfo|undefined {
|
||||
|
Reference in New Issue
Block a user