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:
Christian Parpart
2022-04-05 13:51:42 +02:00
parent d0bd365d2c
commit 2d07ea3d42
4 changed files with 52 additions and 0 deletions
+23
View File
@@ -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();