From e55cc6865cd78c13c09fef1d419c57eb489f5472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20H=C3=A9rilier?= Date: Thu, 24 Oct 2024 18:39:18 +0200 Subject: [PATCH 1/2] workspace: Make didChangeConfiguration use its parameter to update the configuration settings. --- src/message_handler.hh | 2 +- src/messages/workspace.cc | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/message_handler.hh b/src/message_handler.hh index 8f09dc7c..1df705ff 100644 --- a/src/message_handler.hh +++ b/src/message_handler.hh @@ -313,7 +313,7 @@ private: void textDocument_signatureHelp(TextDocumentPositionParam &, ReplyOnce &); void textDocument_switchSourceHeader(TextDocumentIdentifier &, ReplyOnce &); void textDocument_typeDefinition(TextDocumentPositionParam &, ReplyOnce &); - void workspace_didChangeConfiguration(EmptyParam &); + void workspace_didChangeConfiguration(JsonReader &); void workspace_didChangeWatchedFiles(DidChangeWatchedFilesParam &); void workspace_didChangeWorkspaceFolders(DidChangeWorkspaceFoldersParam &); void workspace_executeCommand(JsonReader &, ReplyOnce &); diff --git a/src/messages/workspace.cc b/src/messages/workspace.cc index c604ab62..cfa781e2 100644 --- a/src/messages/workspace.cc +++ b/src/messages/workspace.cc @@ -13,6 +13,9 @@ #include #include +#include +#include + #include #include #include @@ -22,13 +25,29 @@ using namespace llvm; namespace ccls { REFLECT_STRUCT(SymbolInformation, name, kind, location, containerName); -void MessageHandler::workspace_didChangeConfiguration(EmptyParam &) { - for (auto &[folder, _] : g_config->workspaceFolders) - project->load(folder); - project->index(wfiles, RequestId()); +void MessageHandler::workspace_didChangeConfiguration(JsonReader &reader) { + auto it = reader.m->FindMember("settings"); + if (it != reader.m->MemberEnd() && it->value.IsObject()) { + rapidjson::StringBuffer output; + rapidjson::Writer writer(output); + JsonReader m1(&it->value); + it->value.Accept(writer); + LOG_S(INFO) << "didChangeConfiguration: " << output.GetString(); + try { + reflect(m1, *g_config); + } catch (std::invalid_argument &) { + reader.path_.push_back("settings"); + reader.path_.insert(reader.path_.end(), m1.path_.begin(), m1.path_.end()); + throw; + } - manager->clear(); -}; + for (auto &[folder, _] : g_config->workspaceFolders) + project->load(folder); + project->index(wfiles, RequestId()); + + manager->clear(); + } +} void MessageHandler::workspace_didChangeWatchedFiles( DidChangeWatchedFilesParam ¶m) { From 5d401fc95d57732a5bfa90f4584aace6b436c1ad Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 23 Nov 2024 17:51:50 -0800 Subject: [PATCH 2/2] early return and add a comment --- src/messages/workspace.cc | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/messages/workspace.cc b/src/messages/workspace.cc index cfa781e2..2e58fe9e 100644 --- a/src/messages/workspace.cc +++ b/src/messages/workspace.cc @@ -27,26 +27,28 @@ REFLECT_STRUCT(SymbolInformation, name, kind, location, containerName); void MessageHandler::workspace_didChangeConfiguration(JsonReader &reader) { auto it = reader.m->FindMember("settings"); - if (it != reader.m->MemberEnd() && it->value.IsObject()) { - rapidjson::StringBuffer output; - rapidjson::Writer writer(output); - JsonReader m1(&it->value); - it->value.Accept(writer); - LOG_S(INFO) << "didChangeConfiguration: " << output.GetString(); - try { - reflect(m1, *g_config); - } catch (std::invalid_argument &) { - reader.path_.push_back("settings"); - reader.path_.insert(reader.path_.end(), m1.path_.begin(), m1.path_.end()); - throw; - } + if (!(it != reader.m->MemberEnd() && it->value.IsObject())) + return; - for (auto &[folder, _] : g_config->workspaceFolders) - project->load(folder); - project->index(wfiles, RequestId()); - - manager->clear(); + // Similar to MessageHandler::initialize. + rapidjson::StringBuffer output; + rapidjson::Writer writer(output); + JsonReader m1(&it->value); + it->value.Accept(writer); + LOG_S(INFO) << "didChangeConfiguration: " << output.GetString(); + try { + reflect(m1, *g_config); + } catch (std::invalid_argument &) { + reader.path_.push_back("settings"); + reader.path_.insert(reader.path_.end(), m1.path_.begin(), m1.path_.end()); + throw; } + + for (auto &[folder, _] : g_config->workspaceFolders) + project->load(folder); + project->index(wfiles, RequestId()); + + manager->clear(); } void MessageHandler::workspace_didChangeWatchedFiles(