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
b890d10fc6
commit
49d68730f6
@ -89,31 +89,24 @@ describe('hover', () => {
|
||||
});
|
||||
|
||||
it('should be able to find a reference to a component', () => {
|
||||
const fileName = mockHost.addCode(`
|
||||
@Component({
|
||||
template: '«<ᐱtestᐱ-comp></test-comp>»'
|
||||
})
|
||||
export class MyComponent { }`);
|
||||
const marker = mockHost.getDefinitionMarkerFor(fileName, 'test');
|
||||
const quickInfo = ngLS.getQuickInfoAtPosition(fileName, marker.start);
|
||||
expect(quickInfo).toBeTruthy();
|
||||
const {textSpan, displayParts} = quickInfo !;
|
||||
expect(textSpan).toEqual(marker);
|
||||
expect(toText(displayParts)).toBe('(component) AppModule.TestComponent: class');
|
||||
mockHost.override(TEST_TEMPLATE, '<~{cursor}test-comp></test-comp>');
|
||||
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
||||
expect(quickInfo).toBeDefined();
|
||||
const {displayParts, documentation} = quickInfo !;
|
||||
expect(toText(displayParts)).toBe('(component) AppModule.TestComponent: typeof TestComponent');
|
||||
expect(toText(documentation)).toBe('This Component provides the `test-comp` selector.');
|
||||
});
|
||||
|
||||
it('should be able to find a reference to a directive', () => {
|
||||
const fileName = mockHost.addCode(`
|
||||
@Component({
|
||||
template: '<test-comp «string-model»></test-comp>'
|
||||
})
|
||||
export class MyComponent { }`);
|
||||
const marker = mockHost.getReferenceMarkerFor(fileName, 'string-model');
|
||||
const quickInfo = ngLS.getQuickInfoAtPosition(fileName, marker.start);
|
||||
expect(quickInfo).toBeTruthy();
|
||||
const {textSpan, displayParts} = quickInfo !;
|
||||
expect(textSpan).toEqual(marker);
|
||||
expect(toText(displayParts)).toBe('(directive) StringModel: typeof StringModel');
|
||||
const content = mockHost.override(TEST_TEMPLATE, `<div string-model~{cursor}></div>`);
|
||||
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
|
||||
const quickInfo = ngLS.getQuickInfoAtPosition(TEST_TEMPLATE, marker.start);
|
||||
expect(quickInfo).toBeDefined();
|
||||
const {displayParts, textSpan} = quickInfo !;
|
||||
expect(toText(displayParts)).toBe('(directive) AppModule.StringModel: typeof StringModel');
|
||||
expect(content.substring(textSpan.start, textSpan.start + textSpan.length))
|
||||
.toBe('string-model');
|
||||
});
|
||||
|
||||
it('should be able to find an event provider', () => {
|
||||
|
Reference in New Issue
Block a user