支持全局函数补全

This commit is contained in:
csh
2025-09-27 22:23:04 +08:00
parent aac12137cb
commit dc713e6893
220 changed files with 195514 additions and 195869 deletions
+37 -16
View File
@@ -5,36 +5,44 @@
namespace lsp::utils
{
ServerConfig ArgsParser::Parse(int argc, char* argv[])
ArgsParser& ArgsParser::GetInstance()
{
ServerConfig config;
static ArgsParser instance;
return instance;
}
const ServerConfig& ArgsParser::Parse(int argc, char* argv[])
{
config_ = ServerConfig {};
bool use_stdio = false;
for (int i = 1; i < argc; ++i)
{
std::string arg = argv[i];
if (arg == "--help")
{
config.show_help = true;
return config;
config_.show_help = true;
return config_;
}
if (arg == "--log=trace")
config.log_level = spdlog::level::trace;
config_.log_level = spdlog::level::trace;
else if (arg == "--log=debug")
config.log_level = spdlog::level::debug;
config_.log_level = spdlog::level::debug;
else if (arg == "--log=info")
config.log_level = spdlog::level::info;
config_.log_level = spdlog::level::info;
else if (arg == "--log=warn")
config.log_level = spdlog::level::warn;
config_.log_level = spdlog::level::warn;
else if (arg == "--log=error")
config.log_level = spdlog::level::err;
config_.log_level = spdlog::level::err;
else if (arg == "--log=off")
config.log_level = spdlog::level::off;
config_.log_level = spdlog::level::off;
else if (arg.find("--log-file=") == 0)
config.log_file = arg.substr(11);
config_.log_file = arg.substr(11);
else if (arg == "--log-stderr")
config.use_stderr = true;
config_.use_stderr = true;
else if (arg.find("--interpreter=") == 0)
config_.interpreter_path = arg.substr(14);
else if (arg.find("--threads=") == 0)
{
std::string count_str = arg.substr(10);
@@ -46,7 +54,7 @@ namespace lsp::utils
std::cerr << "[TSL-LSP] Error: Thread count must be between 1 and 32" << std::endl;
std::exit(1);
}
config.thread_count = count;
config_.thread_count = count;
}
catch (const std::exception&)
{
@@ -56,7 +64,7 @@ namespace lsp::utils
}
else if (arg == "--stdio")
{
std::cerr << "[TSL-LSP] JosnRPc using stdio" << std::endl;
use_stdio = true;
}
else
{
@@ -64,8 +72,17 @@ namespace lsp::utils
std::cerr << "Use --help for usage information" << std::endl;
}
}
std::cerr << "TSL Language Server " << __DATE__ << std::endl;
if (use_stdio)
std::cerr << "[TSL-LSP] JosnRPc using stdio" << std::endl;
return config;
// config_.interpreter_path = "/mnt/c/Programs/Tinysoft/TSLGen2/";
return config_;
}
const ServerConfig& ArgsParser::GetConfig() const
{
return config_;
}
void ArgsParser::SetupLogger(const ServerConfig& config)
@@ -103,13 +120,17 @@ namespace lsp::utils
hardware_threads = 0; // 表示无法检测
std::cout << "TSL Language Server Protocol (LSP) Server\n"
<< "Version: 1.0.0 (" << __DATE__ << " build)\n"
<< "Version: " << __DATE__ << " build\n"
<< "\n"
<< "Usage: " << program_name << " [options]\n"
<< "\n"
<< "Options:\n"
<< " --help Show this help message and exit\n"
<< "\n"
<< "Interpreter options:\n"
<< " --interpreter=PATH Set path to TSL interpreter executable\n"
<< " Required for some language features\n"
<< "\n"
<< "Logging options:\n"
<< " --log=LEVEL Set log level (trace, debug, info, warn, error, off)\n"
<< " Default: info\n"
+20 -7
View File
@@ -7,17 +7,30 @@ namespace lsp::utils
struct ServerConfig
{
bool use_stderr = false;
std::string log_file;
spdlog::level::level_enum log_level = spdlog::level::info;
size_t thread_count = 4;
bool show_help = false;
size_t thread_count = 4;
spdlog::level::level_enum log_level = spdlog::level::info;
std::string log_file;
std::string interpreter_path;
};
class ArgsParser
{
public:
static ServerConfig Parse(int argc, char* argv[]);
static void SetupLogger(const ServerConfig& config);
static void PrintHelp(const std::string& program_name);
public:
ArgsParser(const ArgsParser&) = delete;
ArgsParser& operator=(const ArgsParser&) = delete;
static ArgsParser& GetInstance();
const ServerConfig& Parse(int argc, char* argv[]);
const ServerConfig& GetConfig() const;
static void SetupLogger(const ServerConfig& config);
static void PrintHelp(const std::string& program_name);
private:
ArgsParser() = default;
~ArgsParser() = default;
ServerConfig config_;
};
}
+42
View File
@@ -0,0 +1,42 @@
#include <algorithm>
#include "./string.hpp"
namespace lsp::utils
{
std::string Trim(const std::string& str)
{
size_t first = str.find_first_not_of(" \t\n\r");
if (first == std::string::npos)
return "";
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(), ::tolower);
return result;
}
bool StartsWithIgnoreCase(const std::string& str, const std::string& prefix)
{
if (prefix.size() > str.size())
return false;
for (size_t i = 0; i < prefix.size(); ++i)
if (std::tolower(str[i]) != std::tolower(prefix[i]))
return false;
return true;
}
bool StartsWith(const std::string& str, const std::string& prefix, bool ignoreCase)
{
if (ignoreCase)
return StartsWithIgnoreCase(str, prefix);
if (prefix.size() > str.size())
return false;
return str.compare(0, prefix.size(), prefix) == 0;
}
}
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include <string>
namespace lsp::utils
{
std::string Trim(const std::string& str);
std::string ToLower(const std::string& str);
bool StartsWith(const std::string& str, const std::string& prefix, bool ignoreCase = true);
bool StartsWithIgnoreCase(const std::string& str, const std::string& prefix);
}