diff --git a/lsp-server/.clangd b/lsp-server/.clangd index 9fff263..8acae65 100644 --- a/lsp-server/.clangd +++ b/lsp-server/.clangd @@ -1,5 +1,9 @@ +CompileFlags: + CompilationDatabase: build/clang-linux/Release + +--- If: - PathMatch: [.*\.hpp, .*\.cpp] + PathMatch: [.*\.hpp, .*\.hxx, .*\.cpp, .*\.cc, .*\.cxx, .*\.cppm, .*\.ixx, .*\.mpp] CompileFlags: Add: diff --git a/lsp-server/src/CMakeLists.txt b/lsp-server/src/CMakeLists.txt index b898c02..d570b39 100644 --- a/lsp-server/src/CMakeLists.txt +++ b/lsp-server/src/CMakeLists.txt @@ -41,9 +41,9 @@ endif() set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) set(SOURCES - main.cppm + cli/launcher.cppm + main.cc utils/args_parser.cppm - utils/string.cpp utils/text_coordinates.cppm core/dispacther.cppm core/server.cppm @@ -86,7 +86,7 @@ target_sources( bridge/spdlog.cppm bridge/taskflow.cppm bridge/tree_sitter.cppm - main.cppm + cli/launcher.cppm language/ast/ast.cppm language/ast/types.cppm language/ast/deserializer.cppm diff --git a/lsp-server/src/main.cppm b/lsp-server/src/cli/launcher.cppm similarity index 93% rename from lsp-server/src/main.cppm rename to lsp-server/src/cli/launcher.cppm index b2c0fc5..5bc23bd 100644 --- a/lsp-server/src/main.cppm +++ b/lsp-server/src/cli/launcher.cppm @@ -1,14 +1,14 @@ module; +export module lsp.cli.launcher; -export module lsp.main; import spdlog; - import std; + import lsp.core.server; import lsp.utils.args_parser; -int main(int argc, char* argv[]) +export int Run(int argc, char* argv[]) { lsp::utils::ArgsParser& args_parser = lsp::utils::ArgsParser::Instance(); auto& config = args_parser.Parse(argc, argv); diff --git a/lsp-server/src/main.cc b/lsp-server/src/main.cc new file mode 100644 index 0000000..0a9d298 --- /dev/null +++ b/lsp-server/src/main.cc @@ -0,0 +1,6 @@ +import lsp.cli.launcher; + +int main(int argc, char* argv[]) +{ + return Run(argc, argv); +} diff --git a/lsp-server/src/utils/string.cpp b/lsp-server/src/utils/string.cpp deleted file mode 100644 index e12cea9..0000000 --- a/lsp-server/src/utils/string.cpp +++ /dev/null @@ -1,130 +0,0 @@ -module; - -import std; - -module lsp.utils.string; - -namespace lsp::utils -{ - std::string Trim(const std::string& str) - { - std::size_t first = str.find_first_not_of(" \t\n\r"); - if (first == std::string::npos) - return ""; - std::size_t last = str.find_last_not_of(" \t\n\r"); - return str.substr(first, last - first + 1); - } - - std::string ToLower(const std::string& str) - { - std::string result = str; - std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return std::tolower(c); }); - return result; - } - - std::string ToUpper(const std::string& str) - { - std::string result = str; - std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return std::toupper(c); }); - return result; - } - - bool StartsWith(const std::string& str, const std::string& prefix) - { - if (prefix.size() > str.size()) - return false; - return str.compare(0, prefix.size(), prefix) == 0; - } - - bool EndsWith(const std::string& str, const std::string& suffix) - { - if (suffix.size() > str.size()) - return false; - return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; - } - - // ==================== 大小写不敏感比较 ==================== - bool IEquals(const std::string& a, const std::string& b) - { - if (a.size() != b.size()) - return false; - - return std::equal(a.begin(), a.end(), b.begin(), [](unsigned char ca, unsigned char cb) { - return std::tolower(ca) == std::tolower(cb); - }); - } - - bool IStartsWith(const std::string& str, const std::string& prefix) - { - if (prefix.size() > str.size()) - return false; - - for (std::size_t i = 0; i < prefix.size(); ++i) - { - if (std::tolower(static_cast(str[i])) != - std::tolower(static_cast(prefix[i]))) - return false; - } - return true; - } - - bool IEndsWith(const std::string& str, const std::string& suffix) - { - if (suffix.size() > str.size()) - return false; - - std::size_t offset = str.size() - suffix.size(); - for (std::size_t i = 0; i < suffix.size(); ++i) - { - if (std::tolower(static_cast(str[offset + i])) != - std::tolower(static_cast(suffix[i]))) - return false; - } - return true; - } - - int ICompare(const std::string& a, const std::string& b) - { - std::size_t min_len = std::min(a.size(), b.size()); - - for (std::size_t i = 0; i < min_len; ++i) - { - int ca = std::tolower(static_cast(a[i])); - int cb = std::tolower(static_cast(b[i])); - - if (ca != cb) - return ca - cb; - } - - // 长度不同 - if (a.size() < b.size()) - return -1; - if (a.size() > b.size()) - return 1; - - return 0; - } - - std::size_t IHash(const std::string& str) - { - std::size_t hash = 0; - for (unsigned char c : str) - hash = hash * 31 + std::tolower(c); - return hash; - } - - std::size_t IHasher::operator()(const std::string& key) const - { - return IHash(key); - } - - bool IEqualTo::operator()(const std::string& a, const std::string& b) const - { - return IEquals(a, b); - } - - bool ILess::operator()(const std::string& a, const std::string& b) const - { - return ICompare(a, b) < 0; - } -} diff --git a/lsp-server/src/utils/string.cppm b/lsp-server/src/utils/string.cppm index 38dcbbf..64c18ec 100644 --- a/lsp-server/src/utils/string.cppm +++ b/lsp-server/src/utils/string.cppm @@ -38,3 +38,126 @@ export namespace lsp::utils bool operator()(const std::string& a, const std::string& b) const; }; } + +namespace lsp::utils +{ + std::string Trim(const std::string& str) + { + std::size_t first = str.find_first_not_of(" \t\n\r"); + if (first == std::string::npos) + return ""; + std::size_t last = str.find_last_not_of(" \t\n\r"); + return str.substr(first, last - first + 1); + } + + std::string ToLower(const std::string& str) + { + std::string result = str; + std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return std::tolower(c); }); + return result; + } + + std::string ToUpper(const std::string& str) + { + std::string result = str; + std::transform(result.begin(), result.end(), result.begin(), [](unsigned char c) { return std::toupper(c); }); + return result; + } + + bool StartsWith(const std::string& str, const std::string& prefix) + { + if (prefix.size() > str.size()) + return false; + return str.compare(0, prefix.size(), prefix) == 0; + } + + bool EndsWith(const std::string& str, const std::string& suffix) + { + if (suffix.size() > str.size()) + return false; + return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; + } + + bool IEquals(const std::string& a, const std::string& b) + { + if (a.size() != b.size()) + return false; + + return std::equal(a.begin(), a.end(), b.begin(), [](unsigned char ca, unsigned char cb) { + return std::tolower(ca) == std::tolower(cb); + }); + } + + bool IStartsWith(const std::string& str, const std::string& prefix) + { + if (prefix.size() > str.size()) + return false; + + for (std::size_t i = 0; i < prefix.size(); ++i) + { + if (std::tolower(static_cast(str[i])) != + std::tolower(static_cast(prefix[i]))) + return false; + } + return true; + } + + bool IEndsWith(const std::string& str, const std::string& suffix) + { + if (suffix.size() > str.size()) + return false; + + std::size_t offset = str.size() - suffix.size(); + for (std::size_t i = 0; i < suffix.size(); ++i) + { + if (std::tolower(static_cast(str[offset + i])) != + std::tolower(static_cast(suffix[i]))) + return false; + } + return true; + } + + int ICompare(const std::string& a, const std::string& b) + { + std::size_t min_len = std::min(a.size(), b.size()); + + for (std::size_t i = 0; i < min_len; ++i) + { + int ca = std::tolower(static_cast(a[i])); + int cb = std::tolower(static_cast(b[i])); + + if (ca != cb) + return ca - cb; + } + + if (a.size() < b.size()) + return -1; + if (a.size() > b.size()) + return 1; + + return 0; + } + + std::size_t IHash(const std::string& str) + { + std::size_t hash = 0; + for (unsigned char c : str) + hash = hash * 31 + std::tolower(c); + return hash; + } + + std::size_t IHasher::operator()(const std::string& key) const + { + return IHash(key); + } + + bool IEqualTo::operator()(const std::string& a, const std::string& b) const + { + return IEquals(a, b); + } + + bool ILess::operator()(const std::string& a, const std::string& b) const + { + return ICompare(a, b) < 0; + } +} diff --git a/lsp-server/test/test_ast/CMakeLists.txt b/lsp-server/test/test_ast/CMakeLists.txt index 0f552a9..e85fed5 100644 --- a/lsp-server/test/test_ast/CMakeLists.txt +++ b/lsp-server/test/test_ast/CMakeLists.txt @@ -18,10 +18,10 @@ endif() set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) set(SOURCES + main.cc test.cppm debug_printer.cppm ../../src/utils/string.cppm - ../../src/utils/string.cpp ../../src/tree-sitter/scanner.c ../../src/tree-sitter/parser.c) diff --git a/lsp-server/test/test_ast/main.cc b/lsp-server/test/test_ast/main.cc new file mode 100644 index 0000000..c7a518f --- /dev/null +++ b/lsp-server/test/test_ast/main.cc @@ -0,0 +1,6 @@ +import lsp.test.ast.main; + +int main(int argc, char* argv[]) +{ + return Run(argc, argv); +} diff --git a/lsp-server/test/test_ast/test.cppm b/lsp-server/test/test_ast/test.cppm index cef4347..5079ca5 100644 --- a/lsp-server/test/test_ast/test.cppm +++ b/lsp-server/test/test_ast/test.cppm @@ -120,7 +120,7 @@ void PrintUsage(const char* program_name) std::cout << " " << program_name << " test.tsf -s -n # Show source without colors\n"; } -int main(int argc, char* argv[]) +export int Run(int argc, char* argv[]) { if (argc < 2) { diff --git a/lsp-server/test/test_lsp_any/CMakeLists.txt b/lsp-server/test/test_lsp_any/CMakeLists.txt index 23ecb26..25c3211 100644 --- a/lsp-server/test/test_lsp_any/CMakeLists.txt +++ b/lsp-server/test/test_lsp_any/CMakeLists.txt @@ -13,6 +13,7 @@ if(UNIX AND NOT APPLE) endif() set(SOURCES + main.cc test_main.cppm) add_executable(${PROJECT_NAME} ${SOURCES}) diff --git a/lsp-server/test/test_lsp_any/main.cc b/lsp-server/test/test_lsp_any/main.cc new file mode 100644 index 0000000..528fb69 --- /dev/null +++ b/lsp-server/test/test_lsp_any/main.cc @@ -0,0 +1,6 @@ +import lsp.test.lsp_any.main; + +int main() +{ + return Run(); +} diff --git a/lsp-server/test/test_lsp_any/test_main.cppm b/lsp-server/test/test_lsp_any/test_main.cppm index 9827745..6cbdca7 100644 --- a/lsp-server/test/test_lsp_any/test_main.cppm +++ b/lsp-server/test/test_lsp_any/test_main.cppm @@ -10,7 +10,7 @@ import lsp.test.lsp_any.transformer; import lsp.test.lsp_any.facade; import lsp.test.lsp_any.common; -int main() +export int Run() { lsp::test::TestRunner runner; diff --git a/lsp-server/test/test_module/CMakeLists.txt b/lsp-server/test/test_module/CMakeLists.txt index 6425253..a2bed83 100644 --- a/lsp-server/test/test_module/CMakeLists.txt +++ b/lsp-server/test/test_module/CMakeLists.txt @@ -12,7 +12,7 @@ endif() set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) -add_executable(test_module main.cppm) +add_executable(test_module main.cppm main.cc) target_sources( test_module PRIVATE diff --git a/lsp-server/test/test_module/main.cc b/lsp-server/test/test_module/main.cc new file mode 100644 index 0000000..cbee99f --- /dev/null +++ b/lsp-server/test/test_module/main.cc @@ -0,0 +1,6 @@ +import lsp.test.module_demo.main; + +int main() +{ + return Run(); +} diff --git a/lsp-server/test/test_module/main.cppm b/lsp-server/test/test_module/main.cppm index 81f2787..994e1fb 100644 --- a/lsp-server/test/test_module/main.cppm +++ b/lsp-server/test/test_module/main.cppm @@ -7,7 +7,7 @@ import std; import math; import math2; -int main() +export int Run() { std::cout << "hello std module\n"; std::vector v{ 1, 2, 3 }; diff --git a/lsp-server/test/test_scheduler/CMakeLists.txt b/lsp-server/test/test_scheduler/CMakeLists.txt index 5dbcf3b..7bbd185 100644 --- a/lsp-server/test/test_scheduler/CMakeLists.txt +++ b/lsp-server/test/test_scheduler/CMakeLists.txt @@ -15,6 +15,7 @@ if(UNIX AND NOT APPLE) endif() set(SOURCES + main.cc test_async_executor.cppm) add_executable(${PROJECT_NAME} ${SOURCES}) diff --git a/lsp-server/test/test_scheduler/main.cc b/lsp-server/test/test_scheduler/main.cc new file mode 100644 index 0000000..cda47a5 --- /dev/null +++ b/lsp-server/test/test_scheduler/main.cc @@ -0,0 +1,6 @@ +import lsp.test.scheduler.async_executor; + +int main() +{ + return Run(); +} diff --git a/lsp-server/test/test_scheduler/test_async_executor.cppm b/lsp-server/test/test_scheduler/test_async_executor.cppm index d8907ac..da61ba1 100644 --- a/lsp-server/test/test_scheduler/test_async_executor.cppm +++ b/lsp-server/test/test_scheduler/test_async_executor.cppm @@ -55,7 +55,7 @@ namespace }; } -int main() +export int Run() { SchedulerTestSuite suite; diff --git a/lsp-server/test/test_semantic/CMakeLists.txt b/lsp-server/test/test_semantic/CMakeLists.txt index dd31704..ac6cf80 100644 --- a/lsp-server/test/test_semantic/CMakeLists.txt +++ b/lsp-server/test/test_semantic/CMakeLists.txt @@ -17,9 +17,9 @@ endif() set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) set(SOURCES + main.cc test_semantic.cppm ../../src/utils/string.cppm - ../../src/utils/string.cpp ../../src/language/symbol/internal/builder.cppm ../../src/language/symbol/internal/store.cppm ../../src/language/symbol/internal/table.cppm diff --git a/lsp-server/test/test_semantic/main.cc b/lsp-server/test/test_semantic/main.cc new file mode 100644 index 0000000..1feb846 --- /dev/null +++ b/lsp-server/test/test_semantic/main.cc @@ -0,0 +1,6 @@ +import lsp.test.semantic.main; + +int main(int argc, char** argv) +{ + return Run(argc, argv); +} diff --git a/lsp-server/test/test_semantic/test_semantic.cppm b/lsp-server/test/test_semantic/test_semantic.cppm index 42d24a0..739cbb4 100644 --- a/lsp-server/test/test_semantic/test_semantic.cppm +++ b/lsp-server/test/test_semantic/test_semantic.cppm @@ -436,7 +436,7 @@ namespace } } -int main(int argc, char** argv) +export int Run(int argc, char** argv) { try { diff --git a/lsp-server/test/test_symbol/CMakeLists.txt b/lsp-server/test/test_symbol/CMakeLists.txt index bdb9de9..26b04b6 100644 --- a/lsp-server/test/test_symbol/CMakeLists.txt +++ b/lsp-server/test/test_symbol/CMakeLists.txt @@ -18,9 +18,9 @@ endif() set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) set(SOURCES + main.cc test.cppm ../../src/utils/string.cppm - ../../src/utils/string.cpp ../../src/language/symbol/internal/builder.cppm ../../src/language/symbol/internal/store.cppm ../../src/language/symbol/internal/table.cppm diff --git a/lsp-server/test/test_symbol/main.cc b/lsp-server/test/test_symbol/main.cc new file mode 100644 index 0000000..7bab46e --- /dev/null +++ b/lsp-server/test/test_symbol/main.cc @@ -0,0 +1,6 @@ +import lsp.test.symbol.main; + +int main(int argc, char* argv[]) +{ + return Run(argc, argv); +} diff --git a/lsp-server/test/test_symbol/test.cppm b/lsp-server/test/test_symbol/test.cppm index 20131dd..a0a6a25 100644 --- a/lsp-server/test/test_symbol/test.cppm +++ b/lsp-server/test/test_symbol/test.cppm @@ -1050,7 +1050,7 @@ void AnalyzeFile(const Options& options) // ==================== 主程序 ==================== -int main(int argc, char* argv[]) +export int Run(int argc, char* argv[]) { Options options;