-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript extensibility #6508
Comments
@billti your demo is very impressive! I tell me if your work could take care of HTML file too. You provide HTML, Angular completion for @Component/template, but what about @Component/templateUrl ? I mean:
<h1[style. // here Ctrl+Space shows FontFamily
@Component({
templateUrl: " // here Ctrl+Space shows person.html
}) |
This is partly the first bullet under challenges above, namely that we can't just assume any With a unique extension that we know definitely is an Angular2 template, then editors could automatically apply the correct grammar (i.e. TextMate bundle in the case of Sublime or VSCode), and load the correct language service (and provide intellisense in the areas you outline above). |
@billti if I have understood your comments, the challenge is to detect if an HTML file *.html is an angular template or not? For me this information is about the project nature. This nature could be detect :
With *.ngml it fixes the problem with project nature, but not the full scan of typescript files to retrieve the well class which defines @Component/templateUrl I'm a little afraid with this case for performance problem to have to scan the full typescript files. Or perhaps I have not understood something? |
That'd be awesome! |
@angelozerr That's half the battle. The challenge is more of a catch-22, and is something like "how do I detect if I need to load the language service, without loading the language service to do the detection logic". For performance reasons many editors do not load the language service unless needed. Currently, an .html document never needs the TypeScript language service, thus it is rarely - if ever - loaded when opening an HTML document. Assuming the above logic would live in the TypeScript (or one of its plugin's) code, then you would need to load the TypeScript language service on every HTML document you open to detect if it is an Angular template. Does that make sense? Maybe that's a trade off we'll have to make. It's just not one to take lightly. |
@billti How much of the detection code needs to be baked into the full-fledged language service? Would it be possible to build a service whose sole purpose is to detect what a file is, but not do anything with it? It could share source with the language service, but it would be a smaller process with an otherwise smaller source base. |
👍 |
Seriously cool feature - looking forward to having something like that! |
I had the similar problem with AngularJS Eclipse based on ternjs. The load of ternjs is done as soon as an HTML editor is opened but only if project contains a .tern-project (you could compare this file to tsconfig.json) which declare angular2 (you could do that by checking that package.json contains angular2) I would like to know too if you could provide too custom tsserver commands to retrieve list of Angular2 components of a project to provide for instance:
|
@billti the last weekend I spend in prototyping a static code analyzer for Angular projects. It seems somehow related to the results you got. I wrote a blog post about this, which could be found here. The prototype can be found at the ng2lint repository. |
@mgechev I read through the code and it seems the most obvious place for collaboration is metadata. We are working on a way to persist the metadata we need (since we need it for off-line template compilation) and we plan to reuse this information in the Angular 2 template language service. This is most helpful for classes for which you only have a .d.ts file. When producing a .d.ts file for a library you would be able to produce a metadata description for all the components and directives in the library. You could also use this persisted state in the metadata collector. We are working on this now but it will not show up anywhere for a few weeks. You are already using the Angular 2 compiler so we are already collaborating there! |
@chuckjaz my current implementation uses I'd love to continue the discussion on gitter, or hangouts! |
Coming here from an Aurelia viewpoint... One of the biggest issue in a large Aurelia SPA project today is that the bindings in your markup are not "part" of your TS code. So typos are not caught. References not found when you refactor something. And so on. Aurelia has some very easy default conventions. For instance, if you have a In those advanced scenarios it seems plain impossible to make it work seamlessly. <!-- aurelia vm=MyClass -->
<template></template> Another problem is the concept of global resources. Those are "functionality" that you create and make available in all (or some) templates in your project. It is very hard if not impossible for a compiler to accurately analyze code so that it knows what resources are available in any given file. To give you an idea of the complexity: Rob has made a demo where he could change the syntax of the templates on a per-file basis in a single project, so that legacy Knockout or Angular 1 syntax could be used inside an Aurelia project. Again it seems to me that to get this working properly one would need some kind of config file at the project level (maybe |
@MarkPieszak AFAIK @chuckjaz is working on this here. |
I'm guessing this is still planned for 2.1, but is there an active PR yet? |
TypeScript 2.1 RC is now available. @chuckjaz has worked for Angular2 support but it works only for VSCode and it's not a tsserver extension. Do you think TypeScript 2.1 release will provide the capability to extends tsserver to support the work of @chuckjaz with Angular2 that in my case I would like to use to give Angular2 support for Eclipse. |
What about typescript compilation (emit) plugins, will this be possible to do with the plugin system? I'd love to see the possibility to change the compilation output and create plugins such as this one for babel https://www.npmjs.com/package/jsx-control-statements (HC React developers please do not throws stones, some actually like this :) |
are there some news for IntelliSense in HTML Files/Templates with TypeScript and perhaps Angular 2 for VS Code or Visual Studio? |
@squadwuschel here's a VSCode plugin for the Angular language service that @chuckjaz developed https://github.com/angular/vscode-ng-language-service. |
Hi. I'm inspired by @chuckjaz 's Angular Language Service plugin for vscode and I've create an extension, https://github.com/Quramy/ng-tsserver, for other editors which communicates with tsserver (Vim, Emacs, Sublime Text, etc...) . |
For people subscribed to this issue, there's been some merged work for TS 2.3 on this in #12231 Looking forwards to what we can do with Relay and TypeScript when this is 👍 |
Should be fixed by #12231. For more information about authoring a tsserver plugin, see https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin. |
TypeScript Extensibility
This is an umbrella issue for tracking the design of an extensibility model for TypeScript.
There have already been a number of issues opened with regards to supporting Angular2 via such a model, (especially for richer template editing support), so this will be the initial focus. This not only ensures rich support for a key TypeScript scenario, but by solving real problems, it also ensures we are not designing in a vacuum.
High level problems
This section captures an overview of the problems to be solved. These are not of equal priority, and not all features below may be implemented, but are captured here for completeness, and to be considered in the broader picture.
Challenges
This section captures non-trivial challenges to be addressed, either with the problem domain in general or the current TypeScript architecture.
require
or take dependencies on other Node.js packages.Angular specific challenges
templateUrl
that resolves to the same file on disk? In which context should TypeScript evaluate that file?templateUrl
properties?baseUrl
orconfig
object needed to map paths from the TypeScript source to the template files?<div>${getStart()}<foo [prop]='expr'/>${getEnd()}</div>
, or analyze the component with the directives given asdirectives: getMyDirectives()
?this.
needed), and the usual global members aren't available (i.e. can't referenceDate.now
,parseInt
, or similar). Thus resolving names and providing completion lists requires quite different logic to the usual TypeScript behavior.Current work
The below is currently experimental work to spike various approaches.
template
, or is preceded with a/** @html */
comment. See https://github.com/billti/TypeScript-TmLanguage/blob/ngml/TypeScript.YAML-tmLanguage#L507typescript.tmLanguage
file under the install location atContents/Resources/app/extensions/typescript/syntaxes
with the version from theTypeScript-TmLanguage
repo above (from thengml
branch).TypeScript
repo above, checkout thengml
branch, and build.typescript.tsdk
property to the build location in the prior step (e.g./src/typescript/built/local
).<
,[
, etc. opentypescriptMain.ts
from theContents/Resources/app/extensions/typescript
folder under the VSCode install location, and change the line that callsregisterCompletionItemProvider
to readvscode_1.languages.registerCompletionItemProvider(modeID, completionItemProvider, '.', '<', '(', '[', '\'');
src/services/plugin-ngml.ts
), as are some basic unit tests.angular2/src/compiler
(if possible)<foo name='Hi {{name}}'></foo>
won't work yet.attr
) don't work yet, i.e.<td [attr.colspan]='expr'>
mem1(mem2) + mem3
will only bindmem1
to the class instance member correctly.directives
values are resolved currently).*ngFor='#item of items'
, aren't implemented yet.mem?.value | mypipe:"arg1"
[prop]
or(event)
syntax#name
attribute syntaxExisting related issues:
The text was updated successfully, but these errors were encountered: