VSCode syntax highlighting for custom shebang

后端 未结 3 1459
逝去的感伤
逝去的感伤 2021-02-08 19:28

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 h

相关标签:
3条回答
  • 2021-02-08 20:11

    I work on VSCode.

    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"
        }]
    

    There is no setting to control this, but you could use file.associations to map these files to python directly.

    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

    0 讨论(0)
  • 2021-02-08 20:17

    To complement Matt Bierner's helpful answer:

    The JSON settings Matt references are in <languageId>/package.json files in the following locations:

    On GitHub:

    • https://github.com/Microsoft/vscode/tree/master/extensions
    • E.g., for Python: https://github.com/Microsoft/vscode/blob/master/extensions/python/package.json

    When installed:

    • In the resources/app/extensions subfolder of the VSCode installation folder; e.g.:

      • Windows (32-bit version):

        C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions
        
      • macOS:

        /Applications/Visual Studio Code.app/Contents/Resources/app/extensions
        
    • E.g, for Python:

      • Windows (32-bit version):

        C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\python\package.json
        
      • macOS:

        /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/python/package.json
        
    0 讨论(0)
  • 2021-02-08 20:26

    And to complement mklement0's complement:
    On Linux, see /usr/share/code/resources/app/extension/
    E.g for Lua: /usr/share/code/resources/app/extensions/lua/package.json

    0 讨论(0)
提交回复
热议问题