♻️ refactor(lsp_server): move entrypoints out of named modules
- export Run() from launcher module and add non-module main TU - apply same pattern to module-based test executables - migrate utils/string implementation fully into string.cppm and drop string.cpp - point clangd to linux build compilation database
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
@@ -0,0 +1,6 @@
|
||||
import lsp.cli.launcher;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return Run(argc, argv);
|
||||
}
|
||||
@@ -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<unsigned char>(str[i])) !=
|
||||
std::tolower(static_cast<unsigned char>(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<unsigned char>(str[offset + i])) !=
|
||||
std::tolower(static_cast<unsigned char>(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<unsigned char>(a[i]));
|
||||
int cb = std::tolower(static_cast<unsigned char>(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;
|
||||
}
|
||||
}
|
||||
@@ -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<unsigned char>(str[i])) !=
|
||||
std::tolower(static_cast<unsigned char>(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<unsigned char>(str[offset + i])) !=
|
||||
std::tolower(static_cast<unsigned char>(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<unsigned char>(a[i]));
|
||||
int cb = std::tolower(static_cast<unsigned char>(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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user