[英]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.我正在编写一个 VSCode 自定义编辑器扩展。 The extension should be activated for component.yaml
files.应该为component.yaml
文件激活扩展。 However I realize that there could be files named component.yaml
with completely different formats.但是我意识到可能存在名为component.yaml
的文件,格式完全不同。 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"
}
}
]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.