简体   繁体   中英

How can VSCode Custom editor extension tell VSCode that this editor extension should be skipped as it does not support the file

I'm writing a VSCode custom editor extension. The extension should be activated for component.yaml files. However I realize that there could be files named component.yaml with completely different formats. I want to detect that the file is not in expected format and bail out, skipping my extension, so that the file opens in the default text editor or another registered extension.

How can my extension refuse/skip opening a file?

An extension cannot refuse to be opened, but you can specify a regular expression for the first line in the file, which has to match to allow your extension to be activate for that file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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