zoukankan      html  css  js  c++  java
  • vscode/sublime 语法高亮定义和代码段的区别

    vscode插件数据格式基于json,sublime插件数据格式基于xml。sublime插件的官方文档说的不清楚,相关教程也很难找,遇到的一些坑记录一下

    语法定义文件对比

    同样使用TextMate定义(tmLanguage),sublime可读取的是xml格式,使用plist结构,极其坑爹

    vscode: test.tmLanguage.json

    {
        "name": "Test",
        "scopeName": "source.test",
        "fileTypes": [
            "test"
        ],
        "patterns": [
            {"include": "#comments"},
        ],
        "repository": {
            "comments": {
                "match": "//.*",
                "name": "comment.line.double-slash"
            }
        }
    }
    

    sublime: test.tmLanguage

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>uuid</key>
        <string>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</string>
    
        <key>name</key>
        <string>Test</string>
        <key>scopeName</key>
        <string>source.test</string>
        <key>fileTypes</key>
        <array>
            <string>test</string>
        </array>
        <key>patterns</key>
        <array>
            <dict>
                <key>include</key>
                <string>#comments</string>
            </dict>
        </array>
        <key>repository</key>
        <dict>
            <key>comments</key>
            <dict>
                <key>match</key>
                <string>//.*</string>
                <key>name</key>
                <string>comment.line.double-slash</string>
            </dict>
        </dict>
    </dict>
    </plist>
    
    • 格式区别: sublime提供一种单独的sublime-syntax格式,使用YAML格式编写,没试过。sublime提供了一种安装PackageDev后,使用YAML编写"*.YAML-tmLanguage"文件,再生成XML文件的格式,但在有一定限制需要手写的时候不太好用。因为使用xml,支持多行文本(vscode的json中使用字符串列表),字符串不需要使用双引号包围,也不需要''转义
    • 生效区别: vscode的语法文件需要在package.json中正确配置,sublime的语法定义文件直接塞到Packages文件夹就可以生效。但有一点需要注意的是sublime需要uuid字段来识别文件...因为这个问题纠结了一段比较长的时间

    代码段定义对比

    vscode

    test.json 或 test.code-snippets

    {
        "snippet1": {
            "scope": "source.test",
            "prefix": "header",
            "body": [
                "this is a header.",
                "this is the 2nd line."
            ]
        },
        "snippet2": {
            "scope": "source.test",
            "prefix": "header2",
            "body": [
                "this is a header 2.",
                "this is the 2nd line."
            ]
        }
    }
    

    sublime

    header.sublime-snippets

    <snippet>
        <scope>source.proto</scope>
        <tabTrigger>header</tabTrigger>
        <content>this is a header.
    this is the 2nd line.</content>
    </snippet>
    

    header2.sublime-snippets

    <snippet>
        <scope>source.proto</scope>
        <tabTrigger>header2</tabTrigger>
        <content>this is a header 2.
    this is the 2nd line.</content>
    </snippet>
    

    二者的文件后缀名似乎都没什么限制。
    sublime的代码段定义文件默认好像是只会读取第一个<snippet>片段,有多个代码段需要建立多个文件,没有深入研究是否有一个文件定义多个代码段的形式

  • 相关阅读:
    MVC模式下 provider: SQL Network Interfaces, error: 50
    How to expose a JSON endpoint from a WCF-service
    net 后台任意设置 控件显示和隐藏就OK
    VS编程,快速折叠或者展开代码到 #region 级别的设置方法。
    java进阶(18)--Enum枚举
    java进阶(17)--Random
    java进阶(16)--System常用方法总结
    java进阶(15)--DecimalFormat、BigDecimal
    java进阶(14)--日期时间处理
    java进阶(13)--int、String、Integer互相转换
  • 原文地址:https://www.cnblogs.com/lunoctis/p/12108529.html
Copyright © 2011-2022 走看看