JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 41
  • Score
    100M100P100Q76684F
  • License MIT

Textmate language service for Visual Studio Code.

Package Exports

  • vscode-textmate-languageservice
  • vscode-textmate-languageservice/out/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vscode-textmate-languageservice) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

vscode-textmate-languageservice

This package is now superseded by vscode-anycode, a quicker LSP which leverages the tree-sitter symbolic-expression syntax parser.

I've chosen to stabilize it with browser compatibility as a 1.0.0 release and recommend you leverage tree-sitter. Maintainable & with faster retokenization, it is a Holy Grail ... whereas this package depends on a well-written Textmate grammar and is a band aid.

If there is native vscode support for the language, find a Tree-sitter syntax online then suggest it in an Anycode issue. Otherwise, please open an issue on the community-maintained Treesitter syntax highlighter extension and someone might deal with it.

Generate language service providers driven entirely by your Textmate grammar and one configuration file.

In order to be supported by this module, the Textmate grammar must include the following features:

  • meta declaration scopes for block level declarations
  • variable assignment scopes differentiated between multiple and single
  • granular keyword control tokens with begin and end scopes

Installation

npm install vscode-textmate-languageservice

Configuration

Create a JSON file named textmate-configuration.json in the extension directory. The file accepts comments and trailing commas.

Textmate configuration fields:

  • assignment - optional (object)
    Collection of Textmate scope selectors for variable assignment scopes when including variable symbols:
    Properties:
    • separator: Token to separate multiple assignments (string)
    • single: Token to match single variable assignment. (string)
    • multiple: Token to match multiple variable assignment. (string)
  • declarations - optional (array)
    List of Textmate scope selectors for declaration token scopes.
  • dedentation - optional (array)
    List of Textmate tokens for dedented code block declarations (e.g. ELSE, ELSEIF).
    Tokens still need to be listed in indentation with the decrementing value -1.
  • exclude (string) VSC glob pattern for files to exclude from workspace symbol search.
  • indentation - optional (object)
    Indentation level offset for Textmate token types (used to implement folding).
  • punctuation - optional (object)
    Collection of punctuation tokens with a significant effect on syntax providers. Properties:
    • continuation: Token scope selector for line continuation (to use in region matching). (string)
  • markers - optional (object)
    Stringified regular expression patterns for folding region comments.
    • start: Escaped regular expression for start region marker. (string)
    • end: Escaped regular expression for end region marker. (string) Properties:
  • symbols - optional (object)
    Map of document symbol tokens to their symbol kind (vscode.SymbolKind value).

Configuration examples

Template for textmate-configuration.json file:

{
  "assignment": {
    "single": "",
    "multiple": "",
    "separator": ""
  },
  "declarations": [],
  "dedentation": [
    "keyword.control.elseif.custom",
    "keyword.control.else.custom"
  ],
  "exclude": "**/{.modules,.includes}/**",
  "indentation": {
    "punctuation.definition.comment.begin.custom": 1,
    "punctuation.definition.comment.end.custom": -1,
    "keyword.control.begin.custom": 1,
    "keyword.control.end.custom": -1
  },
  "punctuation": {
    "continuation": "punctuation.separator.continuation.line.custom"
  },
  "markers": {
    "start": "^\\s*#?region\\b",
    "end": "^\\s*#?end\\s?region\\b"
  },
  "symbols": {
    "keyword.control.custom": 2,
    "entity.name.function.custom": 11
  }
}

An example configuration file that targets Lua:

{
  "assignment": {
    "single": "meta.assignment.variable.single.lua",
    "multiple": "meta.assignment.variable.group.lua",
    "separator": "punctuation.separator.comma.lua"
  },
  "declarations": [
    "meta.declaration.lua entity.name",
    "meta.assignment.definition.lua entity.name"
  ],
  "dedentation": [
    "keyword.control.elseif.lua",
    "keyword.control.else.lua"
  ],
  "exclude": "**/{.luarocks,lua_modules}/**",
  "indentation": {
    "punctuation.definition.comment.begin.lua": 1,
    "punctuation.definition.comment.end.lua": -1,
    "keyword.control.begin.lua": 1,
    "keyword.control.end.lua": -1
  },
  "markers": {
    "start": "^\\s*#?region\\b",
    "end": "^\\s*#?end\\s?region\\b"
  },
  "symbols": {
    "keyword.control.lua": 2,
    "entity.name.function.lua": 11
  }
}

Usage

import LSP from 'vscode-textmate-languageservice';

export async function activate(context: vscode.ExtensionContext) {
    const selector: vscode.DocumentSelector = { language: 'custom', scheme: 'file' };

    const lsp = new LSP('custom', context);

    const foldingProvider = await lsp.createFoldingRangeProvider();
    const documentSymbolProvider = await lsp.createDocumentSymbolProvider();
    const workspaceSymbolProvider = await lsp.createWorkspaceSymbolProvider();
    const definitionProvider = await lsp.createDefinitionProvider();

    context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(selector, documentSymbolProvider));
    context.subscriptions.push(vscode.languages.registerFoldingRangeProvider(selector, foldingProvider));
    context.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(workspaceSymbolProvider));
    context.subscriptions.push(vscode.languages.registerDefinitionProvider(['custom'], peekDefinitionProvider));
}