feat(language-service): modularize error messages (#35678)

This commit performs a modularization of the Language Service's existing
diagnostic messages. Such a modularization has two primary advantages:

- Centralization and decoupling of error messages from the code that
  generates them makes it easy to add/delete/edit diagnostic messages,
  and allows for independent iteration of diagnostic messages and
  diagnostic generation.
- Prepares for additional features like annotating the locations where a
  diagnostic is generated and enabling the configuration of which
  diagnostics should be reported by the language service.

Although it would be preferable to place the diagnostics registry in an
independent JSON file, for ease of typing diagnostic types as an enum
variant of 'ts.DiagnosticCategory', the registry is stored as an object.

Part of #32663.

PR Close #35678
This commit is contained in:
ayazhafiz
2020-02-25 08:32:38 -08:00
committed by atscott
parent 8eb4a9d395
commit 47a1811e0b
8 changed files with 268 additions and 101 deletions

View File

@ -85,7 +85,7 @@ describe('diagnostics', () => {
mockHost.override(TEST_TEMPLATE, template);
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
expect(diags.length).toBe(1);
expect(diags[0].messageText).toBe('Unable to resolve signature for call of method $any');
expect(diags[0].messageText).toBe('Unable to resolve signature for call of $any');
}
});
@ -129,7 +129,7 @@ describe('diagnostics', () => {
`);
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
expect(diags.length).toBe(1);
expect(diags[0].messageText).toBe(`Expected the operants to be of similar type or any`);
expect(diags[0].messageText).toBe(`Expected operands to be of similar type or any`);
});
it('should not report errors for matching exported type', () => {
@ -228,7 +228,7 @@ describe('diagnostics', () => {
it('should report numeric operator errors', () => {
const diags = ngLS.getSemanticDiagnostics(EXPRESSION_CASES).map(d => d.messageText);
expect(diags).toContain('Expected a numeric type');
expect(diags).toContain('Expected a number type');
});
});