format cpp and update tsl.vim

This commit is contained in:
csh 2025-06-24 18:20:37 +08:00
parent b339df7bc5
commit d9beeb82a6
3 changed files with 41 additions and 39 deletions

View File

@ -121,24 +121,24 @@ namespace lsp
log::Debug("Response length: ", byte_length);
log::Debug("Raw response content: [", response_str, "]");
// 在程序启动时设置stdout为二进制模式只需设置一次
static bool binary_mode_set = false;
if (!binary_mode_set) {
// 在程序启动时设置stdout为二进制模式只需设置一次
static bool binary_mode_set = false;
if (!binary_mode_set)
{
#ifdef _WIN32
_setmode(_fileno(stdout), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#endif
binary_mode_set = true;
}
// 构建完整消息
std::string header = "Content-Length: " + std::to_string(byte_length) + "\r\n\r\n";
// 使用 write 系统调用,绕过 C++ 流的缓冲和转换
std::cout.write(header.c_str(), header.length());
std::cout.write(response_str.c_str(), response_str.length());
std::cout.flush();
log::Verbose("Response sent successfully2");
binary_mode_set = true;
}
// 构建完整消息
std::string header = "Content-Length: " + std::to_string(byte_length) + "\r\n\r\n";
// 使用 write 系统调用,绕过 C++ 流的缓冲和转换
std::cout.write(header.c_str(), header.length());
std::cout.write(response_str.c_str(), response_str.length());
std::cout.flush();
log::Verbose("Response sent successfully");
}
}

View File

@ -2,9 +2,11 @@
// 字符串,数字,注释
// 注释 TODO
// abc();
a := "string"; // 字符串
b := 123; // 数字
c := 1.23; // 浮点数
a := "字符串函数func()";
// 类相关
@ -47,13 +49,14 @@ function f(a: real = 1; b: string = "123"; c: number = abc.CONST1): def; // 带
f();
f(a, b);
f(a: 1; b: 's');
f(f(2, "111"));
// 类变量声明,三元表达式(不应该有冲突)
a: string;
[weakref]b: MyClass;
a ? b : c;
a ? b : c ? d : e;
return ifnil(rpr_.Caps) ? false : rpr_.Caps.IsApplied;
// select
Select ["test"] from table end;
@ -62,5 +65,5 @@ select distinct ["test"] from table where ['a'] = 1 end;
// array
a := array(1, 2);
b := array((1, 2), (3, 4))
b := array((1, 2), (3, 4));

View File

@ -13,7 +13,7 @@ syn case ignore
# Keywords
# 程序结构声明
syn keyword tslProgramStructure program function procedure nextgroup=tslFuncName skipwhite
syn keyword tslModuleStructure unit uses implementation interface initalization finalization
syn keyword tslModuleStructure unit uses implementation interface initialization finalization
# 数据类型
syn keyword tslPrimitiveType string integer boolean int64 real array
@ -87,9 +87,9 @@ syn match tslReturnType ':\s*[^;]*' contained contains=tslColon
syn match tslParamSep '[;,]' contained
syn match tslColon ':' contained
syn match tslVarDecl '\(?\s*\)\@<!\h\w*\s*:=\@!\s*[^;?]*;' contains=tslVarName,tslVarType
syn match tslVarName '\(?\s*\)\@<!\h\w*\ze\s*:=\@!' contained
syn match tslVarType ':=\@!\s*[^;?]*' contained contains=tslColon
syn match tslVarDecl '\(?\s\)\@<!\h\w\s:=\@!\s[^;?];' contains=tslVarName,tslVarType
syn match tslVarName '\(?\s\)\@<!\h\w\ze\s:=\@!' contained
syn match tslVarType ':=\@!\s[^;?]' contained contains=tslColon
# 匹配完整的属性链
syn match tslPropertyChain '\h\w*\%(\.\h\w*\)\+' contains=tslObjectName,tslPropertyDot,tslPropertyName
@ -99,31 +99,30 @@ syn match tslPropertyName '\.\@<=\h\w*\%(\ze\.\|\ze\s*[^(]\|\ze\s*$\)' contain
# Function calls
syn match tslFuncCallName '\%(\<\%(function\|procedure\)\s\+\%(\h\w*\.\)\?\)\@<!\h\w*\ze\s*('
\ containedin=ALLBUT,tslFuncParams,tslPropertyChain,tslFunction,tslFuncName,tslFuncNamePart
\ containedin=ALLBUT,tslFuncParams,tslPropertyChain,tslFunction,tslFuncName,tslFuncNamePart,tslComment,tslString,tslRawString
syn region tslFuncCall
\ start='\%(\<\h\w*\s*(\)'
\ end=')'
\ contains=tslCallParams,tslCallSep,tslCallValue,tslCallParam,tslString,tslNumber,tslIdentifier,tslOperator
\ start='\h\w*\s*(\zs'
\ end='\ze)'
\ contains=tslFuncCallName,tslFuncCall,tslNamedParam,tslPositionalParam,tslString,tslRawString,tslNumber,tslIdentifier,tslOperator,tslParamSep
\ transparent
syn region tslCallParams
\ start='\%(\<\h\w*\s*(\)\zs'
\ end='\ze)'
\ contained
\ contains=tslCallParam,tslCallValue,tslCallSep,tslString,tslNumber,tslIdentifier,tslOperator,tslFuncCall
syn match tslNamedParam '\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
syn match tslParamSep '[;,]' contained
syn match tslCallParam '\h\w*\ze\s*:' contained
syn match tslCallValue ':\s*\zs[^;)]*' contained
syn match tslCallValue
\ ':\s*\zs\\%([^;,)]\+\|.\{-}\%([;,)]\|$\))'
\ contained
\ contains=tslString,tslNumber,tslIdentifier,tslOperator,tslFunctionCall
syn match tslCallSep '[;,]' contained
# Operators and delimiters
syn match tslOperator '[+\-*/<>=!&|^~%]'
syn match tslOperator ':='
syn match tslDelimiter '[()[\]{},;:.@?]'
# Comments