-
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
Compile / edit time pluggable analyzers like C# #3003
Comments
I would definitely use this if it became available! |
Thanks for sharing, seems like all the building blocks are almost in place. async may be a blocker though for TypeScript. +1 to Visual Studio debugging Visual Studio #2656 😮 |
This would be great. It would also open good integration for things like design-by-contract and of course nullable checking. I would love this feature. |
As someone who was heavily involved in this work in https://github.com/dotnet/roslyn, i'm definitely very interested in enhancing TypeScript in this space. Unfortunately, there are a lot of hard issues here that make this a non-trivial for us. For one thing, our compiler has been designed for raw speed on a JS engine, rather than extensibility. To be very fast on JS engines, you need to avoid lots of abstractions and complex layering in your objects. So, for example, our AST nodes work very differently than Roslyn's do. This includes:
Furthermore, the JavaScript language and engines are missing many useful features that Roslyn heavily leans on for performance. For example, Roslyn takes huge advantage of structs in order to provide their dual Red Green Trees. By using structs they can effectively have two different tree representations, with only marginal memory/heap/gc overhead. All of these deviations we made from Roslyn (which we understood and acknowledged when we did this work), were for performance reasons. They allowed us to provide a fast and lean compiler initially. Though they do now impact our ability to better supply things like analyzers/fixers in as simple a manner as Roslyn provides them. My hope is that as time moves on we can get these same sorts of features, while still maintaining our goal of a fast and lean compiler. |
I just wanted to post something I posted in the closed post here, just to give a reference of a couple possible uses. Begin quote -> Here are a few examples of possible extensions: Add language support for defining properties with getters and setters. Too big of a change, possibly not useful enough to warrant a change in Typescript, but it would be super cool if I could make a seperate npm package called typescript-properties, and anyone could pull that, and utilize it in there apps. This could maybe be an example that decorators could take care of, not sure.
While this can be accomplished with external tools, it breaks source mapping. With a complex build, like: Original TS |
👍 |
Just wanted to chim in with a use case: We use CSS modules which means that we import CSS files in TypeScript. We get an object map back from that import where the keys are class names from the CSS file. It would be incredible if it was possible to extend TypeScript to give autocompletion and compile safety for this. |
I think tslint would be better architected as a compiler plugin. It better supports the ability to share the typecheckers understanding of the program without duplicate logic to read Can you guys discuss a bit whether this is possible? |
it is possible. we have had a prototype for this 2 years back. we have just been busy with other things since. |
Okay, what needs to happen? Would it help to pick up that prototype, or is On Thu, Mar 31, 2016 at 12:19 PM Mohamed Hegazy [email protected]
|
Prototype was built against the old codebase so it cannot be directly applied now. There are plans to support user-defined diagnostics, at this point it is mostly the question of prioritization. |
I think this topic is related to #6508 which relates to Roadmap |
My understanding is that there are four extension points (at least):
As I see it, we need a higher-level discussion of how the compiler could be configured to know about plugins, how the actual loading of the plugin occurs, how the plugin declares which of the 4+ extension points it wants to hook, how to defend against abusive plugins (intentional or unintentional), and so on. As it stands, Angular is writing multiple independent programs which wrap tsc, which is hard for users to configure and inefficient. @mhegazy would it be helpful to write up a rough proposal for this, or do you already have some partly-formed ideas about it? |
Was this completed when #6508 was delivered? I still can't find guidance on how to write analyzers and fixes for TypeScript projects. Is it at all possible? |
Yes and no depending on your usecase. If you want to provide an alternative language service like angular and vue do, along with any additional diagnostics that entails; then yes - you have hooks available to wrap and reexpose the LS. If you wanted to, say, add lint-like errors on the command line, then no; we've yet to merge any plugin model that supports that. |
It would be nice to have similar plugabble compile time / editing time analyzer plugins as introduced in C# in Build 2015, see the video.
Analyzer is a library that can do additional syntax checks, tag lines as errors / warnings, and are interpreted by language service.
I can imagine one could do similar things with it as Facebook's flow does e.g. own nullable checking just by writing own analyzer. This would be configurable from tsconfig, maybe one could whitelist the files each analyzer works on. This way the nullability check analyzer would only complain about the code I want.
The text was updated successfully, but these errors were encountered: