# 新语音语法高亮

# 1. 介绍

针对 TC Games 宏文件,使其语法高亮

语言名称: tgs (TC Games Scripts)

该扩展项目的名称: tgs-lang-support

需要的功能:

  • 关键字
  • 变量
  • 注释

# 2. tgs 基本功能

# 2.1. 命令

Array.from(document.querySelectorAll('div.content > p[id] > b')).map((item) => item.innerText).forEach(item => console.log(item))

点击 
Click
延时 
Delay
循环 
Loop
长按 
LongPress
滑动 
Slide
按住 
PressDown
按键 
Key
准心重置 
Aimreset
方向键重置 
DirectionReset
键盘行走快跑 
DirectionRun
键盘行走静步 
DirectionWalk
按下键盘按键 
PressKeyboard
松开键盘按键 
ReleaseKeyboard
射击模式开关 
ShotModeSwitch
进入射击模式 
EnterShotMode
退出射击模式 
ExitShotMode
鼠标左键切换开关 
LeftMouseSwitch
进入鼠标左键控制 
EnterLeftMouseControl
退出鼠标左键控制 
ExitLeftMouseControl
托管鼠标左键 
HostLeftMouse
准心自动调节 
AimAutoAdjust
获取准心动态参数 
GetAimDynamicAdjustParm
设置准心动态参数 
SetAimDynamicAdjustParm
简单找图 
SimpleFI
多点找色 
MultiplePointsFC
提示 
tip

# 2.2. 语法

如果 xxx
{
}

如果 xxx
{
}
否则
{
}

变量 变量名=xxx

// 这是一个注释

# 3. 依赖

node -v
# v16.13.2


# 指定镜像源
npm install -g yo generator-code --registry=https://repo.huaweicloud.com/repository/npm/

# 4. 创建项目

W:\dev\vscode\extensions>yo code

     _-----_     ╭──────────────────────────╮
    |       |    │   Welcome to the Visual  │
    |--(o)--|    │   Studio Code Extension  │
   `---------´   │        generator!        │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `

? What type of extension do you want to create? New Language Support

Enter the URL (http, https) or the file path of the tmLanguage grammar or press ENTER to start with a new grammar.

? URL or file to import, or none for new:
 
? What's the name of your extension?            tgs-lang-support
    
? What's the identifier of your extension?      tgs-lang-support    // 项目名称

? What's the description of your extension?     TC Games 宏文件语言支持
                                                                    
Enter the id of the language. The id is an identifier and is single, lower-case name such as 'php', 'javascript'
? Language id:      tgs                     
                                       
Enter the name of the language. The name will be shown in the VS Code editor mode selector.
? Language name:    tgs
                                                                   
Enter the file extensions of the language. Use commas to separate multiple entries (e.g. .ruby, .rb)
? File extensions:  tgs     
                                
Enter the root scope name of the grammar (e.g. source.ruby)
? Scope names:      source.tgs

? Initialize a git repository?      Yes

# 5. 项目结构

tgs-lang-support/
    
    language-configuration.json     // 全局配置、基本配置

    syntaxes/
        tgs.tmLanguage.json         // 核心文件

# 6. 调试

按 F5 即可

# 7. 应用

# 7.1. 本地使用

打包成 vsix 插件,本地安装

# W:\dev\vscode\extensions\tgs-lang-support
npm i vsce -g --registry=https://repo.huaweicloud.com/repository/npm/

vsce package

# 7.2. 发布

# 8. 功能

tgs-lang-support/syntaxes/tgs.tmLanguage.json:

{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "name": "tgs",
  "patterns": [
    {
      "include": "#keywords"
    },
    {
      "include": "#comment"
    }
  ],
  "repository": {
    "keywords": {
      "patterns": [
        {
          "name": "support.function",
          "match": "\\b点击|Click|延时|Delay|循环|Loop|长按|LongPress|滑动|Slide|按住|PressDown|按键|Key|准心重置|Aimreset|方向键重置|DirectionReset|键盘行走快跑|DirectionRun|键盘行走静步|DirectionWalk|按下键盘按键|PressKeyboard|松开键盘按键|ReleaseKeyboard|射击模式开关|ShotModeSwitch|进入射击模式|EnterShotMode|退出射击模式|ExitShotMode|鼠标左键切换开关|LeftMouseSwitch|进入鼠标左键控制|EnterLeftMouseControl|退出鼠标左键控制|ExitLeftMouseControl|托管鼠标左键|HostLeftMouse|准心自动调节|AimAutoAdjust|获取准心动态参数|GetAimDynamicAdjustParm|设置准心动态参数|SetAimDynamicAdjustParm|简单找图|SimpleFI|多点找色|MultiplePointsFC|提示|tip\\b"
        },
        {
          "name": "keyword.control.if",
          "match": "\\b如果|否则\\b"
        },
        {
          "name": "constant.language.boolean",
          "match": "(true|false)"
        },
        {
          "match": "\\s*(变量)\\s+(\\S+?)=",
          "captures": {
            "1": {
              "name": "keyword.control.var"
            },
            "2": {
              "name": "variable.name"
            }
          }
        },
        {
          "name": "keyword.operator.new",
          "match": "!"
        }
      ]
    },

    "comment": {
      "begin": "//",
      "end": "\\n",
      "name": "comment.line.double-slash"
    }
  },
  "scopeName": "source.tgs"
}

# 9. 参考

本章目录