diff --git a/src/clang_tu.cc b/src/clang_tu.cc index 8e1b6c43..c64a5ea6 100644 --- a/src/clang_tu.cc +++ b/src/clang_tu.cc @@ -55,7 +55,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 5b94bc18..49f20fe5 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1164,8 +1164,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 a9878f81..09b2d2a3 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -332,9 +332,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 2afef719..df27e6a0 100644 --- a/src/messages/ccls_navigate.cc +++ b/src/messages/ccls_navigate.cc @@ -50,7 +50,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 8211ff98..943d5751 100644 --- a/src/position.cc +++ b/src/position.cc @@ -28,7 +28,7 @@ limitations under the License. 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; @@ -44,14 +44,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; @@ -61,7 +61,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 d5bf241b..24f4bd4e 100644 --- a/src/position.hh +++ b/src/position.hh @@ -22,12 +22,12 @@ limitations under the License. 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