Commit Graph

26 Commits

Author SHA1 Message Date
ayazhafiz 406419bc0f fix(language-service): fix calculation of pipe spans (#35986)
This commit accomplishes two tasks:

- Fixes the span of queried pipes to only be applied on pipe names
- By consequence, fixes how pipes are located in arguments (previously,
  pipes with arguments could not be found because the span of a pipe
  uses a relative span, while the template position is absolute)

The screenshots attached to the PR for this commit demonstrate the
change.

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

PR Close #35986
2020-03-10 13:26:40 -04:00
ayazhafiz b64ead5cb8 fix(language-service): prune duplicate returned definitions (#34995)
Sometimes, a request for definitions will return multiple of the same
definition. This can happen in at least the cases of

- two-way bindings (one of the same definition for the property and
  event binding)
- multiple template binding expressions in the same attribute
  - something like "*ngFor="let i of items; trackBy: test" has two
    template bindings, resulting in two template binding ASTs at the
    same location (the attribute span). The language service then parses
    both of these bindings individually, resulting in two independent
    but identical definitions. For more context, see https://github.com/angular/angular/pull/34847#discussion_r371006680.

This commit prunes duplicate definitions by signing definitions with
their location, and checking if that location signature has been seen in
a previous definition returned to the client.

PR Close #34995
2020-01-29 12:21:04 -08:00
ivanwonder 09869af90f fix(language-service): remove repeated symbol definitions for structural directive (#34847)
For the structural directive, the 'path' will contain multiple `BoundDirectivePropertyAst` which depends on the number of directive property in the attribute value(e.g. '*ngFor="let item of []; trackBy: test;"', it has 2 `BoundDirectivePropertyAst`, 'ngForOf' and 'ngForTrackBy').

PR Close #34847
2020-01-27 10:47:46 -08:00
ivanwonder e7dff9eb0c feat(language-service): provide hover for microsyntax in structural directive (#34847)
PR Close #34847
2020-01-27 10:47:46 -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
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
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
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 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 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 a391aebbcf feat(language-service): add definitions for styleUrls (#32464)
Adds support for `styleUrls` definitions in the same way `templateUrl`
definitions are provided; clicking on styleUrl will take a user to the
respective file.

Unifies some code in determining a URL definition. We first check if a
url is a `templateUrl`; if it's not, we check that it's a `styleUrl` or
return no definitions.

PR Close #32464
2019-09-09 16:04:14 -04:00
ayazhafiz 1ed3531049 fix(language-service): re-add regressed templateUrl tests (#32438)
Commit 18ce58 (per #32378) regressed tests for templateUrl definitions.
This PR re-adds those tests.

PR Close #32438
2019-09-03 11:59:13 -07:00
Keen Yee Liau 18ce58c2bc refactor(language-service): cleanup tests for Hover (#32378)
Move generic test methods to `MockTypescriptHost` so they could be
shared across all tests.

This is in preparation for adding more tests to Hover when new features
get added.

PR Close #32378
2019-08-28 17:25:07 -07:00
ayazhafiz 46caf88b2c feat(language-service): add definitions for templateUrl (#32238)
Adds support for `getDefinitionAt` when called on a templateUrl
property assignment.

The currrent architecture for getting definitions is designed to be
called on templates, so we have to introduce a new
`getTsDefinitionAndBoundSpan` method to get Angular-specific definitions
in TypeScript files and pass a `readTemplate` closure that will read the
contents of a template using `TypeScriptServiceHost#getTemplates`. We
can probably go in and make this nicer in a future PR, though I'm not
sure what the best architecture should be yet.

Part of angular/vscode-ng-language-service#111

PR Close #32238
2019-08-28 17:09:46 -07:00
Keen Yee Liau a8e2ee1343 fix(language-service): Make Definition and QuickInfo compatible with TS LS (#31972)
Now that the Angular LS is a proper tsserver plugin, it does not make
sense for it to maintain its own language service API.

This is part one of the effort to remove our custom LanguageService
interface.
This interface is cumbersome because we have to do two transformations:
  ng def -> ts def -> lsp definition

The TS LS interface is more comprehensive, so this allows the Angular LS
to return more information.

PR Close #31972
2019-08-08 12:00:56 -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
Ben Lesh eccc41c5cf refactor: using ᐱ instead of Δ in tests (#30338)
This is in preparation to move instructions back to using `Δ` prefix

PR Close #30338
2019-05-08 12:00:25 -07:00
Ben Lesh 138ca5a246 refactor(ivy): prefix all generated instructions (#29692)
- Updates all instructions to be prefixed with the Greek delta symbol

PR Close #29692
2019-04-10 12:11:40 -07:00
Alan c5d9035bab test: fix dts path to the flattened file (#28834)
PR Close #28834
2019-03-06 10:59:18 -08:00
Miško Hevery 540581da3e fix(language-service): Update types for TypeScript nullability support 2017-04-12 11:36:19 -07:00
Jason Aden 3e51a19983 refactor: move angular source to /packages rather than modules/@angular 2017-03-08 16:29:27 -08:00