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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 10 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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);

0 commit comments

Comments
 (0)