fix(language-service): Add global symbol for $any() (#33245)

This commit introduces a "global symbol table" in the language service for symbols that are available in the top level scope,
and add `$any()` to it.

See https://angular.io/guide/template-syntax#the-any-type-cast-function

PR closes https://github.com/angular/vscode-ng-language-service/issues/242

PR Close #33245
This commit is contained in:
Keen Yee Liau
2019-10-17 18:42:27 -07:00
committed by Andrew Kushnir
parent 8bc5fb2ab6
commit 3f257e96c6
7 changed files with 139 additions and 3 deletions

View File

@ -13,6 +13,8 @@ import {TypeScriptServiceHost} from '../src/typescript_host';
import {MockTypescriptHost} from './test_utils';
const TEST_TEMPLATE = '/app/test.ng';
describe('hover', () => {
const mockHost = new MockTypescriptHost(['/app/main.ts']);
const tsLS = ts.createLanguageService(mockHost);
@ -190,6 +192,19 @@ describe('hover', () => {
});
expect(toText(displayParts)).toBe('(directive) AppModule.StringModel: class');
});
it('should be able to provide quick info for $any() cast function', () => {
const content = mockHost.override(TEST_TEMPLATE, '<div>{{$any(title)}}</div>');
const position = content.indexOf('$any');
const quickInfo = ngLS.getHoverAt(TEST_TEMPLATE, position);
expect(quickInfo).toBeDefined();
const {textSpan, displayParts} = quickInfo !;
expect(textSpan).toEqual({
start: position,
length: '$any(title)'.length,
});
expect(toText(displayParts)).toBe('(method) $any');
});
});
function toText(displayParts?: ts.SymbolDisplayPart[]): string {