Skip to content

Commit

Permalink
Fix some clang-tidy warnings
Browse files Browse the repository at this point in the history
Incorporated some fixes by Daniel Chabrowski (MaskRay#467)
  • Loading branch information
MaskRay committed Nov 10, 2019
1 parent eabce35 commit 050a16c
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
rd->isInvalidDecl() || !validateRecord(rd))
offset = -1;
for (FieldDecl *fd : rd->fields()) {
int offset1 = offset < 0 ? -1 : offset + ctx->getFieldOffset(fd);
int offset1 = offset < 0 ? -1 : int(offset + ctx->getFieldOffset(fd));
if (fd->getIdentifier())
type.def.vars.emplace_back(getUsr(fd), offset1);
else if (const auto *rt1 = fd->getType()->getAs<RecordType>()) {
Expand Down
4 changes: 2 additions & 2 deletions src/lsp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void reflect(JsonWriter &visitor, RequestId &value) {
visitor.null_();
break;
case RequestId::kInt:
visitor.int_(atoll(value.value.c_str()));
visitor.int64(atoll(value.value.c_str()));
break;
case RequestId::kString:
visitor.string(value.value.c_str(), value.value.size());
Expand All @@ -51,7 +51,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");
Expand Down
6 changes: 2 additions & 4 deletions src/message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,8 @@ void ReplyOnce::replyLocationLink(std::vector<LocationLink> &result) {
if (g_config->client.linkSupport) {
(*this)(result);
} else {
std::vector<Location> result1;
for (auto &loc : result)
result1.emplace_back(std::move(loc));
(*this)(result1);
(*this)(std::vector<Location>(std::make_move_iterator(result.begin()),
std::make_move_iterator(result.end())));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/message_handler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ struct WorkingFile;
struct WorkingFiles;

namespace pipeline {
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn);
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn);
void replyError(const RequestId &id,
const std::function<void(JsonWriter &)> &fn);
} // namespace pipeline

struct CodeActionParam {
Expand Down
2 changes: 1 addition & 1 deletion src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void do_initialize(MessageHandler *m, InitializeParam &param,
// may take a long time. Indexer threads will emit status/progress
// reports.
if (g_config->index.threads == 0)
g_config->index.threads = std::thread::hardware_concurrency();
g_config->index.threads = (int)std::thread::hardware_concurrency();

LOG_S(INFO) << "start " << g_config->index.threads << " indexers";
for (int i = 0; i < g_config->index.threads; i++)
Expand Down
4 changes: 2 additions & 2 deletions src/messages/textDocument_formatting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ std::vector<TextEdit> replacementsToEdits(std::string_view code,
const tooling::Replacements &repls) {
std::vector<TextEdit> ret;
int i = 0, line = 0, col = 0;
auto move = [&](int p) {
for (; i < p; i++)
auto move = [&](unsigned p) {
for (; i < (int)p; i++)
if (code[i] == '\n')
line++, col = 0;
else {
Expand Down
2 changes: 1 addition & 1 deletion src/messages/workspace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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)
Expand Down
22 changes: 12 additions & 10 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,13 @@ void mainLoop() {

SemaManager manager(
&project, &wfiles,
[&](std::string path, std::vector<Diagnostic> diagnostics) {
[](const std::string &path, std::vector<Diagnostic> 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;
Expand Down Expand Up @@ -706,8 +706,9 @@ void standalone(const std::string &root) {
WorkingFiles wfiles;
VFS vfs;
SemaManager manager(
nullptr, nullptr, [&](std::string, std::vector<Diagnostic>) {},
[](RequestId id) {});
nullptr, nullptr,
[](const std::string &, const std::vector<Diagnostic> &) {},
[](const RequestId &id) {});
IncludeComplete complete(&project);

MessageHandler handler;
Expand Down Expand Up @@ -745,7 +746,7 @@ void standalone(const std::string &root) {
void index(const std::string &path, const std::vector<const char *> &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);
}

Expand Down Expand Up @@ -789,7 +790,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<void(JsonWriter &)> &fn) {
rapidjson::StringBuffer output;
rapidjson::Writer<rapidjson::StringBuffer> w(output);
Expand All @@ -802,7 +803,7 @@ static void reply(RequestId id, const char *key,
w.Null();
break;
case RequestId::kInt:
w.Int(atoll(id.value.c_str()));
w.Int64(atoll(id.value.c_str()));
break;
case RequestId::kString:
w.String(id.value.c_str(), id.value.size());
Expand All @@ -817,11 +818,12 @@ static void reply(RequestId id, const char *key,
for_stdout->pushBack(output.GetString());
}

void reply(RequestId id, const std::function<void(JsonWriter &)> &fn) {
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn) {
reply(id, "result", fn);
}

void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn) {
void replyError(const RequestId &id,
const std::function<void(JsonWriter &)> &fn) {
reply(id, "error", fn);
}
} // namespace pipeline
Expand Down
7 changes: 4 additions & 3 deletions src/pipeline.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ template <typename T> void request(const char *method, T &result) {
notifyOrRequest(method, true, [&](JsonWriter &w) { reflect(w, result); });
}

void reply(RequestId id, const std::function<void(JsonWriter &)> &fn);
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn);

void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
template <typename T> void replyError(RequestId id, T &result) {
void replyError(const RequestId &id,
const std::function<void(JsonWriter &)> &fn);
template <typename T> void replyError(const RequestId &id, T &result) {
replyError(id, [&](JsonWriter &w) { reflect(w, result); });
}
} // namespace pipeline
Expand Down
4 changes: 2 additions & 2 deletions src/project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ bool appendToCDB(const std::vector<const char *> &args) {
return args.size() && StringRef("%compile_commands.json") == args[0];
}

std::vector<const char *> getFallback(const std::string path) {
std::vector<const char *> getFallback(const std::string &path) {
std::vector<const char *> argv{"clang"};
if (sys::path::extension(path) == ".h")
argv.push_back("-xobjective-c++-header");
Expand Down Expand Up @@ -595,7 +595,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);
Expand Down
2 changes: 1 addition & 1 deletion src/project.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct Project {
void setArgsForFile(const std::vector<const char *> &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
8 changes: 5 additions & 3 deletions src/sema_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void *diagnosticMain(void *manager_) {
ret.severity = 1;
break;
}
ret.code = d.category;
ret.code = (int)d.category;
return ret;
};

Expand Down Expand Up @@ -671,8 +671,10 @@ std::shared_ptr<PreambleData> 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<PCHContainerOperations>()) {
: project_(project), wfiles(wfiles),
on_diagnostic_(std::move(on_diagnostic)),
on_dropped_(std::move(on_dropped)),
pch(std::make_shared<PCHContainerOperations>()) {
spawnThread(ccls::preambleMain, this);
spawnThread(ccls::completionMain, this);
spawnThread(ccls::diagnosticMain, this);
Expand Down
7 changes: 4 additions & 3 deletions src/serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <llvm/ADT/CachedHashString.h>
#include <llvm/ADT/DenseSet.h>
#include <llvm/ADT/STLExtras.h>

#include <mutex>
#include <stdexcept>
Expand All @@ -23,7 +24,7 @@ bool gTestOutputMode = false;

namespace ccls {

void JsonReader::iterArray(std::function<void()> fn) {
void JsonReader::iterArray(llvm::function_ref<void()> fn) {
if (!m->IsArray())
throw std::invalid_argument("array");
// Use "0" to indicate any element for now.
Expand All @@ -36,7 +37,7 @@ void JsonReader::iterArray(std::function<void()> fn) {
}
path_.pop_back();
}
void JsonReader::member(const char *name, std::function<void()> fn) {
void JsonReader::member(const char *name, llvm::function_ref<void()> fn) {
path_.push_back(name);
auto it = m->FindMember(name);
if (it != m->MemberEnd()) {
Expand Down Expand Up @@ -69,7 +70,7 @@ void JsonWriter::startObject() { m->StartObject(); }
void JsonWriter::endObject() { m->EndObject(); }
void JsonWriter::key(const char *name) { m->Key(name); }
void JsonWriter::null_() { m->Null(); }
void JsonWriter::int_(int v) { m->Int(v); }
void JsonWriter::int64(int64_t v) { m->Int64(v); }
void JsonWriter::string(const char *s) { m->String(s); }
void JsonWriter::string(const char *s, size_t len) { m->String(s, len); }

Expand Down
7 changes: 4 additions & 3 deletions src/serializer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace llvm {
class CachedHashStringRef;
class StringRef;
template <typename Fn> class function_ref;
} // namespace llvm

namespace ccls {
Expand All @@ -36,8 +37,8 @@ struct JsonReader {
JsonReader(rapidjson::Value *m) : m(m) {}
void startObject() {}
void endObject() {}
void iterArray(std::function<void()> fn);
void member(const char *name, std::function<void()> fn);
void iterArray(llvm::function_ref<void()> fn);
void member(const char *name, llvm::function_ref<void()> fn);
bool isNull();
std::string getString();
std::string getPath() const;
Expand All @@ -57,7 +58,7 @@ struct JsonWriter {
void endObject();
void key(const char *name);
void null_();
void int_(int v);
void int64(int64_t v);
void string(const char *s);
void string(const char *s, size_t len);
};
Expand Down
2 changes: 1 addition & 1 deletion src/working_files.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int alignColumn(const std::string &a, int column, std::string b, bool is_end) {
if (column < head)
return column;
if ((int)a.size() - tail < column)
return column + b.size() - a.size();
return column + (int)b.size() - (int)a.size();
if (std::max(a.size(), b.size()) - head - tail >= kMaxColumnAlignSize)
return std::min(column, (int)b.size());

Expand Down

0 comments on commit 050a16c

Please sign in to comment.