mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implements $/setTrace and uses trace logging.
For helping the caller to know in advance how many files are expected with a response for publishDiagnostics.
This commit is contained in:
parent
d0bd365d2c
commit
2d07ea3d42
@ -76,6 +76,7 @@ LanguageServer::LanguageServer(Transport& _transport):
|
||||
{"exit", [this](auto, auto) { m_state = (m_state == State::ShutdownRequested ? State::ExitRequested : State::ExitWithoutShutdown); }},
|
||||
{"initialize", bind(&LanguageServer::handleInitialize, this, _1, _2)},
|
||||
{"initialized", [](auto, auto) {}},
|
||||
{"$/setTrace", bind(&LanguageServer::setTrace, this, _2)},
|
||||
{"shutdown", [this](auto, auto) { m_state = State::ShutdownRequested; }},
|
||||
{"textDocument/definition", GotoDefinition(*this) },
|
||||
{"textDocument/didOpen", bind(&LanguageServer::handleTextDocumentDidOpen, this, _2)},
|
||||
@ -166,6 +167,13 @@ void LanguageServer::compileAndUpdateDiagnostics()
|
||||
diagnosticsBySourceUnit[*location->sourceName].append(jsonDiag);
|
||||
}
|
||||
|
||||
if (m_client.traceValue() != TraceValue::Off)
|
||||
{
|
||||
Json::Value extra;
|
||||
extra["openFileCount"] = Json::UInt64(diagnosticsBySourceUnit.size());
|
||||
m_client.trace("Number of currently open files: " + to_string(diagnosticsBySourceUnit.size()), extra);
|
||||
}
|
||||
|
||||
m_nonemptyDiagnostics.clear();
|
||||
for (auto&& [sourceUnitName, diagnostics]: diagnosticsBySourceUnit)
|
||||
{
|
||||
@ -273,6 +281,21 @@ void LanguageServer::handleWorkspaceDidChangeConfiguration(Json::Value const& _a
|
||||
changeConfiguration(_args["settings"]);
|
||||
}
|
||||
|
||||
void LanguageServer::setTrace(Json::Value const& _args)
|
||||
{
|
||||
if (!_args["value"].isString())
|
||||
// Simply ignore invalid parameter.
|
||||
return;
|
||||
|
||||
string const stringValue = _args["value"].asString();
|
||||
if (stringValue == "off")
|
||||
m_client.setTrace(TraceValue::Off);
|
||||
else if (stringValue == "messages")
|
||||
m_client.setTrace(TraceValue::Messages);
|
||||
else if (stringValue == "verbose")
|
||||
m_client.setTrace(TraceValue::Verbose);
|
||||
}
|
||||
|
||||
void LanguageServer::handleTextDocumentDidOpen(Json::Value const& _args)
|
||||
{
|
||||
requireServerInitialized();
|
||||
|
@ -68,6 +68,7 @@ private:
|
||||
void requireServerInitialized();
|
||||
void handleInitialize(MessageID _id, Json::Value const& _args);
|
||||
void handleWorkspaceDidChangeConfiguration(Json::Value const& _args);
|
||||
void setTrace(Json::Value const& _args);
|
||||
void handleTextDocumentDidOpen(Json::Value const& _args);
|
||||
void handleTextDocumentDidChange(Json::Value const& _args);
|
||||
void handleTextDocumentDidClose(Json::Value const& _args);
|
||||
|
@ -98,6 +98,18 @@ void IOStreamTransport::error(MessageID _id, ErrorCode _code, string _message)
|
||||
send(move(json), _id);
|
||||
}
|
||||
|
||||
void Transport::trace(std::string _message, Json::Value _extra)
|
||||
{
|
||||
if (m_logTrace != TraceValue::Off)
|
||||
{
|
||||
Json::Value params;
|
||||
if (_extra.isObject())
|
||||
params = move(_extra);
|
||||
params["message"] = move(_message);
|
||||
notify("$/logTrace", move(params));
|
||||
}
|
||||
}
|
||||
|
||||
void IOStreamTransport::send(Json::Value _json, MessageID _id)
|
||||
{
|
||||
solAssert(_json.isObject());
|
||||
|
@ -34,6 +34,13 @@ namespace solidity::lsp
|
||||
|
||||
using MessageID = Json::Value;
|
||||
|
||||
enum class TraceValue
|
||||
{
|
||||
Off,
|
||||
Messages,
|
||||
Verbose
|
||||
};
|
||||
|
||||
enum class ErrorCode
|
||||
{
|
||||
// Defined by JSON RPC
|
||||
@ -89,6 +96,15 @@ public:
|
||||
virtual void notify(std::string _method, Json::Value _params) = 0;
|
||||
virtual void reply(MessageID _id, Json::Value _result) = 0;
|
||||
virtual void error(MessageID _id, ErrorCode _code, std::string _message) = 0;
|
||||
|
||||
void trace(std::string _message, Json::Value _extra = Json::nullValue);
|
||||
|
||||
TraceValue traceValue() const noexcept { return m_logTrace; }
|
||||
void setTrace(TraceValue _value) noexcept { m_logTrace = _value; }
|
||||
|
||||
|
||||
private:
|
||||
TraceValue m_logTrace = TraceValue::Off;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user