0.3.0 • Published 4 years ago

typescript-nornj-plugin v0.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

TypeScript NornJ Plugin

TypeScript server plugin that adds intellisense for NornJ template engine

This is a fork of typescript-lit-html-plugin.

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. The simplest way to use this plugin is through the nornj-highlight extension. This extension automatically enables the plugin, and also adds syntax highlighting for nornj 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-nornj-plugin typescript

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

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-nornj-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.

Configuration

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

If you are using nornj-highlight 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 nj:

import nj from 'nornj';

nj`
    <div></div>
`

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

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "typescript-nornj-plugin",
        "tags": [
          "html",
          "nj",
          "njs",
          "t"
        ]
      }
    ]
  }
}

Formatting

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

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

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.