Skip to content

Commit 3e04997

Browse files
committed
Fix some clang-tidy warnings
Incorporated some fixes by Daniel Chabrowski (#467)
1 parent e941ffa commit 3e04997

15 files changed

+45
-39
lines changed

src/indexer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
662662
rd->isInvalidDecl() || !validateRecord(rd))
663663
offset = -1;
664664
for (FieldDecl *fd : rd->fields()) {
665-
int offset1 = offset < 0 ? -1 : offset + ctx->getFieldOffset(fd);
665+
int offset1 = offset < 0 ? -1 : int(offset + ctx->getFieldOffset(fd));
666666
if (fd->getIdentifier())
667667
type.def.vars.emplace_back(getUsr(fd), offset1);
668668
else if (const auto *rt1 = fd->getType()->getAs<RecordType>()) {

src/lsp.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void reflect(JsonWriter &visitor, RequestId &value) {
3333
visitor.null_();
3434
break;
3535
case RequestId::kInt:
36-
visitor.int_(atoll(value.value.c_str()));
36+
visitor.int64(atoll(value.value.c_str()));
3737
break;
3838
case RequestId::kString:
3939
visitor.string(value.value.c_str(), value.value.size());
@@ -51,7 +51,7 @@ void DocumentUri::setPath(const std::string &path) {
5151
// file:///c%3A/Users/jacob/Desktop/superindex/indexer/full_tests
5252
raw_uri = path;
5353

54-
size_t index = raw_uri.find(":");
54+
size_t index = raw_uri.find(':');
5555
if (index == 1) { // widows drive letters must always be 1 char
5656
raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1,
5757
"%3A");

src/message_handler.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ void ReplyOnce::replyLocationLink(std::vector<LocationLink> &result) {
109109
if (g_config->client.linkSupport) {
110110
(*this)(result);
111111
} else {
112-
std::vector<Location> result1;
113-
for (auto &loc : result)
114-
result1.emplace_back(std::move(loc));
115-
(*this)(result1);
112+
(*this)(std::vector<Location>(std::make_move_iterator(result.begin()),
113+
std::make_move_iterator(result.end())));
116114
}
117115
}
118116

src/message_handler.hh

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ struct WorkingFile;
3232
struct WorkingFiles;
3333

3434
namespace pipeline {
35-
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn);
36-
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
35+
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn);
36+
void replyError(const RequestId &id,
37+
const std::function<void(JsonWriter &)> &fn);
3738
} // namespace pipeline
3839

3940
struct CodeActionParam {

src/messages/initialize.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void do_initialize(MessageHandler *m, InitializeParam &param,
370370
// may take a long time. Indexer threads will emit status/progress
371371
// reports.
372372
if (g_config->index.threads == 0)
373-
g_config->index.threads = std::thread::hardware_concurrency();
373+
g_config->index.threads = (int)std::thread::hardware_concurrency();
374374

375375
LOG_S(INFO) << "start " << g_config->index.threads << " indexers";
376376
for (int i = 0; i < g_config->index.threads; i++)

src/messages/textDocument_formatting.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ std::vector<TextEdit> replacementsToEdits(std::string_view code,
4444
const tooling::Replacements &repls) {
4545
std::vector<TextEdit> ret;
4646
int i = 0, line = 0, col = 0;
47-
auto move = [&](int p) {
48-
for (; i < p; i++)
47+
auto move = [&](unsigned p) {
48+
for (; i < (int)p; i++)
4949
if (code[i] == '\n')
5050
line++, col = 0;
5151
else {

src/messages/workspace.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void MessageHandler::workspace_didChangeWorkspaceFolders(
101101
if (folder == real)
102102
real.clear();
103103
LOG_S(INFO) << "add workspace folder " << wf.name << ": "
104-
<< (real.empty() ? folder : folder + " -> " + real);
104+
<< (real.empty() ? folder : (folder + " -> ").append(real));
105105
workspaceFolders.emplace_back();
106106
auto it = workspaceFolders.end() - 1;
107107
for (; it != workspaceFolders.begin() && folder < it[-1].first; --it)

src/pipeline.cc

+12-10
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,13 @@ void mainLoop() {
604604

605605
SemaManager manager(
606606
&project, &wfiles,
607-
[&](std::string path, std::vector<Diagnostic> diagnostics) {
607+
[](const std::string &path, std::vector<Diagnostic> diagnostics) {
608608
PublishDiagnosticParam params;
609609
params.uri = DocumentUri::fromPath(path);
610-
params.diagnostics = diagnostics;
610+
params.diagnostics = std::move(diagnostics);
611611
notify("textDocument/publishDiagnostics", params);
612612
},
613-
[](RequestId id) {
613+
[](const RequestId &id) {
614614
if (id.valid()) {
615615
ResponseError err;
616616
err.code = ErrorCode::InternalError;
@@ -705,8 +705,9 @@ void standalone(const std::string &root) {
705705
WorkingFiles wfiles;
706706
VFS vfs;
707707
SemaManager manager(
708-
nullptr, nullptr, [&](std::string, std::vector<Diagnostic>) {},
709-
[](RequestId id) {});
708+
nullptr, nullptr,
709+
[](const std::string &, const std::vector<Diagnostic> &) {},
710+
[](const RequestId &id) {});
710711
IncludeComplete complete(&project);
711712

712713
MessageHandler handler;
@@ -744,7 +745,7 @@ void standalone(const std::string &root) {
744745
void index(const std::string &path, const std::vector<const char *> &args,
745746
IndexMode mode, bool must_exist, RequestId id) {
746747
pending_index_requests++;
747-
index_request->pushBack({path, args, mode, must_exist, id},
748+
index_request->pushBack({path, args, mode, must_exist, std::move(id)},
748749
mode != IndexMode::Background);
749750
}
750751

@@ -788,7 +789,7 @@ void notifyOrRequest(const char *method, bool request,
788789
for_stdout->pushBack(output.GetString());
789790
}
790791

791-
static void reply(RequestId id, const char *key,
792+
static void reply(const RequestId &id, const char *key,
792793
const std::function<void(JsonWriter &)> &fn) {
793794
rapidjson::StringBuffer output;
794795
rapidjson::Writer<rapidjson::StringBuffer> w(output);
@@ -801,7 +802,7 @@ static void reply(RequestId id, const char *key,
801802
w.Null();
802803
break;
803804
case RequestId::kInt:
804-
w.Int(atoll(id.value.c_str()));
805+
w.Int64(atoll(id.value.c_str()));
805806
break;
806807
case RequestId::kString:
807808
w.String(id.value.c_str(), id.value.size());
@@ -816,11 +817,12 @@ static void reply(RequestId id, const char *key,
816817
for_stdout->pushBack(output.GetString());
817818
}
818819

819-
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn) {
820+
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn) {
820821
reply(id, "result", fn);
821822
}
822823

823-
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn) {
824+
void replyError(const RequestId &id,
825+
const std::function<void(JsonWriter &)> &fn) {
824826
reply(id, "error", fn);
825827
}
826828
} // namespace pipeline

src/pipeline.hh

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ template <typename T> void request(const char *method, T &result) {
6868
notifyOrRequest(method, true, [&](JsonWriter &w) { reflect(w, result); });
6969
}
7070

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

73-
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
74-
template <typename T> void replyError(RequestId id, T &result) {
73+
void replyError(const RequestId &id,
74+
const std::function<void(JsonWriter &)> &fn);
75+
template <typename T> void replyError(const RequestId &id, T &result) {
7576
replyError(id, [&](JsonWriter &w) { reflect(w, result); });
7677
}
7778
} // namespace pipeline

src/project.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ bool appendToCDB(const std::vector<const char *> &args) {
237237
return args.size() && StringRef("%compile_commands.json") == args[0];
238238
}
239239

240-
std::vector<const char *> getFallback(const std::string path) {
240+
std::vector<const char *> getFallback(const std::string &path) {
241241
std::vector<const char *> argv{"clang"};
242242
if (sys::path::extension(path) == ".h")
243243
argv.push_back("-xobjective-c++-header");
@@ -595,7 +595,7 @@ Project::Entry Project::findEntry(const std::string &path, bool can_redirect,
595595
return ret;
596596
}
597597

598-
void Project::index(WorkingFiles *wfiles, RequestId id) {
598+
void Project::index(WorkingFiles *wfiles, const RequestId &id) {
599599
auto &gi = g_config->index;
600600
GroupMatch match(gi.whitelist, gi.blacklist),
601601
match_i(gi.initialWhitelist, gi.initialBlacklist);

src/project.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct Project {
6464
void setArgsForFile(const std::vector<const char *> &args,
6565
const std::string &path);
6666

67-
void index(WorkingFiles *wfiles, RequestId id);
67+
void index(WorkingFiles *wfiles, const RequestId &id);
6868
void indexRelated(const std::string &path);
6969
};
7070
} // namespace ccls

src/sema_manager.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ void *diagnosticMain(void *manager_) {
603603
ret.severity = 1;
604604
break;
605605
}
606-
ret.code = d.category;
606+
ret.code = (int)d.category;
607607
return ret;
608608
};
609609

@@ -671,8 +671,10 @@ std::shared_ptr<PreambleData> Session::getPreamble() {
671671

672672
SemaManager::SemaManager(Project *project, WorkingFiles *wfiles,
673673
OnDiagnostic on_diagnostic, OnDropped on_dropped)
674-
: project_(project), wfiles(wfiles), on_diagnostic_(on_diagnostic),
675-
on_dropped_(on_dropped), pch(std::make_shared<PCHContainerOperations>()) {
674+
: project_(project), wfiles(wfiles),
675+
on_diagnostic_(std::move(on_diagnostic)),
676+
on_dropped_(std::move(on_dropped)),
677+
pch(std::make_shared<PCHContainerOperations>()) {
676678
spawnThread(ccls::preambleMain, this);
677679
spawnThread(ccls::completionMain, this);
678680
spawnThread(ccls::diagnosticMain, this);

src/serializer.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <llvm/ADT/CachedHashString.h>
1515
#include <llvm/ADT/DenseSet.h>
16+
#include <llvm/ADT/STLExtras.h>
1617

1718
#include <mutex>
1819
#include <stdexcept>
@@ -23,7 +24,7 @@ bool gTestOutputMode = false;
2324

2425
namespace ccls {
2526

26-
void JsonReader::iterArray(std::function<void()> fn) {
27+
void JsonReader::iterArray(llvm::function_ref<void()> fn) {
2728
if (!m->IsArray())
2829
throw std::invalid_argument("array");
2930
// Use "0" to indicate any element for now.
@@ -36,7 +37,7 @@ void JsonReader::iterArray(std::function<void()> fn) {
3637
}
3738
path_.pop_back();
3839
}
39-
void JsonReader::member(const char *name, std::function<void()> fn) {
40+
void JsonReader::member(const char *name, llvm::function_ref<void()> fn) {
4041
path_.push_back(name);
4142
auto it = m->FindMember(name);
4243
if (it != m->MemberEnd()) {
@@ -69,7 +70,7 @@ void JsonWriter::startObject() { m->StartObject(); }
6970
void JsonWriter::endObject() { m->EndObject(); }
7071
void JsonWriter::key(const char *name) { m->Key(name); }
7172
void JsonWriter::null_() { m->Null(); }
72-
void JsonWriter::int_(int v) { m->Int(v); }
73+
void JsonWriter::int64(int64_t v) { m->Int64(v); }
7374
void JsonWriter::string(const char *s) { m->String(s); }
7475
void JsonWriter::string(const char *s, size_t len) { m->String(s, len); }
7576

src/serializer.hh

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace llvm {
2323
class CachedHashStringRef;
2424
class StringRef;
25+
template <typename Fn> class function_ref;
2526
} // namespace llvm
2627

2728
namespace ccls {
@@ -36,8 +37,8 @@ struct JsonReader {
3637
JsonReader(rapidjson::Value *m) : m(m) {}
3738
void startObject() {}
3839
void endObject() {}
39-
void iterArray(std::function<void()> fn);
40-
void member(const char *name, std::function<void()> fn);
40+
void iterArray(llvm::function_ref<void()> fn);
41+
void member(const char *name, llvm::function_ref<void()> fn);
4142
bool isNull();
4243
std::string getString();
4344
std::string getPath() const;
@@ -57,7 +58,7 @@ struct JsonWriter {
5758
void endObject();
5859
void key(const char *name);
5960
void null_();
60-
void int_(int v);
61+
void int64(int64_t v);
6162
void string(const char *s);
6263
void string(const char *s, size_t len);
6364
};

src/working_files.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int alignColumn(const std::string &a, int column, std::string b, bool is_end) {
131131
if (column < head)
132132
return column;
133133
if ((int)a.size() - tail < column)
134-
return column + b.size() - a.size();
134+
return column + (int)b.size() - (int)a.size();
135135
if (std::max(a.size(), b.size()) - head - tail >= kMaxColumnAlignSize)
136136
return std::min(column, (int)b.size());
137137

0 commit comments

Comments
 (0)