自定义shebang的VSCode语法高亮 [英] VSCode syntax highlighting for custom shebang
问题描述
在工作中,我们在自定义环境下运行 python,因此我们使用非标准的shebang.我测试过 VSCode 可以识别没有 .py 扩展名的 python 文件,如果它们有一个 #!/usr/bin/env python
或 /usr/bin 的shebang/python
或这些的变体.
At work we run python under a custom environment, and thus we use a non-standard shebang. I tested that VSCode recognizes python files without a .py extension if they have a shebang that's either #!/usr/bin/env python
or /usr/bin/python
or variants of these.
在工作中,我使用类似于此的shebang:#!/some/directory/envroot "$ENVROOT/bin/python"
但是 vs code 无法识别这一点,因此我必须手动每次都设置语言为python.
At work I use a shebang similar to this: #!/some/directory/envroot "$ENVROOT/bin/python"
but vs code doesn't recognize this, so I have to manually set the language to python each time.
是否有某种配置可以将自定义shebang映射到一种语言,这样我就不必每次打开文件时都手动设置它?
Is there a configuration somewhere that I can map a custom shebang to a language so I don't have to set it manually each time I open the file?
推荐答案
我在 VSCode 工作.
I work on VSCode.
shebang 映射由扩展语法贡献中的 firstLine
定义:
The shebang mapping is defined by firstLine
in the extension grammar contributions:
"languages": [{
"id": "python",
"extensions": [ ".py", ".rpy", ".pyw", ".cpy", ".gyp", ".gypi" ],
"aliases": [ "Python", "py" ],
"firstLine": "^#!/.*\\bpython[0-9.-]*\\b",
"configuration": "./language-configuration.json"
}]
没有设置来控制这个,但你可以使用 file.associations
将这些文件直接映射到 python.
There is no setting to control this, but you could use file.associations
to map these files to python directly.
您的具体示例对我来说也似乎是一个错误.我们目前只使用第一行模式 if整行都匹配,这看起来很奇怪.我已经打开了一个问题来调查这个:https://github.com/Microsoft/vscode/issues/21533
Your specific example also seems like a bug to me. We currently only use the first line pattern if the entire line matches, which seems odd. I've opened an issue to investigate this: https://github.com/Microsoft/vscode/issues/21533
这篇关于自定义shebang的VSCode语法高亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!