Repository navigation
TypeScript extensibility #6508
Description
Activity
Bill Ticehurst (@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:
- person.html
<h1[style. // here Ctrl+Space shows FontFamily
- person.ts:
@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
.htmlfile is an Angular template, and you don't want to load the TypeScript language service and scan all source to see if it is anytime someone opens an HTML file. If it had a unique extension you could identify the grammar and language service based of this (e.g.*.ngmlor similar).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).
Bill Ticehurst (@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 an user settings (ex : for Eclipse you can set a nature in the .project)
- or could be detect:
- search depdendencies in the package.json
- or search if the project contains a node_modules/angular2 folder
- or some other thing (ex : tsconfig.json, etc)
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!
Reacted by Isak ÅgrenAngelo (@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.
LPGhatguy commented
on Feb 17, 2016 ContributorMore actionsBill Ticehurst (@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.
- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptIn DiscussionNot yet reached consensusNot yet reached consensus
on Feb 19, 2016 remojansen commented
on Feb 22, 2016 ContributorMore actions👍
Seriously cool feature - looking forward to having something like that!
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?
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:
- an Angular2 explorer like I had done for Angular1:
- a search engine to retrieve Angular2 component like I have done to retrieve module, controllers, directives for Angular1:
Bill Ticehurst (@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.
Reacted by Artur AmpilogovMinko Gechev (@mgechev) Nice! Chuck Jazdzewski (@chuckjaz) has been investigating this tooling from the Angular implementation side, so he may be interested in some of the work you are doing here.
Minko Gechev (@mgechev) We are definitely covering some of the same ground. I read the blog post and I agree with Bill Ticehurst (@billti); Nice!. I will look at the code and see if there is some things we can share.
Minko Gechev (@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!
13 remaining items
Is it possible to have this kind of intellisense and type checking inside of an External template as well? I'm guessing that would be something an IDE (like VSCode, etc) would need to implement right?
Mark Pieszak (@MarkPieszak) AFAIK Chuck Jazdzewski (@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. Chuck Jazdzewski (@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 Chuck Jazdzewski (@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 (@squadwuschel) here's a VSCode plugin for the Angular language service that Chuck Jazdzewski (@chuckjaz) developed https://github.com/angular/vscode-ng-language-service.
Reacted by Eric M. Dantas, Vlad Sabev, Mark Pieszak, James Pacileo, Daniel Zuidinga and Steve SewellHi. I'm inspired by Chuck Jazdzewski (@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...) .
Reacted by Oskar Karlsson, Mark Pieszak, Minko Gechev, Simon Hürlimann and Bangon KaliFor 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 👍
Reacted by Bnaya Peretz, Oskar Karlsson, jods, Nathaniel Whiteinge, Leon Adler, Toni Villena, Ullrich Praetz, 阿邦, Angel D. Munoz, DerZyklop and 1 moreShould be fixed by #12231. For more information about authoring a tsserver plugin, see https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin.
Reacted by Leon Adler and Ori Livni- addedFixedA PR has been merged for this issueA PR has been merged for this issueand removedIn DiscussionNot yet reached consensusNot yet reached consensus
on May 23, 2017 - locked and limited conversation to collaborators
on Jun 19, 2018



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.
requireor take dependencies on other Node.js packages.Angular specific challenges
templateUrlthat resolves to the same file on disk? In which context should TypeScript evaluate that file?templateUrlproperties?baseUrlorconfigobject 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.tmLanguagefile under the install location atContents/Resources/app/extensions/typescript/syntaxeswith the version from theTypeScript-TmLanguagerepo above (from thengmlbranch).TypeScriptrepo above, checkout thengmlbranch, and build.typescript.tsdkproperty to the build location in the prior step (e.g./src/typescript/built/local).<,[, etc. opentypescriptMain.tsfrom theContents/Resources/app/extensions/typescriptfolder under the VSCode install location, and change the line that callsregisterCompletionItemProviderto 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) + mem3will only bindmem1to the class instance member correctly.directivesvalues are resolved currently).*ngFor='#item of items', aren't implemented yet.mem?.value | mypipe:"arg1"[prop]or(event)syntax#nameattribute syntaxExisting related issues: