diff --git a/libsolidity/lsp/LanguageServer.cpp b/libsolidity/lsp/LanguageServer.cpp index 671476ab0..8a42ca104 100644 --- a/libsolidity/lsp/LanguageServer.cpp +++ b/libsolidity/lsp/LanguageServer.cpp @@ -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(); diff --git a/libsolidity/lsp/LanguageServer.h b/libsolidity/lsp/LanguageServer.h index d2ad09367..e827f6259 100644 --- a/libsolidity/lsp/LanguageServer.h +++ b/libsolidity/lsp/LanguageServer.h @@ -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); diff --git a/libsolidity/lsp/Transport.cpp b/libsolidity/lsp/Transport.cpp index fcd3c8249..b82b34ec4 100644 --- a/libsolidity/lsp/Transport.cpp +++ b/libsolidity/lsp/Transport.cpp @@ -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()); diff --git a/libsolidity/lsp/Transport.h b/libsolidity/lsp/Transport.h index 82fe43909..d84edf49d 100644 --- a/libsolidity/lsp/Transport.h +++ b/libsolidity/lsp/Transport.h @@ -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; }; /**