Skip to content

Angular Language Service as a TypeScript plugin in VS Code, which is more efficient than the official extension (and also up to date).

License

Notifications You must be signed in to change notification settings

Goobles/vscode-typescript-angular-plugin

Repository files navigation

Angular Language Service as a TypeScript plugin extension for Visual Studio Code

Visual Studio Code extension activating the official Angular Language Service as a TypeScript plugin.

Important

The Language Service is an official tool provided by Angular to give you assistance and error-checking in templates. But it does not do highlighting of inline templates (see below).

This extension just uses the official @angular/language-service, but the extension itself is not official.

Also, this extension already works quite well, but it's still experimental.

Why?

Until now, you used the official Angular Language Service extension for VS Code. So why this one?

More efficient

The legacy official extension launches a duplicate TypeScript process, while this extension launches the same Angular Language Service but as a TypeScript plugin, which is more efficient!

This extension works exactly in the same way as the new official TypeScript TSLint plugin extension from Microsoft.

Up to date

As asked and answered in angular/vscode-ng-language-service#298, the legacy official extension is not well maintained, and so have a lot of issues.

This extension is directly using the latest official @angular/language-service package, so it's up to date and it will be updated at each new release of @angular/language-service (including patches).

By the same author

Getting started

Follow instructions on Visual Studio Code marketplace, or just search for "Angular Language Service as a TypeScript plugin" by "Cyrille Tuzi" directly inside VS Code extensions panel. Done.

Requirements

  1. This extension supports Angular >= 6.

  2. To avoid noise in non-Angular projects, this extension is only enabled inside an Angular CLI project, ie. with an angular.json file in workspace.

  3. If you already have the legacy extension, disable it.

  4. This kind of extensions are designed to work with the VS Code version of TypeScript (which is the default configuration). It won't work with a workspace version of TypeScript.

Inline templates

For now, the extension only works with inline templates. Support for external templates is being investigated (see #1 if you want to help).

It's a good occasion to switch to inline templates. Here are some reasons why:

Classic scenario

Despite it's not the default configuration in Angular CLI, the official @angular/language-service is designed to work with inline templates.

Angular is the only major framework doing external templates. Vue and React templates are inlined.

Syntax highlighting

You can add syntax highlighting for inline templates with angular2-inline extension.

Separation of concerns

Separation of concerns doesn't imply separation of files.

Putting a color in your class, that would be breaking the separation of concerns. But guess what: such crazy things are possible with external templates too. ;)

Easier to understand

Externalizing CSS is a good idea, as it's static and can be quite long.

But there is a very direct relation between your HTML template and your TypeScript class, because of data bindings. External templates make it difficult to understand these bindings, especially for new Angular developers.

Single responsibility principle

Finally, I come to what you're screaming at from the beginning: "HTML templates can be long too, so the TypeScript files become a mess with inline templates".

Well, if your templates are long, the mess may be how you program (sorry!), as it usually means you don't respect the single responsibility principle.

Inline templates favors to pay attention to keep components small, which is good, while external templates favors huge components, which is bad.

So yes, the good practice is inline templates! :)

How?

For a new project:

ng new --inlineTemplate

For an existing project, add this in angular.json:

{
  "projects": {
    "yourprojectname": {
      "schematics": {
        "@schematics/angular:component": {
          "inlineTemplate": true
        }
      }
    }
  }
}

Release Notes

Changelog available here.

License

MIT

About

Angular Language Service as a TypeScript plugin in VS Code, which is more efficient than the official extension (and also up to date).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published