mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
WIP
This commit is contained in:
parent
4258f58323
commit
3c91a00afa
@ -189,11 +189,11 @@ void LanguageServer::changeConfiguration(Json::Value const& _settings)
|
|||||||
if (auto traceLogFileNode = _settings["trace-log-file"])
|
if (auto traceLogFileNode = _settings["trace-log-file"])
|
||||||
{
|
{
|
||||||
if (traceLogFileNode.isString())
|
if (traceLogFileNode.isString())
|
||||||
m_client.setTraceLogFile(boost::filesystem::path(_settings["trace-log-file"].asString()));
|
m_client.setTraceLogFile(boost::filesystem::path(traceLogFileNode.asString()));
|
||||||
if (traceLogFileNode.isNull())
|
else if (traceLogFileNode.isNull())
|
||||||
m_client.setTraceLogFile(nullopt);
|
m_client.setTraceLogFile(nullopt);
|
||||||
else
|
else
|
||||||
lspAssert(false, ErrorCode::InvalidParams, "Invalid trace-log-file value. Must be a path to a file.");
|
lspAssert(false, ErrorCode::InvalidParams, "Invalid trace-log-file value. Must be a path to a file. "s + std::to_string(traceLogFileNode.type()));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_settingsObject = _settings;
|
m_settingsObject = _settings;
|
||||||
|
@ -42,6 +42,12 @@ using namespace std;
|
|||||||
using namespace solidity::lsp;
|
using namespace solidity::lsp;
|
||||||
|
|
||||||
// {{{ Transport
|
// {{{ Transport
|
||||||
|
ofstream Transport::traceLogFileStream() const
|
||||||
|
{
|
||||||
|
lspAssert(m_traceLogFilePath, ErrorCode::InternalError, "");
|
||||||
|
return ofstream(m_traceLogFilePath.value().generic_string(), ios::app);
|
||||||
|
}
|
||||||
|
|
||||||
optional<Json::Value> Transport::receive()
|
optional<Json::Value> Transport::receive()
|
||||||
{
|
{
|
||||||
auto const headers = parseHeaders();
|
auto const headers = parseHeaders();
|
||||||
@ -59,21 +65,21 @@ optional<Json::Value> Transport::receive()
|
|||||||
|
|
||||||
string const data = readBytes(stoul(headers->at("content-length")));
|
string const data = readBytes(stoul(headers->at("content-length")));
|
||||||
|
|
||||||
if (m_traceLogFilePath)
|
|
||||||
{
|
|
||||||
ofstream traceLogger(m_traceLogFilePath.value().generic_string(), ios::app);
|
|
||||||
traceLogger << "Received: " << data << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Json::Value jsonMessage;
|
Json::Value jsonMessage;
|
||||||
string jsonParsingErrors;
|
string jsonParsingErrors;
|
||||||
solidity::util::jsonParseStrict(data, jsonMessage, &jsonParsingErrors);
|
solidity::util::jsonParseStrict(data, jsonMessage, &jsonParsingErrors);
|
||||||
if (!jsonParsingErrors.empty() || !jsonMessage || !jsonMessage.isObject())
|
if (!jsonParsingErrors.empty() || !jsonMessage || !jsonMessage.isObject())
|
||||||
{
|
{
|
||||||
|
if (m_traceLogFilePath)
|
||||||
|
traceLogFileStream() << "{\"Received\": " << util::jsonPrettyPrint(jsonMessage) << "}," << endl;
|
||||||
|
|
||||||
error({}, ErrorCode::ParseError, "Could not parse RPC JSON payload. " + jsonParsingErrors);
|
error({}, ErrorCode::ParseError, "Could not parse RPC JSON payload. " + jsonParsingErrors);
|
||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_traceLogFilePath)
|
||||||
|
traceLogFileStream() << "{\"Received\": " << util::jsonPrettyPrint(jsonMessage) << "}," << endl;
|
||||||
|
|
||||||
return {std::move(jsonMessage)};
|
return {std::move(jsonMessage)};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,10 +156,7 @@ void Transport::send(Json::Value _json, MessageID _id)
|
|||||||
string const jsonString = solidity::util::jsonCompactPrint(_json);
|
string const jsonString = solidity::util::jsonCompactPrint(_json);
|
||||||
|
|
||||||
if (m_traceLogFilePath)
|
if (m_traceLogFilePath)
|
||||||
{
|
traceLogFileStream() << "{\"Sending\": " << jsonString << "}," << endl;
|
||||||
ofstream traceLogger(m_traceLogFilePath.value().generic_string(), ios::app);
|
|
||||||
traceLogger << "Sending: " << jsonString << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeBytes(fmt::format("Content-Length: {}\r\n\r\n", jsonString.size()));
|
writeBytes(fmt::format("Content-Length: {}\r\n\r\n", jsonString.size()));
|
||||||
writeBytes(jsonString);
|
writeBytes(jsonString);
|
||||||
|
@ -109,6 +109,8 @@ public:
|
|||||||
/// to be written to if trace value is set to verbose.
|
/// to be written to if trace value is set to verbose.
|
||||||
void setTraceLogFile(std::optional<boost::filesystem::path> _pathToLogfile);
|
void setTraceLogFile(std::optional<boost::filesystem::path> _pathToLogfile);
|
||||||
|
|
||||||
|
std::ofstream traceLogFileStream() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TraceValue m_logTrace = TraceValue::Off;
|
TraceValue m_logTrace = TraceValue::Off;
|
||||||
std::optional<boost::filesystem::path> m_traceLogFilePath;
|
std::optional<boost::filesystem::path> m_traceLogFilePath;
|
||||||
|
@ -913,6 +913,8 @@ void CommandLineInterface::handleAst()
|
|||||||
void CommandLineInterface::serveLSP()
|
void CommandLineInterface::serveLSP()
|
||||||
{
|
{
|
||||||
lsp::StdioTransport transport;
|
lsp::StdioTransport transport;
|
||||||
|
transport.setTraceLogFile(m_options.languageServer.traceLogFile);
|
||||||
|
|
||||||
if (!lsp::LanguageServer{transport}.run())
|
if (!lsp::LanguageServer{transport}.run())
|
||||||
solThrow(CommandLineExecutionError, "LSP terminated abnormally.");
|
solThrow(CommandLineExecutionError, "LSP terminated abnormally.");
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ static string const g_strLicense = "license";
|
|||||||
static string const g_strLibraries = "libraries";
|
static string const g_strLibraries = "libraries";
|
||||||
static string const g_strLink = "link";
|
static string const g_strLink = "link";
|
||||||
static string const g_strLSP = "lsp";
|
static string const g_strLSP = "lsp";
|
||||||
|
static string const g_strLSPTrace = "lsp-trace";
|
||||||
static string const g_strMachine = "machine";
|
static string const g_strMachine = "machine";
|
||||||
static string const g_strMetadataHash = "metadata-hash";
|
static string const g_strMetadataHash = "metadata-hash";
|
||||||
static string const g_strMetadataLiteral = "metadata-literal";
|
static string const g_strMetadataLiteral = "metadata-literal";
|
||||||
@ -649,6 +650,16 @@ General Information)").c_str(),
|
|||||||
;
|
;
|
||||||
desc.add(alternativeInputModes);
|
desc.add(alternativeInputModes);
|
||||||
|
|
||||||
|
po::options_description lspModeOptions("LSP Mode Options");
|
||||||
|
lspModeOptions.add_options()
|
||||||
|
(
|
||||||
|
g_strLSPTrace.c_str(),
|
||||||
|
po::value<string>()->value_name(""),
|
||||||
|
"Enables trace I/O logging to a given file."
|
||||||
|
)
|
||||||
|
;
|
||||||
|
desc.add(lspModeOptions);
|
||||||
|
|
||||||
po::options_description assemblyModeOptions("Assembly Mode Options");
|
po::options_description assemblyModeOptions("Assembly Mode Options");
|
||||||
assemblyModeOptions.add_options()
|
assemblyModeOptions.add_options()
|
||||||
(
|
(
|
||||||
@ -942,7 +953,12 @@ void CommandLineParser::processArgs()
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (m_options.input.mode == InputMode::LanguageServer)
|
if (m_options.input.mode == InputMode::LanguageServer)
|
||||||
|
{
|
||||||
|
if (m_args.count("lsp-trace"))
|
||||||
|
m_options.languageServer.traceLogFile = boost::filesystem::path(m_args.at("lsp-trace").as<string>());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
checkMutuallyExclusive({g_strColor, g_strNoColor});
|
checkMutuallyExclusive({g_strColor, g_strNoColor});
|
||||||
|
|
||||||
|
@ -227,6 +227,11 @@ struct CommandLineOptions
|
|||||||
std::optional<std::string> yulSteps;
|
std::optional<std::string> yulSteps;
|
||||||
} optimizer;
|
} optimizer;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
std::optional<boost::filesystem::path> traceLogFile = std::nullopt;
|
||||||
|
} languageServer;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
bool initialize = false;
|
bool initialize = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user