Commit Graph

293 Commits

Author SHA1 Message Date
Greg Magolan 93c2df23bf build: upgrade to rules_nodejs 1.0.0 (first stable release) (#34736)
Brings in the fix for stamping which was preventing many targets from getting cached.

PR Close #34736
2020-01-15 14:58:07 -05:00
Andrius 1f79e624d1 build: typescript 3.7 support (#33717)
This PR updates TypeScript version to 3.7 while retaining compatibility with TS3.6.

PR Close #33717
2020-01-14 16:42:21 -08: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
Keen Yee Liau 84c659e246 refactor(language-service): Construct proper template AST from HTML ast (#34764)
The Template AST that corresponds to a given HTML AST is not always
complete, and often has to be reconstructed. This commit refactors the
code to make it easier to adapt to multiple cases.

PR Close #34764
2020-01-14 13:32:58 -08:00
ivanwonder 1a453872c8 fix(language-service): apply suggested change. (#34564)
PR Close #34564
2020-01-14 09:30:27 -08:00
ivanwonder 6f916c1240 fix(language-service): only visit directives (#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
ayazhafiz 7325053dfa refactor(language-service): adds Symbol#typeArguments and does cleanup (#34571)
Adds a `typeArguments` method to the `Symbol` interface, cleaning up how
type parameters of a TypeScript type are currently found. This will be
necessary for providing completions for `$event` variables' properties
(#34570).

This commit also performs some fly-by cleanups seen while implementing
the `typeArguments` methods. There is more clean up to do in the
`typescript_symbols` file, but the scope of this commit didn't need to
get larger.

PR Close #34571
2020-01-13 15:16:15 -08:00
ayazhafiz 15b4173a76 refactor(language-service): create attr for missing attr, bound tmpl (#34743)
Currently the language service constructs an `AttrAst` anytime it is
missing from a `TemplateAst` path. However, this should only be done
when the path does not contain an "attribute-like" AST, which can
includes bound properties or bound events.

This commit also refactors `visitAttr` to parse bindings only for
microsyntax expressions and does some other minor cleanup to make
linters happy.

This is some cleanup to help the language service eventually use
`BoundDirectivePropertyAst`s for providing completions for template
bindings rather than performing the manual parsing currently done.

PR Close #34743
2020-01-13 15:04:37 -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
atscott e88d652f2a Revert "build: upgrade to rules_nodejs 1.0.0 (first stable release) (#34589)" (#34730)
This reverts commit cb6ffa1211.

PR Close #34730
2020-01-10 14:12:15 -08:00
Greg Magolan cb6ffa1211 build: upgrade to rules_nodejs 1.0.0 (first stable release) (#34589)
Brings in the fix for stamping which was preventing many targets from getting cached.

PR Close #34589
2020-01-10 08:31:58 -08:00
ayazhafiz 4d95c3d39a refactor(language-service): rename expression completions method (#34518)
This commit renames `addAttributeValuesToCompletions`, which generates
expression completions and is not exclusive to processing attributes, to
`processExpressionCompletions`. Also removes the expression completion
logic in `visitBoundText` for a call to `processExpressionCompletions`.

The conditional branch in `visitBoundText` is also removed. This branch
was added in one of the first commits to the language service
(519a324454) and appears to be
unnecessary, as the expression AST is constructed from the template
position anyway.

PR Close #34518
2020-01-10 08:31:09 -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 1eae7c81e9 refactor(language-service): Append missing AttrAst to AstPath (#34459)
When a HTML Ast containing an Attribute node is converted to a Template Ast,
the attribute node might get dropped from the Template Ast path.
This is because the AttrNode is not even in the Template Ast to begin with.
In this case, we manually fix the path by converting the Attribute node
to a AttrAst node and appending it to the path.

This allows the `ExpressionVisitor` to properly visit the leaf node in the
TemplateAst path. We no longer need to visit the `Element` and look for
attributes.

PR Close #34459
2019-12-18 09:14:16 -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 613dc1122a fix(language-service): Simplify resolution logic in banner (#34262)
Due to a bug in the existing banner, `typescript` module was require-d
instead of reusing the module passed in from tsserver.
This bug is caused by some source files in language-service that imports
`typescript` instead of `typescript/lib/tsserverlibrary`.
This is not an unsupported use case, it's just that when typescript is
resolved in the banner we have to be very careful about which modules to
"require".
The convoluted logic in the banner makes it very hard to detect
anomalies. This commit cleans it up and removes a lot of unneeded code.

This commit also removes `ts` import in typescript_host.ts and use `tss`
instead to make it less confusing.

PR Close #34262
2019-12-06 10:27:30 -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 a91ca99b1f refactor(language-service): refactor the method TypeWrapper.name and PipeSymbol.selectSignature (#34177)
PR Close #34177
2019-12-05 13:12:44 -08:00
ivanwonder 7a86a32040 fix(language-service): apply suggestion (#34177)
PR Close #34177
2019-12-05 13:12:44 -08:00
ivanwonder 148a060daa fix(language-service): return the js primitive type name (#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 7eccbcd30d fix(language-service): Make missing module suggestion instead of error (#34115)
If a Component or Directive is not part of any NgModule, the language
service currently produces an error message. This should not be an
error. Instead, it should be a suggestion.

This PR removes `ng.DiagnosticKind`, and instead reuses
`ts.DiagnosticCategory`.

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

PR Close #34115
2019-12-02 11:19:40 -08:00
Keen Yee Liau 99320e1ffc fix(language-service): use host.error() instead of console.error() (#34114)
`host.error()` would log to file, and makes error messages much easier
to inspect because entries are time-stamped.

PR Close #34114
2019-12-02 11:14:08 -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