0

I'm trying to customize token colorization for Fortran in VS Code. To give a concrete example, I want all preprocessor directives to be a certain color and in italics. I can do it by adding the following block in settings.json,

"editor.tokenColorCustomizations": {"textMateRules": [
  {
    "scope": ["keyword.preprocessor.ifdef.fortran","keyword.preprocessor.endif.fortran","keyword.preprocessor.ifndef.fortran","keyword.preprocessor.indicator.fortran"],
    "settings": {"foreground": "#99E8B2", "fontStyle": "italic"},
  },
]}

However, this looks ugly. Is there a way to specify that all preprocessor keywords in fortran should be formatted a certain way? I tried "keyword.preprocessor.*.fortran" and "keyword.preprocessor..+.fortran", but they didn't work. I could just do "keyword.preprocessor" as the scope, but I only want this formatting to apply to Fortran preprocessor keywords, not (say) C preprocessors.

This question applies to other elements of the language as well. For example, if I want all type specifiers to have a certain color, I would like to specify a "wildcard" for the scope, such as "storage.type.*.fortran", but that syntax does not work. If I could specify "storage.type" as the scope but limit it only to Fortran, that would be perfect.

Edit As per suggestions of @rioV8, I tried the following:

"[FortranFreeForm]": {
    "editor.tokenColorCustomizations": {"textMateRules": [
        {
            "scope": "meta.parameter.fortran",
            "settings": {"foreground": "#f0f0f0"},
        }]}},

in my settings.json, but that did not work.

TM5
  • 192
  • 3
  • 12
  • you can define settings that are [language specific](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings) – rioV8 May 20 '21 at 04:12
  • Does this work for token color customization? I tried that (included in my edit to the original question), but didn't work. – TM5 May 20 '21 at 14:55
  • In fact, if I hover my mouse over editor.tokenColorCustomizations in settings.json, a popup says "This setting does not support per-language configuration." – TM5 May 20 '21 at 15:01
  • did not know that, if you only have Fortran in your workspace, you can modify `.vscode/settings.json` – rioV8 May 20 '21 at 17:48
  • I use python and fortran with equal frequency, and occasionally also C and shell scripts. Haven't been able to find a syntax highlighting scheme that makes sense for all of them, hence the desire to define per-language token colorization. – TM5 May 21 '21 at 20:21

1 Answers1

0

In the scope attribute you would put source.{file extension} {rule} to specify a rule for that specific language.

For example:

{
    "scope": "source.tsx keyword.operator, source.tsx keyword, source.tsx storage, source.tsx variable.language",
    "settings": {
        "fontStyle": "italic"
    }
}

Answer