diff --git a/src/lsp.cc b/src/lsp.cc index 530f3da6..4f191541 100644 --- a/src/lsp.cc +++ b/src/lsp.cc @@ -63,7 +63,7 @@ void DocumentUri::setPath(const std::string &path) { // file:///c%3A/Users/jacob/Desktop/superindex/indexer/full_tests raw_uri = path; - size_t index = raw_uri.find(":"); + size_t index = raw_uri.find(':'); if (index == 1) { // widows drive letters must always be 1 char raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1, "%3A"); diff --git a/src/message_handler.cc b/src/message_handler.cc index cb28b05d..321d1b68 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -121,9 +121,8 @@ void ReplyOnce::replyLocationLink(std::vector &result) { if (g_config->client.linkSupport) { (*this)(result); } else { - std::vector result1; - for (auto &loc : result) - result1.emplace_back(std::move(loc)); + std::vector result1{std::make_move_iterator(result.begin()), + std::make_move_iterator(result.end())}; (*this)(result1); } } diff --git a/src/message_handler.hh b/src/message_handler.hh index 3d231c17..e19b2264 100644 --- a/src/message_handler.hh +++ b/src/message_handler.hh @@ -32,8 +32,9 @@ struct WorkingFile; struct WorkingFiles; namespace pipeline { -void reply(RequestId id, const std::function &fn); -void replyError(RequestId id, const std::function &fn); +void reply(const RequestId &id, const std::function &fn); +void replyError(const RequestId &id, + const std::function &fn); } // namespace pipeline struct CodeActionParam { diff --git a/src/messages/workspace.cc b/src/messages/workspace.cc index 88225d73..cce5b4b0 100644 --- a/src/messages/workspace.cc +++ b/src/messages/workspace.cc @@ -101,7 +101,7 @@ void MessageHandler::workspace_didChangeWorkspaceFolders( if (folder == real) real.clear(); LOG_S(INFO) << "add workspace folder " << wf.name << ": " - << (real.empty() ? folder : folder + " -> " + real); + << (real.empty() ? folder : (folder + " -> ").append(real)); workspaceFolders.emplace_back(); auto it = workspaceFolders.end() - 1; for (; it != workspaceFolders.begin() && folder < it[-1].first; --it) diff --git a/src/pipeline.cc b/src/pipeline.cc index 481f4e35..45fc1286 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -616,13 +616,13 @@ void mainLoop() { SemaManager manager( &project, &wfiles, - [&](std::string path, std::vector diagnostics) { + [&](const std::string &path, std::vector diagnostics) { PublishDiagnosticParam params; params.uri = DocumentUri::fromPath(path); - params.diagnostics = diagnostics; + params.diagnostics = std::move(diagnostics); notify("textDocument/publishDiagnostics", params); }, - [](RequestId id) { + [](const RequestId &id) { if (id.valid()) { ResponseError err; err.code = ErrorCode::InternalError; @@ -717,8 +717,9 @@ void standalone(const std::string &root) { WorkingFiles wfiles; VFS vfs; SemaManager manager( - nullptr, nullptr, [&](std::string, std::vector) {}, - [](RequestId id) {}); + nullptr, nullptr, + [&](const std::string &, const std::vector &) {}, + [](const RequestId &id) {}); IncludeComplete complete(&project); MessageHandler handler; @@ -756,7 +757,7 @@ void standalone(const std::string &root) { void index(const std::string &path, const std::vector &args, IndexMode mode, bool must_exist, RequestId id) { pending_index_requests++; - index_request->pushBack({path, args, mode, must_exist, id}, + index_request->pushBack({path, args, mode, must_exist, std::move(id)}, mode != IndexMode::Background); } @@ -800,7 +801,7 @@ void notifyOrRequest(const char *method, bool request, for_stdout->pushBack(output.GetString()); } -static void reply(RequestId id, const char *key, +static void reply(const RequestId &id, const char *key, const std::function &fn) { rapidjson::StringBuffer output; rapidjson::Writer w(output); @@ -828,11 +829,12 @@ static void reply(RequestId id, const char *key, for_stdout->pushBack(output.GetString()); } -void reply(RequestId id, const std::function &fn) { +void reply(const RequestId &id, const std::function &fn) { reply(id, "result", fn); } -void replyError(RequestId id, const std::function &fn) { +void replyError(const RequestId &id, + const std::function &fn) { reply(id, "error", fn); } } // namespace pipeline diff --git a/src/pipeline.hh b/src/pipeline.hh index d7021a7b..d0c60219 100644 --- a/src/pipeline.hh +++ b/src/pipeline.hh @@ -65,10 +65,11 @@ template void request(const char *method, T &result) { notifyOrRequest(method, true, [&](JsonWriter &w) { reflect(w, result); }); } -void reply(RequestId id, const std::function &fn); +void reply(const RequestId &id, const std::function &fn); -void replyError(RequestId id, const std::function &fn); -template void replyError(RequestId id, T &result) { +void replyError(const RequestId &id, + const std::function &fn); +template void replyError(const RequestId &id, T &result) { replyError(id, [&](JsonWriter &w) { reflect(w, result); }); } } // namespace pipeline diff --git a/src/project.cc b/src/project.cc index bb48e995..c8e4c934 100644 --- a/src/project.cc +++ b/src/project.cc @@ -249,7 +249,7 @@ bool appendToCDB(const std::vector &args) { return args.size() && StringRef("%compile_commands.json") == args[0]; } -std::vector getFallback(const std::string path) { +std::vector getFallback(const std::string &path) { std::vector argv{"clang"}; if (sys::path::extension(path) == ".h") argv.push_back("-xobjective-c++-header"); @@ -607,7 +607,7 @@ Project::Entry Project::findEntry(const std::string &path, bool can_redirect, return ret; } -void Project::index(WorkingFiles *wfiles, RequestId id) { +void Project::index(WorkingFiles *wfiles, const RequestId &id) { auto &gi = g_config->index; GroupMatch match(gi.whitelist, gi.blacklist), match_i(gi.initialWhitelist, gi.initialBlacklist); diff --git a/src/project.hh b/src/project.hh index 7c8a51e7..aa73fd60 100644 --- a/src/project.hh +++ b/src/project.hh @@ -76,7 +76,7 @@ struct Project { void setArgsForFile(const std::vector &args, const std::string &path); - void index(WorkingFiles *wfiles, RequestId id); + void index(WorkingFiles *wfiles, const RequestId &id); void indexRelated(const std::string &path); }; } // namespace ccls diff --git a/src/sema_manager.cc b/src/sema_manager.cc index 7b5c92c2..a6097e82 100644 --- a/src/sema_manager.cc +++ b/src/sema_manager.cc @@ -231,7 +231,7 @@ class StoreDiags : public DiagnosticConsumer { } public: - StoreDiags(std::string path) : path(path) {} + StoreDiags(std::string path) : path{std::move(path)} {} std::vector take() { return std::move(output); } bool isConcerned(const SourceManager &sm, SourceLocation l) { FileID fid = sm.getFileID(l); @@ -683,8 +683,10 @@ std::shared_ptr Session::getPreamble() { SemaManager::SemaManager(Project *project, WorkingFiles *wfiles, OnDiagnostic on_diagnostic, OnDropped on_dropped) - : project_(project), wfiles(wfiles), on_diagnostic_(on_diagnostic), - on_dropped_(on_dropped), pch(std::make_shared()) { + : project_(project), wfiles(wfiles), + on_diagnostic_(std::move(on_diagnostic)), + on_dropped_(std::move(on_dropped)), + pch(std::make_shared()) { spawnThread(ccls::preambleMain, this); spawnThread(ccls::completionMain, this); spawnThread(ccls::diagnosticMain, this); diff --git a/src/serializer.cc b/src/serializer.cc index a90a58c7..c050dd22 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -35,7 +35,7 @@ bool gTestOutputMode = false; namespace ccls { -void JsonReader::iterArray(std::function fn) { +void JsonReader::iterArray(const llvm::function_ref fn) { if (!m->IsArray()) throw std::invalid_argument("array"); // Use "0" to indicate any element for now. @@ -48,7 +48,7 @@ void JsonReader::iterArray(std::function fn) { } path_.pop_back(); } -void JsonReader::member(const char *name, std::function fn) { +void JsonReader::member(const char *name, const llvm::function_ref fn) { path_.push_back(name); auto it = m->FindMember(name); if (it != m->MemberEnd()) { diff --git a/src/serializer.hh b/src/serializer.hh index 13455cc2..b56ef7f2 100644 --- a/src/serializer.hh +++ b/src/serializer.hh @@ -17,6 +17,7 @@ limitations under the License. #include "utils.hh" +#include #include #include @@ -48,8 +49,8 @@ struct JsonReader { JsonReader(rapidjson::Value *m) : m(m) {} void startObject() {} void endObject() {} - void iterArray(std::function fn); - void member(const char *name, std::function fn); + void iterArray(const llvm::function_ref fn); + void member(const char *name, const llvm::function_ref fn); bool isNull(); std::string getString(); std::string getPath() const; diff --git a/src/utils.cc b/src/utils.cc index d385de0c..f712dc80 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -152,7 +152,7 @@ std::string realPath(const std::string &path) { bool normalizeFolder(std::string &path) { for (auto &[root, real] : g_config->workspaceFolders) if (real.size() && llvm::StringRef(path).startswith(real)) { - path = root + path.substr(real.size()); + path = root.append(path.substr(real.size())); return true; } return false;