1
votes

I am trying to set up custom language highlighting in VSCode extension. So far I was successful at making it depend on file extension. But due to some specifics of structure I need to apply language by a string in the file path. This is the example from VSC API docs:

{
  "contributes": {
    "languages": [
      {
        "id": "python",
        "extensions": [".py"],
        "aliases": ["Python", "py"],
        "filenames": [],
        "firstLine": "^#!/.*\\bpython[0-9.-]*\\b",
        "configuration": "./language-configuration.json"
      }
    ]
  }
}

It seems there is a filenames parameter. But from my testing it seems that it support only full name of the file, doesn't accept regex or file path.

Is there a way to enable language by a part of file path. For ex.: we have a file \someFolder\Important\file.file, apply our custom language to all file in that have Important in their path.

1

1 Answers

0
votes

Use filenamePatterns, which allows glob matching. So, in your package.json:

{
  "contributes": {
    "languages": [
      {
        "id": "python",
        "aliases": ["Python", "py"],
        "filenamePatterns": [
          "*.py",
          "*Important*"
        ],
        "firstLine": "^#!/.*\\bpython[0-9.-]*\\b",
        "configuration": "./language-configuration.json"
      }
    ]
  }
}

Note: the filenamePatterns feature is not documented.