From d9beeb82a6550119ba0a46c3011e04283c91f8b2 Mon Sep 17 00:00:00 2001 From: csh Date: Tue, 24 Jun 2025 18:20:37 +0800 Subject: [PATCH] format cpp and update tsl.vim --- lsp-server/src/lsp/server.cpp | 32 +++++++++++++-------------- test/test.tsl | 7 ++++-- vim/tsl.vim | 41 +++++++++++++++++------------------ 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/lsp-server/src/lsp/server.cpp b/lsp-server/src/lsp/server.cpp index 7d1e9e6..eead953 100644 --- a/lsp-server/src/lsp/server.cpp +++ b/lsp-server/src/lsp/server.cpp @@ -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"); } } diff --git a/test/test.tsl b/test/test.tsl index c66a36e..ecf55f0 100644 --- a/test/test.tsl +++ b/test/test.tsl @@ -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)); diff --git a/vim/tsl.vim b/vim/tsl.vim index 8a2f5ee..26ec6a7 100644 --- a/vim/tsl.vim +++ b/vim/tsl.vim @@ -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*\)\@=!&|^~%]' -syn match tslOperator ':=' syn match tslDelimiter '[()[\]{},;:.@?]' # Comments