0

I am writing a TextMate grammar to extend the syntax highlighting capabilities on Markdown language using Visual Studio Code. The expected outcome is something like what is achieved with Fabio's vscode-highlight, but I was looking for something more 'simple', without having the need to install or create an extension.

Already did lots of research but can't get any matches when inspecting the scope. Any suggestions? As of now, my files are:

./package.json
{
    "name": "name123",
    "description": "desc123",
    "publisher": "me",
    "version": "0.0.1",
    "engines": {
        "vscode": "^1.0.0"
    },
    "contributes": {
        "grammars": [{
            "language": "markdown",
            "scopeName": "text.html.markdown",
            "path": "./syntaxes/markdown.tmLanguage.json"
        }]
    }
}
./syntaxes/markdown.tmLanguage.json
{
  "scopeName": "text.html.markdown",
  "patterns": [
    { "include": "#headings" }],
  "repository": {
    "headings": {
      "patterns": [
        { "include": "#symbol" },
        { "include": "#text" }]},
        "symbol": {
          "match": "*s2",
          "name": "symbol.letter.number.headings.md" },
        "text": {
          "match": "Description 12345",
          "name": "text.description.headings.md" }
  }
}
Gama11
  • 31,714
  • 9
  • 78
  • 100
mafap
  • 371
  • 3
  • 18
  • 40

1 Answers1

1

In markdown files, there is a regex error logged to the dev console:

ERR target of repeat operator is not specified: Error: target of repeat operator is not specified
    at Object.createOnigScanner (c:\Program Files\Microsoft VS Code\resources\app\node_modules.asar\vscode-textmate\release\main.js:58:24)
    at Grammar.createOnigScanner (c:\Program Files\Microsoft VS Code\resources\app\node_modules.asar\vscode-textmate\release\main.js:2466:30)
    [...]

The problem is the *s2 regex. I'm not sure what exactly you were trying to match there, but there has to be some character that should be repeated before *.

Your other scope matches as expected withsymbol removed to avoid the error:

Gama11
  • 31,714
  • 9
  • 78
  • 100
  • The `*` was just a coincidence, it was meant to be a random symbol. I have no errors, can't figure out what is wrong. My `package.json` and `markdown.tmLanguage.json` were created manually, is it a problem? Where do they need to be located? – mafap Apr 13 '19 at 15:08
  • No, that should not be a problem. The location of the project doesn't really matter if you launch through the extension development host. – Gama11 Apr 13 '19 at 16:01
  • I thought this would work like normal settings. So, you mean it is mandatory to create an extension just for that purpose? – mafap Apr 13 '19 at 16:53
  • Yes, you can't add a TmLanguage grammar without an extension, and pretty much the whole point of `package.json` is to describe the things that an _extension_ contributes. :) – Gama11 Apr 13 '19 at 16:55
  • Maybe you're looking for something like this? https://stackoverflow.com/questions/47218502/vscode-editor-tokencolorcustomizations-comment-does-not-color-the-whole-c – Gama11 Apr 13 '19 at 16:55
  • The `editor.tokenColorCustomizations` does not solve the problem as the TM scope inspector is not working anyway. The idea was not to create an extension. Will give it a try or end up using Fabio's extension. Your insights were still valuable ;) – mafap Apr 13 '19 at 17:47