Commit Graph

56 Commits

Author SHA1 Message Date
ayazhafiz e7c74cbd69 feat(language-service): completions for output $event properties in (#34570)
This commit adds support for completions of properties on `$event`
variables in bound outputs.

This is the second major PR to support completions for `$event`
variables (https://github.com/angular/vscode-ng-language-service/issues/531).
The final completion support that must be provided is for `$event`
variables in bindings targeting DOM events, like `(click)`.

PR Close #34570
2020-01-28 09:07:43 -08:00
Keen Yee Liau 0223aa6121 fix(language-service): Diagnostic span should point to class name (#34932)
Right now, if an Angular diagnostic is generated for a TypeScript node,
the span points to the decorator Identifier, i.e. the Identifier node
like `@NgModule`, `@Component`, etc.
This is weird. It should point to the class name instead.
Note, we do not have a more fine-grained breakdown of the span when
diagnostics are emitted, this work remains to be done.

PR Close #34932
2020-01-23 15:55:44 -08:00
ayazhafiz 4ba478267e feat(language-service): specific suggestions for template context diags (#34751)
This commit elaborates diagnostics produced for invalid template
contexts by including the name of the embedded template type using the
template context, and in the common case that the implicity property is
being referenced (e.g. in a `for .. of ..` expression), suggesting to
refine the type of the context. This suggestion is provided because
users will sometimes use a base class as the type of the context in the
embedded view, and a more specific context later on (e.g. in an
`ngOnChanges` method).

Closes https://github.com/angular/vscode-ng-language-service/issues/251

PR Close #34751
2020-01-23 12:25:42 -08:00
ayazhafiz 68025ce09a test(language-service): recognize inputs/ouputs declared in decorator (#34875)
This commit adds a regression test to check that the language service
recognizes inputs and outputs declared in a directive decorator.

See #34874.

PR Close #34875
2020-01-23 10:15:12 -08:00
Keen Yee Liau f723a27a71 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
2020-01-22 14:36:04 -05:00
Keen Yee Liau bfe9bc912a fix(language-service): CRLF offset in inline template (#34737)
This commit fixes incorrect CRLF offsets in inline template.

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

PR Close #34737
2020-01-13 07:16:50 -08:00
ayazhafiz 443e423b58 test(language-service): make app.component a constant (#34587)
Cleans up usages of `app.component.ts` to be a constant file variable.

PR Close #34587
2020-01-09 13:31:39 -08:00
ivanwonder 7a86a32040 fix(language-service): apply suggestion (#34177)
PR Close #34177
2019-12-05 13:12:44 -08:00
ivanwonder 2ebaa51514 fix(language-service): bug of accessing a string index signature using dot notation (#34177)
PR Close #34177
2019-12-05 13:12:44 -08:00
Keen Yee Liau 39722df41e fix(language-service): Do not produce diagnostics if metadata for NgModule not found (#34113)
The language service incorrectly reports an error if it fails to find
NgModule metadata for a particular Component / Directive. In many cases,
the use case is legit, particularly in test.

This commit removes such diagnostic message and cleans up the interface
for `TypeScriptHost.getTemplateAst()`.

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

PR Close #34113
2019-12-02 11:13:41 -08:00
ayazhafiz 1425e63029 fix(language-service): determine correct type for ngFor exported values (#34089)
Currently, variables of an unknown type in an `*ngFor` expression are
refined to have the type of the iterable binding of the `*ngFor`
expression. Unfortunately, this is a bug for variables aliasing
[values exported by
`*ngFor`](https://angular.io/api/common/NgForOf#local-variables),
including `index` and `first`, because they are also given the type of
the binding expression, but they are not of the binding type. For
example, in

```typescript
@Component({
  selector: 'test',
  template: `
    <div *ngFor="let hero of heroes; let i = index; let isFirst = first">
      {{ hero }}
    </div>
  `
})
export class TestComponent {
  heroes: Hero[];
}
```

The local variables `i` and `isFirst` are determined to have a type of
`Hero`, when actually their types are `number` and `boolean`,
respectively.

This commit fixes this bug by checking if the value of a variable in an
`*ngFor` expression is known to be an export and assigning the variable
the type of that export value. Only if the variable does not alias an
export is it typed with the binding value of the `*ngFor` expression.

Closes https://github.com/angular/vscode-ng-language-service/issues/460

PR Close #34089
2019-12-02 11:03:34 -08:00
ivanwonder c5006e025f fix(language-service): fix error of array-index out of bounds exception (#33928)
PR Close #33928
2019-11-27 12:48:41 -08:00
ivanwonder 5a227d8d7c feat(language-service): completions support for tuple array (#33928)
PR Close #33928
2019-11-27 12:48:41 -08:00
ayazhafiz 49804fe017 fix(language-service): determine index types accessed using dot notation (#33884)
Commit 53fc2ed8bf added support for
determining index types accessed using index signatures, but did not
include support for index types accessed using dot notation:

```typescript
const obj<T>: { [key: string]: T };
obj['stringKey']. // gets `T.` completions
obj.stringKey.    // did not peviously get `T.` completions
```

This adds support for determining an index type accessed via dot
notation by rigging an object's symbol table to return the string index
signature type a property access refers to, if that property does not
explicitly exist on the object. This is very similar to @ivanwonder's
work in #29811.

`SymbolWrapper` now takes an additional parameter to explicitly set the
type of the symbol wrapped. This is done because
`SymbolTableWrapper#get` only has access to the symbol of the index
type, _not_ the index signature symbol itself. An attempt to get the
type of the index type will give an error.

Closes #29811
Closes https://github.com/angular/vscode-ng-language-service/issues/126

PR Close #33884
2019-11-26 15:57:07 -08:00
Keen Yee Liau 7cd16b9e2c fix(language-service): function.bind() should not be an error (#34041)
When performing diagnostic checks or completions, we should take into
account members and properties in the base class, if any. Otherwise, the
language service will produce a false error.

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

PR Close #34041
2019-11-25 21:20:56 -05:00
ayazhafiz 53fc2ed8bf feat(language-service): completions support for indexed types (#33775)
Previously, indexing a container type would not return completions for
the indexed type because for every TypeScript type, the recorded index
type was always marked as `undefined`, regardless of the index
signature.

This PR now returns the index type of TypeScript containers with numeric
or string index signatures. This allows use to generate completions for
arrays and defined index types:

```typescript
interface Container<T> {
  [key: string]: T;
}
const ctr: Container<T>;
ctr['stringKey']. // gives `T.` completions

const arr: T[];
arr[0]. // gives `T.` completions
```

Note that this does _not_ provide completions for properties indexed by
string literals, e.g.

```typescript
interface Container<T> {
  foo: T;
}
const ctr: Container<T>;
ctr['foo']. // does not give `T.` completions
```

Closes angular/vscode-ng-language-service#110
Closes angular/vscode-ng-language-service#277

PR Close #33775
2019-11-15 16:16:06 -08:00
Keen Yee Liau 1d3aae6f92 fix(language-service): Function alias should be callable (#33782)
This commit fixes a long standing bug whereby a template variable that
gets initialized to a class method gets resolved to the Any type, thus
when it is called the language service produces error "Member X is not
callable".

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

PR Close #33782
2019-11-15 10:43:18 -08:00
Keen Yee Liau 8b91ea5532 fix(language-service): Resolve template variable in nested ngFor (#33676)
This commit fixes a bug whereby template variables in nested scope are
not resolved properly and instead are simply typed as `any`.

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

PR Close #33676
2019-11-11 16:06:00 -08:00
Keen Yee Liau 9ebac71521 fix(language-service): Should not crash if expr ends unexpectedly (#33524)
If there is any parser errors when parsing template, we should stop
immediately and not proceed with template expression diagnostics.

This regression is caused by 6d11154652
and affected v9.0.0-next.4 onwards.

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

PR Close #33524
2019-11-01 17:37:48 +00:00
Keen Yee Liau 1de757993d fix(language-service): Improve signature selection for pipes with args (#33456)
Pipes with arguments like `slice:0` or `slice:0:1` should not produce
diagnostic errors.

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

PR Close #33456
2019-10-29 14:40:35 -07:00
Keen Yee Liau 3f257e96c6 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
2019-10-23 10:02:50 -07:00
Keen Yee Liau 65a0d2b53d fix(language-service): Preserve CRLF in templates for language-service (#33241)
This is a potential fix for https://github.com/angular/vscode-ng-language-service/issues/235
suggested by @andrius-pra in
47696136e3.

Currently, CRLF line endings are converted to LFs and this causes the
diagnostics span to be off in templates that use CRLF. The line endings
must be preserved in order to maintain correct span offset. The solution
is to add an option to the Tokenizer to indicate such preservation.

PR Close #33241
2019-10-22 13:29:23 -04:00
Igor Minar 86e1e6c082 feat: typescript 3.6 support (#32946)
BREAKING CHANGE: typescript 3.4 and 3.5 are no longer supported, please update to typescript 3.6

Fixes #32380

PR Close #32946
2019-10-18 13:15:16 -04:00
Keen Yee Liau 11bf7679a1 fix(language-service): reset MockHost after every spec instead of creating new LS (#33200)
This commit speeds up the tests by calling `MockHost.reset()` in
`beforeEach()` instead of destroying the entire language service and
creating a new one. The creation of a new language service instance is
expensive due to the need to initialize many core Symbols when creating
a new program.

This speeds ups the test (on my local machine) from 35 secs to 15 secs.

PR Close #33200
2019-10-16 17:49:55 -04:00
Keen Yee Liau 4c0726db9c test(language-service): Move diagnostics tests to diagnostics_spec.ts (#33158)
This commit moves diagnostic specs in `ts_plugin_spec.ts` to
`diagnostics_spec.ts`.

PR Close #33158
2019-10-14 23:40:20 +00:00
Keen Yee Liau 28358b6395 fix(language-service): Turn on strict mode for test project (#32783)
This is the last part in refactoring of the test project.
This PR turns on strict mode for typechecking and fixed tests that
fail under this mode.

PR Close #32783
2019-10-01 11:01:01 -07:00
Keen Yee Liau 53b32f17b3 test(language-service): Remove MockTypescriptHost.readFileContent() (#32782)
readFileContent() has the exact same functionality as readFile(), but it
is not actually part of ts.LanguageServiceHost interface.
It's not actually needed, so replace it with readFile() instead.

PR Close #32782
2019-09-30 14:16:03 -07:00
Keen Yee Liau f3859ff2b9 test(language-service): remove MockData from MockTypescriptHost (#32752)
Remove MockData from the constructor parameters of MockTypescriptHost
since the entire Tour of Heroes (TOH) project is now loaded from disk.

Added a new method `reset()` to MockTypescriptHost that is necessary to
reset the state of the project before each spec if run to make sure
previous overrides are cleared.

PR Close #32752
2019-09-18 15:29:25 -07:00
Keen Yee Liau 708ae4c8ef fix(language-service): Fix failing tests after merge (#32758)
https://github.com/angular/angular/pull/32653 and
https://github.com/angular/angular/pull/32592 created a conflict in test
that caused CI to turn red. This PR fixes the failing tests.

PR Close #32758
2019-09-18 14:37:36 -07:00
ayazhafiz 5ace90f04d test(language-service): add missing tests for templateUrls (#32592)
Add missing tests for duplicate, missing template diagnostics

PR Close #32592
2019-09-18 13:35:53 -07:00
ayazhafiz 4c168ed9ba feat(language-service): provide diagnostics for invalid styleUrls (#32674)
Similar to diagnostics for invalid templateUrls, check that styleUrls
actually point to a valid Url.

Closes #32564.

PR Close #32674
2019-09-17 13:38:37 -07:00
ayazhafiz adeee0fa7f feat(language-service): provide diagnostic for invalid templateUrls (#32586)
`templateUrls` that do not point to actual files are now diagnosed as such
by the Language Service. Support for `styleUrls` will come in a next PR.

This introduces a utility method `getPropertyValueOfType` that scans
TypeScript ASTs until a property assignment whose initializer of a
certain type is found. This PR also notices a couple of things that
could be improved in the language-service implementation, such as
enumerating directive properties and unifying common logic, that will be
fixed in future PRs.

Part of #32564.

PR Close #32586
2019-09-12 11:47:44 -07:00
ayazhafiz d30cd3309b refactor(language-service): move to using mockHost as much as possible (#32589)
Update tests that still do not use `mockHost` for certain operations,
like `addCode`.

PR Close #32589
2019-09-11 19:27:27 -04:00
Keen Yee Liau 5c94833b8f test(language-service): Add test for CRLF line endings (#32245)
This commit adds a no-op test for exposing the bug in the way language
service handles CRLF line endings in templates.
There is no easy fix for now, but the test should be enabled once a fix
is in place.

PR Close #32245
2019-08-21 15:21:09 -07:00
Keen Yee Liau 5f76de1d71 test(language-service): Fix diagnostic tests (#32161)
This commit fixes many diagnostic tests have have incorrect/uncaught assertions.
Also added more assertions to make sure TS diagnostics are clear.
A few test util methods are removed to reduce clutter and improve readability.

PR Close #32161
2019-08-16 15:26:05 -07:00
Keen Yee Liau 9808d91c62 refactor(language-service): Cleanup TypescriptHost (#32017)
Cleanup the logic in TypeScriptHost as to when langauge service state
should be synchronized with the editor state.

The model employed follows that of tsserver, in which case it is the
caller's responsiblity to synchronize host data before any LS methods
are called.

PR Close #32017
2019-08-14 11:57:48 -07:00
Keen Yee Liau a5f39aeda6 refactor(language-service): Return ts.Diagnostic[] for getDiagnostics (#32115)
Part 2/3 of language service refactoring:
Now that the language service is a proper tsserver plugin, all LS
interfaces should return TS values. This PR refactors the
ng.getDiagnostics() API to return ts.Diagnostic[] instead of
ng.Diagnostic[].

PR Close #32115
2019-08-13 11:20:27 -07:00
Keen Yee Liau 4ec50811d4 refactor(language-service): Remove NgLSHost -> NgLS dependency (#31122)
```
NgLSHost: AngularLanguageServiceHost
NgLS: AngularLanguageService
```

NgLSHost should not depend on NgLS, because it introduces circular
dependency.
Instead, the `getTemplateAst` and `getTemplatAstAtPosition` methods should
be moved to NgLSHost and exposed as public methods.
This removes the circular dependency, and also removes the need for the
awkward 'setSite' method in NgLSHost.

PR Close #31122
2019-06-19 15:19:56 -07:00
Alan fd7dd4d9fc refactor: clean up language service from unused code and imports (#30534)
PR Close #30534
2019-05-17 13:32:06 -07:00
Keen Yee Liau 2c9b6c0c1f fix(compiler-cli): create LiteralLikeNode for String and Number literal (#27536)
Typescript 3.2 introduced BigInt type, and consequently the
implementation for checkExpressionWorker() in checkers.ts is refactored.

For NumberLiteral and StringLiteral types, 'text' filed must be present
in the Node type, therefore they must be LiteralLikeNode instead of
Node.

PR Close #27536
2018-12-18 13:20:01 -08:00
George Kalpakas 787c54736c test: run unit tests in random order (#19904)
PR Close #19904
2018-07-06 13:48:02 -07:00
Keen Yee Liau 43e1520260 fix(language-service): Clear caches when program changes (#21337)
This commit fixes a bug whereby the caches are not cleared when the
program changes. This subsequently produces the incorrect error of
'Component ... is not included in a module ...'.

PR Close #19405

PR Close #21337
2018-01-12 14:43:01 -08:00
Keen Yee Liau 3203069d6c fix(language-service): Allow empty templates (#20651)
Fixes the bug where templates with empty strings show up as error in the editor.

PR Close #19406

PR Close #20651
2017-11-29 16:52:55 -06:00
Chuck Jazdzewski 8ecda94899 feat(compiler-cli): improve error messages produced during structural errors (#20459)
The errors produced when error were encountered while interpreting the
content of a directive was often incomprehencible. With this change
these kind of error messages should be easier to understand and diagnose.

PR Close #20459
2017-11-27 16:59:57 -06:00
Chuck Jazdzewski c1b029a413 fix(language-service): do not report errors for `OpaqueToken` (#19427)
`OpaqueToken` was removed from angular but the language-service
should not report errors when it is used for older versions of
angular.
2017-09-28 09:30:34 -07:00
Chuck Jazdzewski f194f18dbd fix(language-service): infer `any` `ngForOf` of type `any`
Fixes: #17611
2017-06-20 12:04:51 -07:00
Miško Hevery 5293794316 fix: turn on nullability in the code base. 2017-04-18 12:07:33 -07:00
Chuck Jazdzewski f21ff904c2 fix(language-service): respect baseUrl compiler option
Fixes #15974
2017-04-17 14:36:49 -07:00
Chuck Jazdzewski 0a3a9afe58 fix(language-service): infer correct type of `?.` expressions
Fixes #15885
2017-04-17 09:48:52 -07:00
Miško Hevery 540581da3e fix(language-service): Update types for TypeScript nullability support 2017-04-12 11:36:19 -07:00