Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

typescript-lit-html-plugin

Microsoft8.5kMIT0.9.0

TypeScript language service plugin that adds IntelliSense for html tagged templates

TypeScript, html, literal html, templates

readme

TypeScript lit-html Plugin

TypeScript server plugin that adds intellisense for lit-html template strings

Build Status

Features

  • IntelliSense for html tags and attributes.
  • Quick info hovers on tags.
  • Formatting support.
  • Auto closing tags.
  • Folding html.
  • CSS completions in style blocks.
  • Works with literal html strings that contain placeholders.

Usage

This plugin requires TypeScript 2.4 or later. It can provide intellisense in both JavaScript and TypeScript files within any editor that uses TypeScript to power their language features. This includes VS Code, Sublime with the TypeScript plugin, Atom with the TypeScript plugin, Visual Studio, and others.

With VS Code

The simplest way to use this plugin is through the lit-html extension. This extension automatically enables the plugin, and also adds syntax highlighting for lit-html template strings and synchronization of settings between VS Code and the plugin.

To use a specific version of this plugin with VS Code, first install the plugin and a copy of TypeScript in your workspace:

npm install --save-dev typescript-lit-html-plugin typescript

Then add a plugins section to your tsconfig.json or jsconfig.json

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-lit-html-plugin"
      }
    ]
  }
}

Finally, run the Select TypeScript version command in VS Code to switch to use the workspace version of TypeScript for VS Code's JavaScript and TypeScript language support. You can find more information about managing typescript versions in the VS Code documentation.

With Sublime

This plugin works with the Sublime TypeScript plugin.

First install the plugin and a copy of TypeScript in your workspace:

npm install --save-dev typescript-lit-html-plugin typescript

And configure Sublime to use the workspace version of TypeScript by setting the typescript_tsdk setting in Sublime:

{
    "typescript_tsdk": "/Users/matb/my-amazing-project/node_modules/typescript/lib"
}

Finally add a plugins section to your tsconfig.json or jsconfig.json and restart Sublime.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-lit-html-plugin"
      }
    ]
  }
}

With Atom

This plugin works with the Atom TypeScript plugin.

First install the plugin and a copy of TypeScript in your workspace:

npm install --save-dev typescript-lit-html-plugin typescript

Then add a plugins section to your tsconfig.json or jsconfig.json and restart Atom.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-lit-html-plugin"
      }
    ]
  }
}

To get syntax highlighting for lit-html strings in Atom, consider installing the language-babel extension.

With Visual Studio

This plugin works Visual Studio 2017 using the TypeScript 2.5+ SDK.

First install the plugin in your project:

npm install --save-dev typescript-lit-html-plugin

Then add a plugins section to your tsconfig.json.

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-lit-html-plugin"
      }
    ]
  }
}

Then reload your project to make sure the plugin has been loaded properly. Note that jsconfig.json projects are currently not supported in VS.

Configuration

You can configure the behavior of this plugin in plugins section of in your tsconfig or jsconfig.

If you are using lit-html extension for VS Code, you can configure these settings in the editor settings instead of using a tsconfig or jsconfig.

Tags

This plugin adds html IntelliSense to any template literal tagged with html or raw:

import {html} from 'lit-html'

html`
    <div></div>
`

You can enable IntelliSense for other tag names by configuring "tags":

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-lit-html-plugin",
        "tags": [
          "html",
          "template"
        ]
      }
    ]
  }
}

Formatting

The plugin formats html code by default. You can disable this by setting "format.enabled": false

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-lit-html-plugin",
        "format": { "enabled": false }
      }
    ]
  }
}

Contributing

To build the typescript-lit-html-plugin, you'll need Git and Node.js.

First, fork the typescript-lit-html-plugin repo and clone your fork:

git clone https://github.com/YOUR_GITHUB_ACCOUNT_NAME/typescript-lit-html-plugin.git
cd typescript-lit-html-plugin

Then install dev dependencies:

npm install

The plugin is written in TypeScript. The source code is in the src/ directory with the compiled JavaScript output to the lib/ directory. Kick off a build using the compile script:

npm run compile

Testing

Run the test using the e2e script:

(cd e2e && npm install)
npm run e2e

The repo also includes a vscode launch.json that you can use to debug the tests and the server. The Mocha Tests launch configuration starts the unit tests. Once a test is running and the TypeScript server for it has been started, use the Attach To TS Server launch configuration to debug the plugin itself.

Submitting PRS

You can submit bug fixes and features through pull requests. To get started, first checkout a new feature branch on your local repo:

git checkout -b my-awesome-new-feature-branch

Make the desired code changes, commit them, and then push the changes up to your forked repository:

git push origin my-awesome-new-feature-branch

Then submit a pull request against the Microsoft typescript-lit-html-plugin repository.

Please also see our Code of Conduct.

changelog

Changelog

0.9.0 - November 16, 2018

  • Add auto closing tags.
  • Prevent potential double decoration of a language service.

0.8.0 - November 16, 2018

  • Allow editors to configure plugin. Requires TS 3.1.4+ and editor support.

0.7.1 - November 13, 2018

  • Fix tag highlighting when using TS 3.1+.

0.7.0 - November 13, 2018

  • Fix some false positive reporting for styles. Thanks @csvn!
  • Tag matching highlighting. Requires VS Code 1.30+
  • Picked up new styled components version which includes some important fixes and additions.

0.6.0 - October 15, 2018

  • Pick up new html service version with bug fixes and features like vendor info.
  • Pick up new decorator library version to fix a possible state corruption error.

0.5.3 - July 9, 2018

  • Disable formatting in html that contains a style block. There is an annoying bug that may corrupt the html when running format on these blocks. Better to disable formatting in them for now.

0.5.2 - July 9, 2018

  • Remove TS as peerDep.

0.5.1 - July 9, 2018

  • Fixing false errors when using placeholders in style block.

0.5.0 - July 6, 2018

  • Error reporting and quick fixes for css in style blocks. Thanks @justinribeiro!

0.4.2 - July 5, 2018

  • Use more consistent look for quick info hover. Thanks @justinribeiro!

0.4.1 - July 3, 2018

  • Return css quickInfo inside styled blocks. Thanks @justinribeiro!

0.4.0 - July 3, 2018

  • Added folding support.

0.3.1 - June 29, 2018

  • Don't return signature help inside html template strings.

0.3.0 - June 29, 2018

  • Added css IntelliSense inside of <style> tags. Thanks @justinribeiro!

0.2.0 - January 11, 2018

  • Add completion entry details for tag completions.
  • Support raw tag by default as well.
  • Don't remove newlines in empty html block.

0.1.1 - January 9, 2018

  • Also make sure we don't have a runtime dep on TS for hover.

0.1.0 - January 9, 2018

  • Make sure we don't have a runtime dep on TS for completion items

0.0.3 - Novermber 30, 2017

  • Do not take run time dependency on TS.
  • Fix auto import completions not showing up when using plugin with TS 2.6.2+

0.0.2 - October 27, 2017

  • Support for VS 2017

0.0.1 - October 10, 2017

  • Initial release