Commit Graph

241 Commits

Author SHA1 Message Date
Keen Yee Liau 2be0a1d35b refactor(language-service): Colocate getAnalzyedModules and upToDate (#33779)
These two functions go hand-in-hand, putting them together improves
readability.

PR Close #33779
2019-11-12 21:34:52 -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
Greg Magolan 1c22e464b2 build: remove deps on legacy nodejs rules rollup_bundle internals (#33201) (#33607)
The legacy nodejs rules rollup_bundle is now deprecated and will be removed in the nodejs rules 1.0 release due in mid-November. This PR brings in the rules_nodejs internal API deps that ng_rollup_bundle, ng_package and ls_rollup_bundle depend on into this repo to break the dependency. In the future these rules should switch to use the new rollup_bundle via a macro as done in https://github.com/angular/angular/pull/33329 but this is not possible right now due to the complication of having esm5 re-rooted ts_library dependencies.

The es6 sources now have .mjs extensions so they no longer need to be re-rooted to `{package}.es6`. This eliminates the need for the collect_es6_sources() function.

Note: repo has been updated to the newest working version of rollup which is 1.25.2. There is some regression in 1.26.0 which causes the following bundling failure:

```
ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1: Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
Parse error at packages/localize/localize.umd.js:491,4
    export * from './src/constants';
    ^
ERROR: Export statement may only appear at top level
    at js_error (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/parse.js:357:11)
    at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:347:13)
    at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24)
    at AST_Export._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:718:17)
    at walk_body (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:168:17)
    at AST_Function.call (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:430:13)
    at descend (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1208:21)
    at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:256:13)
    at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24)
    at AST_Function._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:424:24)
[Function]
Target //packages/localize:npm_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1 Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped)
```

Will leave that for another day.

Terser also updated to 4.3.3. Updating to 4.3.4 (https://github.com/terser/terser/blob/master/CHANGELOG.md) turns comments preservation on by default which increases the size of the //packages/core/test/bundling/todo:bundle.min.js in CI. After bazelbuild/rules_nodejs#1317 terser can be updated to the latest as passing —comments /a^/ to args can turn off all comments for the //packages/core/test/bundling/todo:bundle.min.js size test.

PR Close #33201

PR Close #33607
2019-11-06 19:56:57 +00:00
Greg Magolan 3de72e4124 revert: build: remove deps on legacy nodejs rules rollup_bundle internals (#33201) (#33604)
This reverts commit 0addaab270.

PR Close #33604
2019-11-05 22:48:33 +00:00
Greg Magolan 0addaab270 build: remove deps on legacy nodejs rules rollup_bundle internals (#33201)
The legacy nodejs rules rollup_bundle is now deprecated and will be removed in the nodejs rules 1.0 release due in mid-November. This PR brings in the rules_nodejs internal API deps that ng_rollup_bundle, ng_package and ls_rollup_bundle depend on into this repo to break the dependency. In the future these rules should switch to use the new rollup_bundle via a macro as done in https://github.com/angular/angular/pull/33329 but this is not possible right now due to the complication of having esm5 re-rooted ts_library dependencies.

The es6 sources now have .mjs extensions so they no longer need to be re-rooted to `{package}.es6`. This eliminates the need for the collect_es6_sources() function.

Note: repo has been updated to the newest working version of rollup which is 1.25.2. There is some regression in 1.26.0 which causes the following bundling failure:

```
ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1: Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
Parse error at packages/localize/localize.umd.js:491,4
    export * from './src/constants';
    ^
ERROR: Export statement may only appear at top level
    at js_error (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/parse.js:357:11)
    at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:347:13)
    at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24)
    at AST_Export._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:718:17)
    at walk_body (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:168:17)
    at AST_Function.call (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:430:13)
    at descend (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1208:21)
    at Dn.visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/scope.js:256:13)
    at Dn._visit (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:1207:24)
    at AST_Function._walk (/private/var/tmp/_bazel_greg/5e8f8a9cd1c6fbc1afd11e37ee1fe2e5/sandbox/darwin-sandbox/79/execroot/angular/bazel-out/host/bin/external/npm/terser/bin/terser.sh.runfiles/npm/node_modules/terser/lib/ast.js:424:24)
[Function]
Target //packages/localize:npm_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /Users/greg/google/angular/packages/localize/BUILD.bazel:20:1 Optimizing JavaScript packages/localize/localize.umd.min.js [terser] failed (Exit 1) terser.sh failed: error executing command bazel-out/host/bin/external/npm/terser/bin/terser.sh bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.js --output bazel-out/darwin-fastbuild/bin/packages/localize/localize.umd.min.js ... (remaining 5 argument(s) skipped)
```

Will leave that for another day.

Terser also updated to 4.3.3. Updating to 4.3.4 (https://github.com/terser/terser/blob/master/CHANGELOG.md) turns comments preservation on by default which increases the size of the //packages/core/test/bundling/todo:bundle.min.js in CI. After bazelbuild/rules_nodejs#1317 terser can be updated to the latest as passing —comments /a^/ to args can turn off all comments for the //packages/core/test/bundling/todo:bundle.min.js size test.

PR Close #33201
2019-11-05 20:55:54 +00: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 c61f413477 refactor(language-service): Simplify ExpressionVisitor in completions.ts (#33391)
This commit simplifies the logic of `ExpressionVisitor` in
`completions.ts`.

Specifically,

1. helper functions `uniqueByName` and `lowerName` are removed.
2. Clean up the logic in visitElement()
3. Reorder constructor params
4. Add methods `addAttributeValuesToCompletions`,
`addKeysToCompletions`, and `addSymbolsToCompletions`.

PR Close #33391
2019-10-28 10:39:42 -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
ayazhafiz ee4fc12e42 refactor(language-service): find expression ASTs using absolute spans (#33387)
Moves to using the absolute span of an expression AST (relative to an
entire template) rather than a relative span (relative to the start
of the expression) to find an expression AST given a position in a
template.

This is part of the changes needed to support text replacement in
templates (#33091).

PR Close #33387
2019-10-24 17:08:23 -07:00
Keen Yee Liau 4c4217c5b7 refactor(language-service): Remove unused function 'createElementCssSelector' (#33383)
It's no longer used and needed.

PR Close #33383
2019-10-24 14:10:47 -07:00
Keen Yee Liau 93a0b1ba13 refactor(language-service): Remove AttrInfo interface (#33380)
It's no longer used and needed.

PR Close #33380
2019-10-24 14:10:14 -07:00
Keen Yee Liau 73530a9e25 refactor(language-service): Create ng.CompletionEntry to replace ts.CompletionEntry (#33379)
It is messy to keep casting `CompletionEntry.kind` from
`ng.CompletionKind` to `ts.ScriptElementKind`.

Instead, create a new type `ng.CompletionEntry` that is exactly the same
as `ts.CompletionEntry`, but with the `kind` type overridden to
`ng.CompletionKind`.

This way, we only have to cast it once, and can do so in a safe manner.

PR Close #33379
2019-10-24 14:09:33 -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 e0059c7d51 refactor: format files (#31248)
PR Close #31248
2019-10-18 14:49:12 -04:00
Suguru Inatomi e122d27176 refactor: fix by beedback (#31248)
PR Close #31248
2019-10-18 14:49:12 -04:00
Suguru Inatomi bab740d793 refactor: format files (#31248)
PR Close #31248
2019-10-18 14:49:12 -04:00
Suguru Inatomi 60e4490808 refactor: fix by feedback (#31248)
PR Close #31248
2019-10-18 14:49:12 -04:00
Suguru Inatomi 251a512222 refactor: create CompletionKind.PSEUDO_ELEMENT (#31248)
PR Close #31248
2019-10-18 14:49:12 -04:00
Suguru Inatomi 692535a935 refactor: make pseudo elements array readonly (#31248)
PR Close #31248
2019-10-18 14:49:12 -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
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
ayazhafiz d2222541e8 refactor(language-service): use strict comparisons (#33114)
PR Close #33114
2019-10-17 21:19:02 -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 43241a560a fix(language-service): Increase project/script version in MockHost.reset() (#33200)
PR Close #33200
2019-10-16 17:49:55 -04:00
Keen Yee Liau 67c914819a test(language-service): Move completions test to completions_spec.ts (#33159)
There are many specs in `ts_plugin_spec.ts` that exercise the behavior
of completions. These specs should belong in `completions_spec` instead.

In addition,

1. Tests for `getExternalFiles()` added in `ts_plugin_spec.ts`
2. Fixed bug in MockHost.reset() to remove overriden script names
3. Add test for TS diagnostics when `angularOnly = true` is not set

PR Close #33159
2019-10-16 10:23:45 -04:00
ayazhafiz ce7f934c66 feat(language-service): directive info when looking up attribute's symbol (#33127)
Now, hovering over an attribute on an element will provide information
about the directive that attribute matches in the element, if any.
(More generally, we return information about directive symbols
matched on an element attribute.)

I believe this is similar to how the indexer provides this kind of
information, though more precise in the sense that this commit provides
directive information only if the directive selector exactly matches the
attribute selector. In another sense, this is a limitation.

In fact, there are the limitations of:

- Directives matched on the element, but with a selector of anything
  more than the attribute (e.g. `div[string-model]` or
  `[string-model][other-attr]`) will not be returned as symbols matching
  on the attribute.
- Only one symbol can be returned currently. If the attribute matches
  multiple directives, only one directive symbol will be returned.
  Furthermore, we cannot say that the directive symbol returned is
  determinstic.

Resolution of these limitations can be discussed in the future. At least
the second limitation should be very easy to fixup in a future commit.

This relies solely on the template compiler and is agnostic to any Ivy
changes, so this is strictly a feature enhancement that will not have to
be refactored when we migrate the language service to Ivy.

PR Close #33127
2019-10-15 16:49:18 +00:00
Keen Yee Liau 64aae3a9df test(language-service): test project cleanup (#33157)
This PR adds es2015 lib to the `tsconfig.json` of the test project so
that `Promise` could be used. Note this only affects diagnostics in the
IDE. The tsconfig in Language Service Mock Host is the actual config
values used, and it already has es2015 lib.

- Other minor cleanup: Rename imports in `main.ts`.
- Add more cases to `parsing-cases.ts`, which are tested in later PRs

PR Close #33157
2019-10-14 23:42:53 +00: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
ayazhafiz e409ed0eab feat(language-service): hover information for component NgModules (#33118)
Enables providing information about the NgModule a component is in when
its selector is hovered on in a template. Also enables differentiation
of a component and a directive when a directive class name is hovered
over in a TypeScript file.

Next step is to enable hover information for directives.

Part of #32565.

PR Close #33118
2019-10-14 20:28:06 +00:00
Andrius 39587ad127 fix(compiler-cli): resolve type of exported *ngIf variable. (#33016)
Currently, method `getVarDeclarations()` does not try to resolve the type of
exported variable from *ngIf directive. It always returns `any` type.
By resolving the real type of exported variable, it is now possible to use this
type information in language service and provide completions, go to definition
and quick info functionality in expressions that use exported variable.
Also language service will provide more accurate diagnostic errors during
development.

PR Close #33016
2019-10-14 20:24:43 +00:00
Ayaz Hafiz b04488d692 feat(compiler): record absolute span of template expressions in parser (#31897)
Currently, the spans of expressions are recorded only relative to the
template node that they reside in, not their source file.

Introduce a `sourceSpan` property on expression ASTs that records the
location of an expression relative to the entire source code file that
it is in. This may allow for reducing duplication of effort in
ngtsc/typecheck/src/diagnostics later on as well.

Child of #31898

PR Close #31897
2019-10-14 20:14:16 +00:00
Keen Yee Liau 4acf0a09ac test(language-service): Remove non-deterministic test (#33120)
A few specs in `completions_spec.ts` are non-deterministic and do not provide much value to test a specific behavior of language service.
Besides that, they are also slow to run.

PR Close #33120
2019-10-14 16:25:28 +00:00
Keen Yee Liau 84ba1f012e test(language-service): Remove redundant marker methods in MockHost (#33115)
Remove the following methods from MockHost:

1. `getMarkerLocations`: Replaced with `getLocationMarkerFor()`
2. `getReferenceMarkers`: Replaced with `getReferenceMarkerFor()`

PR Close #33115
2019-10-14 16:20:55 +00:00
Keen Yee Liau 728cd8446f fix(language-service): Use index.d.ts for typings (#33043)
The current `typings` value in `package.json` causes the import of
`@angular/language-service` in TypeScript to be generated as

```
const language_service_1 = require("@angular/language-service/language-service");
```
in CJS output.

This breaks the import shim that overwrites the behavior of `require` at
runtime. Changing the typings to `index.d.ts` fixes the issue.

PR Close #33043
2019-10-10 13:58:57 -07:00
Keen Yee Liau adb562bca6 fix(language-service): create StaticReflector once only (#32543)
The creation of StaticReflector in createMetadataResolver() is a very expensive operation because it involves numerous module resolutions.
To make matter worse, since the API of the Reflector does not provide the ability to invalidate its internal caches, it has to be destroyed and recreated on *every* program change.
This has a HUGE impact on performance.
This PR fixes this problem by carefully invalidating all StaticSymbols in a file that has changed, thereby reducing the overhead of recomputation on program change.

PR Close #32543
2019-10-03 15:02:03 -07:00
ayazhafiz 0d186dda35 feat(language-service): module definitions on directive hover (#32763)
Adds information about the NgModule a Directive is declared in when the
Directive class name is hovered over, in the form

```
(directive) NgModule.Directive: class
```

Closes #32565

PR Close #32763
2019-10-02 13:26:30 -07:00
ayazhafiz 01e4d44e8c fix(language-service): add closing quote in invalid test template (#32785)
Fixes an invalid TypeScript code in the language service tests. I must
have missed this while reviewing previously; sorry about that!

PR Close #32785
2019-10-01 14:57:45 -07:00
ayazhafiz 98feee7e0e feat(language-service): allow retreiving synchronized analyzed NgModules (#32779)
Sometimes modules retreived from the language service need to be
synchronized to the last time they were updated, and not updated
on-the-fly. This PR adds a flag to
`TypeScriptServiceHost#getAnalyzedModules` that retreives cached
analyzed NgModules rather than potentially recomputing them.

PR Close #32779
2019-10-01 11:02:09 -07: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
Keen Yee Liau 9d8dc793da test(language-service): Create proper test project (#32653)
Language service uses a canonical "Tour of Heroes" project to test
various features, but the files are all contained in test_data.ts which
is hard to read and often contains errors that are difficult to catch
without proper IDE syntax highlighting. The directory structure is also
not clear from first glance.

This PR refactors the test project into standalone files in the proper
format.

Next up:
[ ] Update the interface of MockTypeScript to only accept scriptNames.
[ ] Remove test_data.ts

PR Close #32653
2019-09-18 13:07:01 -07:00
ayazhafiz 2846505dbd feat(language-service): expose determining the NgModule of a Directive (#32710)
This sets up the Language Service to support #32565.
This PR exposes a `getDirectiveModule` method on `TypeScriptServiceHost`
that returns the NgModule owning a Directive given the Directive's
TypeScript node or its Angular `StaticSymbol`. Both types are supported
to reduce extraneous helper methods.

PR Close #32710
2019-09-18 12:59:35 -07:00