refactor(language-service): Consistent naming between ts and ng LanguageService (#34888)

This commit makes the Angular Language Service interface a strict subset
of TypeScript's Language Service by renaming all methods to be
consistent with TypeScript's.

The custom Angular `LanguageService` interface was needed before the
inception of TypeScript tsserver plugin, but is now obsolete since
Angular LS is a proper tsserver plugin.

This allows us to easily adapt to upstream TS changes in the future, and
also allows us to reuse all data types defined in TypeScript.

PR Close #34888
This commit is contained in:
Keen Yee Liau
2020-01-21 14:51:43 -08:00
committed by Matias Niemelä
parent 84d24c08e1
commit f723a27a71
8 changed files with 189 additions and 221 deletions

View File

@ -12,7 +12,7 @@ import {getTemplateCompletions} from './completions';
import {getDefinitionAndBoundSpan, getTsDefinitionAndBoundSpan} from './definitions';
import {getDeclarationDiagnostics, getTemplateDiagnostics, ngDiagnosticToTsDiagnostic, uniqueBySpan} from './diagnostics';
import {getHover, getTsHover} from './hover';
import {Diagnostic, LanguageService} from './types';
import * as ng from './types';
import {TypeScriptServiceHost} from './typescript_host';
/**
@ -20,16 +20,16 @@ import {TypeScriptServiceHost} from './typescript_host';
*
* @publicApi
*/
export function createLanguageService(host: TypeScriptServiceHost): LanguageService {
export function createLanguageService(host: TypeScriptServiceHost) {
return new LanguageServiceImpl(host);
}
class LanguageServiceImpl implements LanguageService {
class LanguageServiceImpl implements ng.LanguageService {
constructor(private readonly host: TypeScriptServiceHost) {}
getDiagnostics(fileName: string): tss.Diagnostic[] {
getSemanticDiagnostics(fileName: string): tss.Diagnostic[] {
const analyzedModules = this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
const results: Diagnostic[] = [];
const results: ng.Diagnostic[] = [];
const templates = this.host.getTemplates(fileName);
for (const template of templates) {
@ -48,7 +48,9 @@ class LanguageServiceImpl implements LanguageService {
return uniqueBySpan(results).map(d => ngDiagnosticToTsDiagnostic(d, sourceFile));
}
getCompletionsAt(fileName: string, position: number): tss.CompletionInfo|undefined {
getCompletionsAtPosition(
fileName: string, position: number,
options?: tss.GetCompletionsAtPositionOptions): tss.CompletionInfo|undefined {
this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
const ast = this.host.getTemplateAstAtPosition(fileName, position);
if (!ast) {
@ -67,7 +69,8 @@ class LanguageServiceImpl implements LanguageService {
};
}
getDefinitionAt(fileName: string, position: number): tss.DefinitionInfoAndBoundSpan|undefined {
getDefinitionAndBoundSpan(fileName: string, position: number): tss.DefinitionInfoAndBoundSpan
|undefined {
this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
const templateInfo = this.host.getTemplateAstAtPosition(fileName, position);
if (templateInfo) {
@ -84,7 +87,7 @@ class LanguageServiceImpl implements LanguageService {
}
}
getHoverAt(fileName: string, position: number): tss.QuickInfo|undefined {
getQuickInfoAtPosition(fileName: string, position: number): tss.QuickInfo|undefined {
this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
const templateInfo = this.host.getTemplateAstAtPosition(fileName, position);
if (templateInfo) {