1

I've been trying to create a test extension for a custom code highlighting.

The extension works perfectly fine but I am wondering how can I attach the token colour definitions, sort of like a default if people don't add it to the settings.json.

At first I thought I could do it in package.json in the contributes section but I can't get it to work.

Here's an example of what I'm trying to "attach" to my extension:

{"scope": ["source.qqql.scope"], "settings": {"foreground": "#aaaaaa"}},
{"scope": ["source.qqql.scope.type"], "settings": {"foreground": "#6997bf"}},
{"scope": ["source.qqql.scope.name"], "settings": {"foreground": "#555555"}},

I also tried adding it to

"configurationDefaults": {
  "[qqql]": {
    "editor.tokenColorCustomizations": [
      "textMateRules": [<here>]
    ]
  }
}

in the package.json but upon testing with F5 it didn't colorise the tokens.

I followed this topic: VS Code - Text formatting in a new language extension but I fear I'm missing a step or a crucial part of understanding how to do it. Any help would be appreciate it.

Moseleyi
  • 2,585
  • 1
  • 24
  • 46
  • the TextMate grammer determines the `scope name` and the Theme determines the color of the `scope name`. So add the name to the Theme or customize the Theme, maybe customize doesn't work if the theme doesn't have the scope name used – rioV8 Mar 22 '22 at 01:02
  • Thanks @rioV8. I'm reading the https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#theming page where it says: `Theming is about assigning colors and styles to tokens. Theming rules are specified in Color Theme files (JSON format). Users can also customize the theming rules in the user settings.` but I can't find how to do it exactly.. – Moseleyi Mar 22 '22 at 07:37
  • 1
    The problem is also that I don't want the theme to change completely. Just the token colour to be added to whatever theme people are using – Moseleyi Mar 22 '22 at 08:07
  • does it work if you add the customization to `setting.json`, maybe they don't allow you to add any `editor.*` settings in `contribute.configurationDefaults`, but then how are you going to determine if it is a light or dark theme or high contrast, you can change `settings.json` from your extension with a command called by the user `Add syntax colors to language qqql (Light Theme)` – rioV8 Mar 22 '22 at 08:25
  • The token colours will only work with light theme, which is okay but I don't want to change the whole editor's theme to light - basically I want the token colours to work wihtout forcing people to change the whole theme. I have found an issue in vs-code-themes where poeple argue for language-specific themes, which is probably what I am after. Yes if I add tokens to `settings.json` then it all works great – Moseleyi Mar 22 '22 at 09:28
  • then let your extension modify `settings.json` – rioV8 Mar 22 '22 at 10:45
  • Yeah that's what I want to do but how? – Moseleyi Mar 22 '22 at 11:21
  • read the `Configuration` section in the VSC API – rioV8 Mar 22 '22 at 15:32
  • I had a look and read through WorkspaceConfiguration section but nothing comes to mind, thank you for you help anyway. – Moseleyi Mar 22 '22 at 19:47
  • read the methods more carefully – rioV8 Mar 22 '22 at 21:56

0 Answers0