diff --git a/src/clang_tu.cc b/src/clang_tu.cc index d10ed746..22032742 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -43,7 +43,7 @@ static Pos Decomposed2LineAndCol(const SourceManager &SM, while (i < P.size() && (uint8_t)P[i] >= 128 && (uint8_t)P[i] < 192) i++; } - return {(int16_t)std::min(l, INT16_MAX), + return {(uint16_t)std::min(l, UINT16_MAX), (int16_t)std::min(c, INT16_MAX)}; } diff --git a/src/indexer.cc b/src/indexer.cc index b6653fc3..5b730fe6 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1151,8 +1151,8 @@ public: }; } // namespace -const int IndexFile::kMajorVersion = 19; -const int IndexFile::kMinorVersion = 1; +const int IndexFile::kMajorVersion = 20; +const int IndexFile::kMinorVersion = 0; IndexFile::IndexFile(const std::string &path, const std::string &contents) : path(path), file_contents(contents) {} diff --git a/src/message_handler.cc b/src/message_handler.cc index 7179931d..a770eb75 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -320,9 +320,9 @@ void EmitSemanticHighlight(DB *db, WorkingFile *wfile, QueryFile &file) { // but we still want to keep the range for jumping to definition. std::string_view concise_name = detailed_name.substr(0, detailed_name.find('<')); - int16_t start_line = sym.range.start.line; + uint16_t start_line = sym.range.start.line; int16_t start_col = sym.range.start.column; - if (start_line < 0 || start_line >= wfile->index_lines.size()) + if (start_line >= wfile->index_lines.size()) continue; std::string_view line = wfile->index_lines[start_line]; sym.range.end.line = start_line; diff --git a/src/messages/ccls_navigate.cc b/src/messages/ccls_navigate.cc index f2a6ac44..cb85ba7c 100644 --- a/src/messages/ccls_navigate.cc +++ b/src/messages/ccls_navigate.cc @@ -38,7 +38,7 @@ void MessageHandler::ccls_navigate(JsonReader &reader, ReplyOnce &reply) { if (auto line = wf->GetIndexPosFromBufferPos(ls_pos.line, &ls_pos.character, false)) ls_pos.line = *line; - Pos pos{(int16_t)ls_pos.line, (int16_t)ls_pos.character}; + Pos pos{(uint16_t)ls_pos.line, (int16_t)ls_pos.character}; Maybe res; switch (param.direction[0]) { diff --git a/src/position.cc b/src/position.cc index c615c2b9..c572421b 100644 --- a/src/position.cc +++ b/src/position.cc @@ -16,7 +16,7 @@ namespace ccls { Pos Pos::FromString(const std::string &encoded) { char *p = const_cast(encoded.c_str()); - int16_t line = int16_t(strtol(p, &p, 10)) - 1; + uint16_t line = uint16_t(strtoul(p, &p, 10) - 1); assert(*p == ':'); p++; int16_t column = int16_t(strtol(p, &p, 10)) - 1; @@ -32,14 +32,14 @@ std::string Pos::ToString() { Range Range::FromString(const std::string &encoded) { Pos start, end; char *p = const_cast(encoded.c_str()); - start.line = int16_t(strtol(p, &p, 10)) - 1; + start.line = uint16_t(strtoul(p, &p, 10) - 1); assert(*p == ':'); p++; start.column = int16_t(strtol(p, &p, 10)) - 1; assert(*p == '-'); p++; - end.line = int16_t(strtol(p, &p, 10)) - 1; + end.line = uint16_t(strtoul(p, &p, 10) - 1); assert(*p == ':'); p++; end.column = int16_t(strtol(p, nullptr, 10)) - 1; @@ -49,7 +49,7 @@ Range Range::FromString(const std::string &encoded) { bool Range::Contains(int line, int column) const { if (line > INT16_MAX) return false; - Pos p{(int16_t)line, (int16_t)std::min(column, INT16_MAX)}; + Pos p{(uint16_t)line, (int16_t)std::min(column, INT16_MAX)}; return !(p < start) && p < end; } diff --git a/src/position.hh b/src/position.hh index 0a08452b..35b1df9e 100644 --- a/src/position.hh +++ b/src/position.hh @@ -10,12 +10,12 @@ namespace ccls { struct Pos { - int16_t line = -1; + uint16_t line = 0; int16_t column = -1; static Pos FromString(const std::string &encoded); - bool Valid() const { return line >= 0; } + bool Valid() const { return column >= 0; } std::string ToString(); // Compare two Positions and check if they are equal. Ignores the value of