refactor(language-service): Avoid leaking host outside of LanguageService (#34941)
As part of the effort to tighten the API surface of `TypeScriptServiceHost` in preparation for the migration to Ivy, I realized some recently added APIs are not strictly needed. They can be safely removed without sacrificing functionality. This allows us to clean up the code, especially in the implementation of QuickInfo, where the `TypeScriptServiceHost` is leaked outside of the `LanguageService` class. This refactoring also cleans up some duplicate code where the QuickInfo object is generated. The logic is now consolidated into a simple `createQuickInfo` method shared across two different implementations. PR Close #34941
This commit is contained in:

committed by
Andrew Kushnir

parent
8926f764a5
commit
3414ef276e
@ -11,7 +11,7 @@ import * as tss from 'typescript/lib/tsserverlibrary';
|
||||
import {getTemplateCompletions} from './completions';
|
||||
import {getDefinitionAndBoundSpan, getTsDefinitionAndBoundSpan} from './definitions';
|
||||
import {getDeclarationDiagnostics, getTemplateDiagnostics, ngDiagnosticToTsDiagnostic, uniqueBySpan} from './diagnostics';
|
||||
import {getHover, getTsHover} from './hover';
|
||||
import {getTemplateHover, getTsHover} from './hover';
|
||||
import * as ng from './types';
|
||||
import {TypeScriptServiceHost} from './typescript_host';
|
||||
|
||||
@ -88,19 +88,15 @@ class LanguageServiceImpl implements ng.LanguageService {
|
||||
}
|
||||
|
||||
getQuickInfoAtPosition(fileName: string, position: number): tss.QuickInfo|undefined {
|
||||
this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
|
||||
const analyzedModules = this.host.getAnalyzedModules(); // same role as 'synchronizeHostData'
|
||||
const templateInfo = this.host.getTemplateAstAtPosition(fileName, position);
|
||||
if (templateInfo) {
|
||||
return getHover(templateInfo, position, this.host);
|
||||
return getTemplateHover(templateInfo, position, analyzedModules);
|
||||
}
|
||||
|
||||
// Attempt to get Angular-specific hover information in a TypeScript file, the NgModule a
|
||||
// directive belongs to.
|
||||
if (fileName.endsWith('.ts')) {
|
||||
const sf = this.host.getSourceFile(fileName);
|
||||
if (sf) {
|
||||
return getTsHover(sf, position, this.host);
|
||||
}
|
||||
}
|
||||
const declarations = this.host.getDeclarations(fileName);
|
||||
return getTsHover(position, declarations, analyzedModules);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user