3.0.0
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# TSL Tools for Vim
|
||||
|
||||
<p align="left">
|
||||
<strong>强大的 TSL 语言开发工具集</strong><br>
|
||||
为 VSCode 提供完整的 TSL 语言支持
|
||||
</p>
|
||||
<p align="left">
|
||||
<img src="https://img.shields.io/badge/Vim-%3E%3D9.0-green.svg" alt="Vim">
|
||||
</p>
|
||||
|
||||
## 🚀 快速安装
|
||||
|
||||
### 1️⃣ 基础语法高亮
|
||||
|
||||
#### 手动安装
|
||||
|
||||
```bash
|
||||
# 创建语法目录(如果不存在)
|
||||
mkdir -p ~/.vim/syntax/
|
||||
|
||||
# 复制语法文件
|
||||
cp vim/tsl.vim ~/.vim/syntax/
|
||||
```
|
||||
|
||||
#### 配置文件关联
|
||||
|
||||
在你的 `~/.vimrc`
|
||||
|
||||
```vim
|
||||
" 自动识别 .tsl 和 .tsf 文件
|
||||
autocmd BufNewFile,BufRead *.ts[lf] setf tsl
|
||||
|
||||
" 或者分开设置
|
||||
autocmd BufNewFile,BufRead *.tsl setf tsl
|
||||
autocmd BufNewFile,BufRead *.tsf setf tsl
|
||||
```
|
||||
|
||||
### 2️⃣ LSP 语言服务器配置
|
||||
|
||||
TSL 提供完整的 LSP 支持,包括代码补全、错误检查、跳转定义等功能。
|
||||
|
||||
#### 使用 coc.nvim
|
||||
|
||||
编辑 `~/.vim/coc-settings.json` 或运行 `:CocConfig`:
|
||||
|
||||
```json
|
||||
{
|
||||
"languageserver": {
|
||||
"tsl-server": {
|
||||
"command": "tsl-server",
|
||||
"args": ["--log=info", "--log=stderr", "--interpreter=~/tsl64"],
|
||||
"filetypes": ["tsl", "tsf"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| 参数 | 说明 | 默认值 |
|
||||
| -------------------- | -------------------------------- | -------- |
|
||||
| `--log` | 日志级别 (trace/info/warn/error) | `info` |
|
||||
| `--log-stderr` | 输出日志到标准错误 | - |
|
||||
| `--log-file=PATH` | 输出日志到文件 | - |
|
||||
| `--interpreter=PATH` | TSL 解释器路径 | 自动检测 |
|
||||
|
||||
更多参数使用`tsl-server --help`获取
|
||||
|
||||
### 3️⃣ 代码片段配置
|
||||
|
||||
#### coc-snippets
|
||||
|
||||
1. 安装 coc-snippets:
|
||||
|
||||
```vim
|
||||
:CocInstall coc-snippets
|
||||
```
|
||||
|
||||
2. 配置片段文件路径:
|
||||
|
||||
```json
|
||||
{
|
||||
"snippets.textmateSnippetsRoots": ["~/.vim/snippets"]
|
||||
}
|
||||
```
|
||||
+287
@@ -0,0 +1,287 @@
|
||||
{
|
||||
"If Statement": {
|
||||
"prefix": "if",
|
||||
"body": [
|
||||
"if ${1:condition} then",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "If statement"
|
||||
},
|
||||
"If-Else Statement": {
|
||||
"prefix": "ifelse",
|
||||
"body": [
|
||||
"if ${1:condition} then",
|
||||
"begin",
|
||||
"\t$2",
|
||||
"end",
|
||||
"else",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "If-else statement"
|
||||
},
|
||||
"If-ElseIf-Else Statement": {
|
||||
"prefix": "ifelif",
|
||||
"body": [
|
||||
"if ${1:condition1} then",
|
||||
"begin",
|
||||
"\t$2",
|
||||
"end",
|
||||
"else if ${3:condition2} then",
|
||||
"begin",
|
||||
"\t$4",
|
||||
"end",
|
||||
"else",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "If-elseif-else statement"
|
||||
},
|
||||
"For Loop (To)": {
|
||||
"prefix": "for",
|
||||
"body": [
|
||||
"for ${1:i} := ${2:0} to ${3:10} do",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "For loop with counter"
|
||||
},
|
||||
"For Loop (DownTo)": {
|
||||
"prefix": "fordown",
|
||||
"body": [
|
||||
"for ${1:i} := ${2:10} downto ${3:0} do",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "For loop with counter (downto)"
|
||||
},
|
||||
"For-In Loop": {
|
||||
"prefix": "forin",
|
||||
"body": [
|
||||
"for ${1:key}, ${2:value} in ${3:collection} do",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "For-in loop"
|
||||
},
|
||||
"While Loop": {
|
||||
"prefix": "while",
|
||||
"body": [
|
||||
"while ${1:condition} do",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "While loop"
|
||||
},
|
||||
"Repeat-Until Loop": {
|
||||
"prefix": "repeat",
|
||||
"body": [
|
||||
"repeat",
|
||||
"\t$0",
|
||||
"until ${1:condition};"
|
||||
],
|
||||
"description": "Repeat-until loop"
|
||||
},
|
||||
"Case Statement": {
|
||||
"prefix": "case",
|
||||
"body": [
|
||||
"case ${1:expression} of",
|
||||
"\t${2:value1}:",
|
||||
"\tbegin",
|
||||
"\t\t${3:statements}",
|
||||
"\tend;",
|
||||
"\t${4:value2}:",
|
||||
"\tbegin",
|
||||
"\t\t${5:statements}",
|
||||
"\tend;",
|
||||
"else",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end",
|
||||
"end;"
|
||||
],
|
||||
"description": "Case statement"
|
||||
},
|
||||
"Try-Except Block": {
|
||||
"prefix": "try",
|
||||
"body": [
|
||||
"try",
|
||||
"\t$1",
|
||||
"except",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Try-except block"
|
||||
},
|
||||
"Function Declaration": {
|
||||
"prefix": "funcdecl",
|
||||
"body": [
|
||||
"function ${1:functionName}(${2:})${3:: ${4:returnType}};$0"
|
||||
],
|
||||
"description": "Function declaration only"
|
||||
},
|
||||
"Function Implementation": {
|
||||
"prefix": "func",
|
||||
"body": [
|
||||
"function ${1:functionName}(${2:})${3:: ${4:returnType}};",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Function implementation"
|
||||
},
|
||||
"Function with Parameters": {
|
||||
"prefix": "funcparam",
|
||||
"body": [
|
||||
"function ${1:functionName}(${2:param1}: ${3:type1}; ${4:param2}: ${5:type2})${6:: ${7:returnType}};",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Function with typed parameters"
|
||||
},
|
||||
"Function with Var Parameters": {
|
||||
"prefix": "funcvar",
|
||||
"body": [
|
||||
"function ${1:functionName}(var ${2:param1}: ${3:type1}; ${4:param2}: ${5:type2})${6:: ${7:returnType}};",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Function with var/out parameters"
|
||||
},
|
||||
"Anonymous Function": {
|
||||
"prefix": "anonfunc",
|
||||
"body": [
|
||||
"function(${1:})${2:: ${3:returnType}}",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end"
|
||||
],
|
||||
"description": "Anonymous function"
|
||||
},
|
||||
"Unit Module": {
|
||||
"prefix": "unit",
|
||||
"body": [
|
||||
"unit ${1:UnitName};",
|
||||
"",
|
||||
"interface",
|
||||
"\t$2",
|
||||
"",
|
||||
"implementation",
|
||||
"\t$0",
|
||||
"",
|
||||
"end."
|
||||
],
|
||||
"description": "Unit module structure"
|
||||
},
|
||||
"Unit with Initialization": {
|
||||
"prefix": "unitfull",
|
||||
"body": [
|
||||
"unit ${1:UnitName};",
|
||||
"",
|
||||
"interface",
|
||||
"\t${2:// public declarations}",
|
||||
"",
|
||||
"implementation",
|
||||
"\t${3:// implementation}",
|
||||
"",
|
||||
"initialization",
|
||||
"\t${4:// initialization code}",
|
||||
"",
|
||||
"finalization",
|
||||
"\t${5:// cleanup code}",
|
||||
"",
|
||||
"end."
|
||||
],
|
||||
"description": "Complete unit with initialization and finalization"
|
||||
},
|
||||
"Class Definition": {
|
||||
"prefix": "class",
|
||||
"body": [
|
||||
"type ${1:ClassName} = class${2:(${3:ParentClass})}",
|
||||
"\t${4:public}",
|
||||
"\t\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Class definition"
|
||||
},
|
||||
"Class with Public/Private": {
|
||||
"prefix": "classfull",
|
||||
"body": [
|
||||
"type ${1:ClassName} = class${2:(${3:ParentClass})}",
|
||||
"\tpublic",
|
||||
"\t\tfunction ${4:methodName}(${5:})${6:: ${7:returnType}};",
|
||||
"\t\t$0",
|
||||
"\tprotected",
|
||||
"\t\t",
|
||||
"\tprivate",
|
||||
"\t\t",
|
||||
"end;"
|
||||
],
|
||||
"description": "Class with public/protected/private sections"
|
||||
},
|
||||
"Class Method Implementation": {
|
||||
"prefix": "classmethod",
|
||||
"body": [
|
||||
"function ${1:ClassName}.${2:methodName}(${3:})${4:: ${5:returnType}};",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Class method implementation"
|
||||
},
|
||||
"Class Method with Override": {
|
||||
"prefix": "methodoverride",
|
||||
"body": [
|
||||
"function ${1:methodName}(${2:})${3:: ${4:returnType}};",
|
||||
"override;",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Override method in class"
|
||||
},
|
||||
"Class Method with Virtual": {
|
||||
"prefix": "methodvirtual",
|
||||
"body": [
|
||||
"function ${1:methodName}(${2:})${3:: ${4:returnType}};",
|
||||
"virtual;",
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end;"
|
||||
],
|
||||
"description": "Virtual method in class"
|
||||
},
|
||||
"Property Declaration": {
|
||||
"prefix": "prop",
|
||||
"body": [
|
||||
"property ${1:propertyName}: ${2:type} read ${3:getter} write ${4:setter};$0"
|
||||
],
|
||||
"description": "Property with getter and setter"
|
||||
},
|
||||
"Property Read Only": {
|
||||
"prefix": "propread",
|
||||
"body": [
|
||||
"property ${1:propertyName}: ${2:type} read ${3:getter};$0"
|
||||
],
|
||||
"description": "Read-only property"
|
||||
},
|
||||
"Begin-End Block": {
|
||||
"prefix": "begin",
|
||||
"body": [
|
||||
"begin",
|
||||
"\t$0",
|
||||
"end"
|
||||
],
|
||||
"description": "Begin-end block"
|
||||
}
|
||||
}
|
||||
+31
-46
@@ -69,52 +69,40 @@ syn keyword tslMathConstant inf nan
|
||||
# todo
|
||||
syn keyword tslTodo FIXME NOTE NOTES TODO XXX contained
|
||||
|
||||
# Identifier
|
||||
syn match tslIdentifier '\h\w*'
|
||||
|
||||
# Operators and delimiters
|
||||
syn match tslOperator '[+\-*/<>=!&|^~%]'
|
||||
syn match tslDelimiter '[,;:.@?$]'
|
||||
|
||||
# Function definitions
|
||||
syn match tslFuncName '\%(\h\w*\.\)\?\h\w*' contained nextgroup=tslFuncParams skipwhite contains=tslTypeNameInFunc,tslDotInFunc
|
||||
syn match tslTypeNameInFunc '\h\w*\ze\.\h\w*' contained
|
||||
syn match tslDotInFunc '\.' contained
|
||||
syn match tslFuncName '\.\@<=\h\w*' contained
|
||||
|
||||
syn region tslFuncParams
|
||||
\ matchgroup=Delimiter
|
||||
\ start='('
|
||||
\ end=')'
|
||||
\ contained
|
||||
\ contains=tslParam,tslParamType,tslParamSep,tslNumber,tslString,tslPropertyChain
|
||||
\ contains=tslParam,tslParamType,tslParamSep,tslNumber,tslString,tslPropertyChain,tslOperator
|
||||
\ nextgroup=tslReturnType skipwhite
|
||||
|
||||
syn match tslParam '\h\w*' contained nextgroup=tslParamType skipnl skipwhite
|
||||
syn match tslParam '\h\w*' contained nextgroup=tslParamType skipwhite
|
||||
syn match tslParamType ':\s*[^;,)=]*' contained contains=tslColon
|
||||
syn match tslReturnType ':\s*[^;]*' contained contains=tslColon
|
||||
syn match tslParamSep '[;,]' contained
|
||||
syn match tslColon ':' contained
|
||||
|
||||
# Property chain
|
||||
syn match tslPropertyChain '\h\w*\%(\.\h\w*\)\+\>' contains=tslObjectName,tslPropertyDot,tslPropertyName
|
||||
syn match tslObjectName '\h\w*\ze\.\h\w*' contained
|
||||
syn match tslPropertyChain '\.\h\w*' contains=tslPropertyDot,tslPropertyName
|
||||
syn match tslPropertyDot '\.' contained
|
||||
syn match tslPropertyName '\.\@<=\h\w*\%(\ze\.\|\ze\s*[^(]\|\ze\s*$\)' contained
|
||||
syn match tslPropertyName '\h\w*' contained
|
||||
|
||||
# Function calls
|
||||
syn match tslFuncCallName '\%(\<\%(function\|procedure\)\s\+\%(\h\w*\.\)\?\)\@<!\h\w*\ze\s*('
|
||||
\ containedin=ALLBUT,tslFuncParams,tslPropertyChain,tslFunction,tslFuncName,tslFuncNamePart,tslComment,tslString,tslRawString
|
||||
syn match tslFuncCallName '\h\w*\ze\s*(' containedin=tslPropertyChain
|
||||
|
||||
syn region tslFuncCall
|
||||
\ start='\h\w*\s*(\zs'
|
||||
\ end='\ze)'
|
||||
\ contains=tslFuncCallName,tslFuncCall,tslNamedParam,tslPositionalParam,tslString,tslRawString,tslNumber,tslIdentifier,tslOperator,tslParamSep
|
||||
\ transparent
|
||||
|
||||
syn match tslNamedParam '\%((\|;\s*\)\zs\h\w*\s*:\s*[^;,)]*' contained
|
||||
\ contains=tslParamName,tslParamColon,tslParamValue
|
||||
|
||||
syn match tslParamName '\h\w*\ze\s*:' contained
|
||||
syn match tslParamColon ':' contained
|
||||
syn match tslParamValue ':\s*\zs[^;,)]*' contained
|
||||
\ contains=tslString,tslNumber,tslIdentifier,tslOperator,tslFuncCall,tslFuncCallName
|
||||
|
||||
syn match tslPositionalParam '[^;,():]*' contained
|
||||
\ contains=tslString,tslNumber,tslIdentifier,tslOperator,tslFuncCall,tslFuncCallName
|
||||
|
||||
# Variable declaration
|
||||
syn match tslVarDeclWithTag '\]\@<=\s*\h\w*\ze\s*:\%(=\)\@!'
|
||||
@@ -131,29 +119,30 @@ syn region tslVarTypeDecl
|
||||
\ contained keepend oneline
|
||||
\ contains=tslVarType
|
||||
syn match tslVarType '[^;]*' contained
|
||||
|
||||
# Operators and delimiters
|
||||
syn match tslOperator '[+\-*/<>=!&|^~%]'
|
||||
syn match tslDelimiter '[()[\]{},;:.@?]'
|
||||
# 冒号的情况
|
||||
# 1. 简单赋值a := 1; 不需要匹配
|
||||
# 2. 三元表达式a ? b : c; 不需要匹配
|
||||
# 3. 普通类型变量声明 a: string; b: array of number; c: obj.A; 匹配:;中的字符,包括.和空格
|
||||
# 4. 声明类型时候有tag,比如[werkref]a: string; 不需要匹配[xxx],只需要和3一样匹配
|
||||
# 5. 变量声明时候带初始化a: number = 1; :=之间的内容是类型,=之后的内容由tslnumber,tslstring等匹配
|
||||
# 6. gloabl var 等是关键字,global a: string = "123"; 不能把global匹配为identifier
|
||||
# 7. 多变量声明, global a, b: number = 1; // 需要匹配的类型是: =之间的number
|
||||
# 8. 不能匹配到函数调用的指定参数模式func(a: 123; b: "sss");
|
||||
|
||||
# Comments
|
||||
syn match tslComment '//.*$' contains=tslTodo,@Spell
|
||||
syn region tslComment start='(\*' end='\*)' contains=tslTodo,@Spell keepend
|
||||
syn region tslComment start='{' end='}' contains=tslTodo,@Spell keepend
|
||||
syn region tslComment start='(\*' end='\*)' contains=tslTodo,@Spell keepend
|
||||
|
||||
# Strings
|
||||
syn region tslString start=+[uU]\=\z(['"]\)+ end='\z1' skip='\\\\\|\\\z1'
|
||||
syn region tslRawString start=+[uU]\=[rR]\z(['"]\)+ end='\z1' skip='\\\\\|\\\z1'
|
||||
syn region tslString start=+[uU]\=\z(['"]\)+ end='\z1' skip='\\\z1'
|
||||
syn region tslRawString start=+[uU]\=[rR]\z(['"]\)+ end='\z1'
|
||||
|
||||
# Numbers
|
||||
syn match tslNumber '\<0[oO]\=\o\+[Ll]\=\>'
|
||||
syn match tslNumber '\<0[xX]\x\+[Ll]\=\>'
|
||||
syn match tslNumber '\<0[oO]\o\+[Ll]\=\>'
|
||||
syn match tslNumber '\<0[bB][01]\+[Ll]\=\>'
|
||||
syn match tslNumber '\<\%([1-9]\d*\|0\)[Ll]\=\>'
|
||||
syn match tslNumber '\<\d\+[jJ]\>'
|
||||
syn match tslNumber '\<\d\+[eE][+-]\=\d\+[jJ]\=\>'
|
||||
syn match tslNumber '\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@='
|
||||
syn match tslNumber '\%(^\|\W\)\zs\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>'
|
||||
syn match tslNumber '\<\d\+\%(\.\d*\)\=\%([eE][+-]\=\d\+\)\=[jJlL]\=\>'
|
||||
|
||||
|
||||
# Highlight links
|
||||
@@ -161,7 +150,7 @@ hi def link tslProgramStructure Statement
|
||||
hi def link tslModuleStructure Statement
|
||||
hi def link tslPrimitiveType Type
|
||||
hi def link tslClassType Statement
|
||||
hi def link tslClassModifier Identifier
|
||||
hi def link tslClassModifier StorageClass
|
||||
hi def link tslAccessModifier Statement
|
||||
hi def link tslPropertyAccessor Operator
|
||||
hi def link tslConstructor Special
|
||||
@@ -185,16 +174,16 @@ hi def link tslSqlOperator Special
|
||||
hi def link tslSystemKeyword Special
|
||||
hi def link tslCallingConvention Special
|
||||
hi def link tslBuiltinVar Constant
|
||||
hi def link tslBuiltinFunction Constant
|
||||
hi def link tslBuiltinFunction Special
|
||||
hi def link tslBoolean Boolean
|
||||
hi def link tslNull Constant
|
||||
hi def link tslMathConstant Number
|
||||
|
||||
# 其他元素的高亮链接保持不变
|
||||
hi def link tslObjectName Type
|
||||
hi def link tslPropertyDot Operator
|
||||
hi def link tslPropertyName Special
|
||||
|
||||
hi def link tslFuncCallName Function
|
||||
|
||||
hi def link tslFuncName Function
|
||||
hi def link tslTypeNameInFunc Type
|
||||
hi def link tslParam Identifier
|
||||
@@ -206,11 +195,7 @@ hi def link tslColon Delimiter
|
||||
hi def link tslVarName Identifier
|
||||
hi def link tslVarType Type
|
||||
|
||||
hi def link tslFuncCallName Function
|
||||
hi def link tslCallParam Identifier
|
||||
hi def link tslCallValue Type
|
||||
hi def link tslCallSep Delimiter
|
||||
|
||||
hi def link tslIdentifier PreProc
|
||||
hi def link tslOperator Operator
|
||||
hi def link tslDelimiter Delimiter
|
||||
hi def link tslTodo Todo
|
||||
|
||||
Reference in New Issue
Block a user