简体   繁体   English

按文件名模式的 VSCode 语言扩展

[英]VSCode language extension by filename pattern

I am trying to set up custom language highlighting in VSCode extension.我正在尝试在 VSCode 扩展中设置自定义语言突出显示。 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:这是来自 VSC API 文档的示例:

{
  "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.似乎有一个filenames参数。 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.例如:我们有一个文件\someFolder\Important\file.file ,将我们的自定义语言应用于路径中包含Important文件的所有文件。

Use filenamePatterns , which allows glob matching.使用filenamePatterns ,它允许全局匹配。 So, in your package.json:因此,在您的 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.注意: filenamePatterns功能没有记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM