Commit Graph

160 Commits

Author SHA1 Message Date
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
Ayaz Hafiz 1ea04ffc05 feat(language-service): support multiple symbol definitions (#34782)
In Angular, symbol can have multiple definitions (e.g. a two-way
binding). This commit adds support for for multiple definitions for a
queried location in a template.

PR Close #34782
2020-01-23 10:14:19 -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
ayazhafiz 6c8e322fa1 refactor(language-service): cleanup of low-hanging TODOs (#34784)
Cleans up some simple TODOs. Also removes
`typescript_symbols#getTypeWrapper`, which I thought I had but failed to
remove in #34571.

PR Close #34784
2020-01-21 13:09:30 -05:00
ayazhafiz d7ea389c84 feat(language-service): provide completion for $event variable (#34566)
This commit adds a completion for the `$event` variable in bound event
expressions.

This is the first in a series of PRs to support completions for
properties on `$event` variables (https://github.com/angular/vscode-ng-language-service/issues/531).

PR Close #34566
2020-01-14 15:54:02 -08:00
ivanwonder 1a453872c8 fix(language-service): apply suggested change. (#34564)
PR Close #34564
2020-01-14 09:30:27 -08:00
ivanwonder c8c6fd7153 refactor(language-service): test case (#34564)
PR Close #34564
2020-01-14 09:30:27 -08:00
ivanwonder 7005645592 fix(language-service): break the hover/definitions for two-way binding (#34564)
PR Close #34564
2020-01-14 09:30:27 -08:00
ivanwonder 5260021447 feat(language-service): support hover/definitions for structural directive (#34564)
PR Close #34564
2020-01-14 09:30:26 -08: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
Keen Yee Liau 6d28a209e4 test(language-service): Remove test cases from parsing-cases.ts (#34716)
This commit removes some test scenarios from `parsing-cases.ts` and
colocate them with the test code instead. This makes the tests easier to
read and understand.

PR Close #34716
2020-01-10 14:44:24 -08:00
ayazhafiz 794dcb58d3 fix(language-service): do not use an i18n parser for templates (#34531)
The compiler's `I18NHtmlParser` may expand template nodes that have
internationalization metadata attached to them; for instance,

```html
<div i18n="@@i18n-el">{{}}</div>
```

gets expanded to an AST with the i18n metadata extracted and text filled
in as necessary; to the language service, the template above, as read in
the AST, now looks something like

```html
<div>{{$implicit}}</div>
```

This is undesirable for the language service because we want to preserve
the original form of the source template source code, and have
information about the original values of the template. The language
service also does not need to use an i18n parser -- we don't generate
any template output.

To fix this turns out to be as easy as moving to using a raw
`HtmlParser`.

---

A note on the testing strategy: as mentioned above, we don't need to use
an i18n parser, but we don't **not** need to use one if the parser
does not heavily modify the template AST. For this reason, the tests
target the functionality of not modifying a template with i18n metadata
rather than testing that the language service does not use an i18n parser.

---

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

PR Close #34531
2020-01-10 08:23:08 -08:00
ivanwonder 181d766941 feat(language-service): completions support for template reference variables (#34363)
PR Close #34363
2020-01-09 13:45:42 -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
ayazhafiz ee46b9b44f fix(language-service): correctly parse expressions in an attribute (#34517)
Currently, the language service provides completions in a template node
attribute by first checking if the attribute contains template bindings
to provide completions for, and then providing completions for the
expression in the attribute.

In the latter case, the expression AST was being constructed
"synthetically" inside the language service, in particular declaring the
expression to be a `PropertyRead` with an implicit receiver.
Unfortunately, this AST can be incorrect if the expression is actually a
property read on a component property receiver (e.g. when reading
`key` in the expression `obj.key`, `obj` is the receiver).

The fix is pretty simple - rather than a synthetic construction of the
AST, ask the expression parser to parse the expression in the attribute.

Fixes https://github.com/angular/vscode-ng-language-service/issues/523

PR Close #34517
2020-01-06 11:37:21 -08:00
Keen Yee Liau c079f38cbb feat(language-service): Show documentation on hover (#34506)
This commit adds dpcumentation to the hover tooltip.

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

PR Close #34506
2020-01-06 11:36:57 -08:00
ivanwonder ba2fd31e62 fix(language-service): The pipe method should not include parentheses (#34485)
PR Close #34485
2020-01-06 11:31:14 -08:00
Keen Yee Liau 9b9116c79d feat(language-service): Append symbol type to hover tooltip (#34515)
Now that https://github.com/angular/angular/pull/34177 fixed the `TypeWrapper`
to have a proper name, we have the information needed to show the type
name in a hover tooltip.

PR Close #34515
2019-12-20 14:40:04 -08:00
Keen Yee Liau 2dffe65cfd fix(language-service): completions after "let x of |" in ngFor (#34473)
This commit fixes a bug in which we do testing for completions.
Subsequently, this exposes another bug in our implementation whereby
suggestions are not provided in "ngFor" where there should have been.

Currently, multiple test cases are grouped together in a single
template. This requires the template to be somewhat complete so that
test cases that depend on variables declared earlier would pass.

Consider the following example:

```
  template: `
    <div *ngFor="let ~{for-person}person of ~{for-people}people">
      <span>Name: {{~{for-interp-person}person.~{for-interp-name}name}}</span>
      <span>Age: {{person.~{for-interp-age}age}}</span>
    </div>`,
```

In order to test `~{for-interp-person}`, `people` has to be included after
`~{for-people}`. This means the test case for `~{for-people}` is not
reflective of the actual use case because the variable is already there!
In real case, the expression would be incomplete, and our implementation
failed to take that into account.

This commit breaks such test into individual tests, and fix the bugs in
the underlying implementation.

PR Close #34473
2019-12-19 11:34:03 -08:00
Keen Yee Liau a04f7c0d5f fix(language-service): Proper completions for properties and events (#34445)
This commit fixes autocompletions for properties and events bindings.

The language service will no longer provide bindings like (click) or [id].
Instead, it'll infer the context based on the brackets and provide suggestions
without any brackets.

This fix also adds support for alternative binding syntax such as
`bind-`, `on-`, and `bindon`.

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

PR Close #34445
2019-12-18 09:13:31 -08:00
Keen Yee Liau 5df8a3ba95 fix(language-service): HTML path should include last node before cursor (#34440)
Given the following HTML and cursor position:
```
<div c|></div>
      ^ cursor is here
```

Note that the cursor is **after** the attribute `c`.

Under the current implementation, only `Element` is included in the
path. Instead, it should be `Element -> Attribute`.

This bug occurs only for cases where the cursor is right after the Node,
and it is because the `end` position of the span is excluded from the search.
Instead, the `end` position should be included.

PR Close #34440
2019-12-16 14:12:36 -08:00
Keen Yee Liau 5eaab85fc0 fix(language-service): Remove completions for let and of in ngFor (#34434)
`let` and `of` should be considered reserved keywords in template syntax
and thus should not be part of the autocomplete suggestions.

For reference, TypeScript does not provide such completions.

This commit removes these results and cleans up the code.

PR Close #34434
2019-12-16 12:45:38 -08:00
Keen Yee Liau f05e1719cc fix(language-service): Remove getExternalFiles() (#34260)
This commit removes the `getExternalFiles()` from the tsserver plugin.
This API is no longer needed now that we do not intend to support
external templates under the plugin mode.
Instead, the external files are added to the project only when they are
opened by the user.
For complete discussion, see https://github.com/angular/vscode-ng-language-service/issues/473

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

PR Close #34260
2019-12-05 13:13:20 -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 dd944ef73f fix(language-service): Insert parentheses for method completion (#33860)
This commit leverages the `insertText` field in `ts.CompletionEntry` to
return a completion text for class methods that includes parentheses.

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

PR Close #33860
2019-12-03 10:13:36 -08:00
Igor Minar 180a41af68 ci: replace fixme-ivy-aot with no-ivy-aot tag for //packages/language-service/test (#34144)
This target will need to be completely updated once the language service supports Ivy.

PR Close #34144
2019-12-02 11:24:18 -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 592fd37b3e fix(language-service): Provide completions for attribute values (#33839)
This commit fixes a bug whereby completions for attribute values are only
provided for directives that support the micro-syntax format, all other
bindings are ignored.

I'm not sure if this is a regresssion or a bug, because there were no
tests prior to this.

PR Close #33839
2019-11-15 16:13:08 -08:00
Keen Yee Liau cbb1d9f2bb fix(compiler-cli): Refactor getTsTypeFromBuiltinType (#33778)
This commit fixes a few issues with helper method
`getBuiltInTypeFromTsType`.

1. The function is wrongly named. It should be the other way round.
2. The ts.Type returned by the function should not contain any value.
This is because for some data types like Number and String, the
SourceFile (context.node) is not the correct value. Value is never
needed for program correctness in this case.

PR Close #33778
2019-11-15 10:43:41 -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 c5a75fd807 fix(language-service): Recompute analyzed modules only when source files change (#33806)
This commit fixes a bug brought up by @andrius-pra whereby the language
service host would recompute the analyzed modules even when none of the
source files changes. This is due to a bug in our unit test that
precludes non-TS files from incrementing the project version.
Consequently, when the external template is updated, the program remains
the same.

With the bug fixed, the next step is to figure out if any source files
have been added / changed / removed since the last computation. The
previously analyzed could be safely retained only when none of these
operations happen.

PR Close #33806
2019-11-15 10:42:09 -08:00
Keen Yee Liau c365eded5b fix(language-service): Remove getTemplateReferences() from LanguageService API (#33807)
The method `getTemplateReferences()` appears in both the LanguageService
interface and LanguageServiceHost interface. It should belong in the
latter and not the former, since the former deals with the semantics of
the language and not the mechanics.

PR Close #33807
2019-11-15 10:41:51 -08:00
Keen Yee Liau 9935aa43ad refactor(compiler-cli): Move diagnostics files to language service (#33809)
The following files are consumed only by the language service and do not
have to be in compiler-cli:

1. expression_diagnostics.ts
2. expression_type.ts
3. typescript_symbols.ts
4. symbols.ts

PR Close #33809
2019-11-14 09:29:07 -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 31dccab2da test(language-service): Completions test should reuse existing host and services (#33478)
Reusing the single instance of MockHost and language services makes the
tests run much faster.

PR Close #33478
2019-10-30 11:48:49 -07: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
ayazhafiz da4eb91283 feat(language-service): add support for text replacement (#33091)
Adds a `replacementSpan` field on a completion that will allow typed
text to be replaced with the suggested completion value if a user
selects the completion. Previously, the completion value would simply be
appended to the text already typed. E.g. if we had

```
{{ti}}
```

typed in a template and `title` was recommended as a completion and
selected, the template would become

```
{{tititle}}
```

With `replacementSpan`, the original text `ti` will be replaced for
`title`.

PR Close #33091
2019-10-29 11:47:01 -07:00
Keen Yee Liau a78b70178e fix(language-service): Do not show HTML elements and attrs for ext template (#33388)
This commit removes HTML elements and HTML attributes from the
completions list for external template. This is because these
completions should be handled by the native HTML extension, and not
Angular.

Once we setup TextMate grammar for inline templates, we could remove the
HTML completions completely.

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

PR Close #33388
2019-10-25 09:18:16 -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 49eec5d872 fix(language-service): Add directive selectors & banana-in-a-box to completions (#33311)
This commit refactors attribute completions and fixes two bugs:
1. selectors for directives are not provided
2. banana-in-a-box (two way binding) syntax are not provided

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

PR Close #33311
2019-10-23 09:10:39 -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
Suguru Inatomi 7c64b8d3fd feat(language-service): add Angular pseudo elements into completions (#31248)
PR Close #31248
2019-10-18 14:49:12 -04:00