mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-10-31 04:32:33 +00:00 
			
		
		
		
	Change Pos::line from int16_t to uint16_t
This allows representing line 0 ~ 65535.
This commit is contained in:
		
							parent
							
								
									43774f2c11
								
							
						
					
					
						commit
						c4ab72500b
					
				| @ -55,7 +55,7 @@ static Pos Decomposed2LineAndCol(const SourceManager &SM, | |||||||
|         while (i < P.size() && (uint8_t)P[i] >= 128 && (uint8_t)P[i] < 192) |         while (i < P.size() && (uint8_t)P[i] >= 128 && (uint8_t)P[i] < 192) | ||||||
|           i++; |           i++; | ||||||
|   } |   } | ||||||
|   return {(int16_t)std::min<int>(l, INT16_MAX), |   return {(uint16_t)std::min<int>(l, UINT16_MAX), | ||||||
|           (int16_t)std::min<int>(c, INT16_MAX)}; |           (int16_t)std::min<int>(c, INT16_MAX)}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1164,8 +1164,8 @@ public: | |||||||
| }; | }; | ||||||
| } // namespace
 | } // namespace
 | ||||||
| 
 | 
 | ||||||
| const int IndexFile::kMajorVersion = 19; | const int IndexFile::kMajorVersion = 20; | ||||||
| const int IndexFile::kMinorVersion = 1; | const int IndexFile::kMinorVersion = 0; | ||||||
| 
 | 
 | ||||||
| IndexFile::IndexFile(const std::string &path, const std::string &contents) | IndexFile::IndexFile(const std::string &path, const std::string &contents) | ||||||
|     : path(path), file_contents(contents) {} |     : path(path), file_contents(contents) {} | ||||||
|  | |||||||
| @ -332,9 +332,9 @@ void EmitSemanticHighlight(DB *db, WorkingFile *wfile, QueryFile &file) { | |||||||
|       // but we still want to keep the range for jumping to definition.
 |       // but we still want to keep the range for jumping to definition.
 | ||||||
|       std::string_view concise_name = |       std::string_view concise_name = | ||||||
|           detailed_name.substr(0, detailed_name.find('<')); |           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; |       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; |         continue; | ||||||
|       std::string_view line = wfile->index_lines[start_line]; |       std::string_view line = wfile->index_lines[start_line]; | ||||||
|       sym.range.end.line = start_line; |       sym.range.end.line = start_line; | ||||||
|  | |||||||
| @ -50,7 +50,7 @@ void MessageHandler::ccls_navigate(JsonReader &reader, ReplyOnce &reply) { | |||||||
|     if (auto line = |     if (auto line = | ||||||
|             wf->GetIndexPosFromBufferPos(ls_pos.line, &ls_pos.character, false)) |             wf->GetIndexPosFromBufferPos(ls_pos.line, &ls_pos.character, false)) | ||||||
|       ls_pos.line = *line; |       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<Range> res; |   Maybe<Range> res; | ||||||
|   switch (param.direction[0]) { |   switch (param.direction[0]) { | ||||||
|  | |||||||
| @ -28,7 +28,7 @@ limitations under the License. | |||||||
| namespace ccls { | namespace ccls { | ||||||
| Pos Pos::FromString(const std::string &encoded) { | Pos Pos::FromString(const std::string &encoded) { | ||||||
|   char *p = const_cast<char *>(encoded.c_str()); |   char *p = const_cast<char *>(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 == ':'); |   assert(*p == ':'); | ||||||
|   p++; |   p++; | ||||||
|   int16_t column = int16_t(strtol(p, &p, 10)) - 1; |   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) { | Range Range::FromString(const std::string &encoded) { | ||||||
|   Pos start, end; |   Pos start, end; | ||||||
|   char *p = const_cast<char *>(encoded.c_str()); |   char *p = const_cast<char *>(encoded.c_str()); | ||||||
|   start.line = int16_t(strtol(p, &p, 10)) - 1; |   start.line = uint16_t(strtoul(p, &p, 10) - 1); | ||||||
|   assert(*p == ':'); |   assert(*p == ':'); | ||||||
|   p++; |   p++; | ||||||
|   start.column = int16_t(strtol(p, &p, 10)) - 1; |   start.column = int16_t(strtol(p, &p, 10)) - 1; | ||||||
|   assert(*p == '-'); |   assert(*p == '-'); | ||||||
|   p++; |   p++; | ||||||
| 
 | 
 | ||||||
|   end.line = int16_t(strtol(p, &p, 10)) - 1; |   end.line = uint16_t(strtoul(p, &p, 10) - 1); | ||||||
|   assert(*p == ':'); |   assert(*p == ':'); | ||||||
|   p++; |   p++; | ||||||
|   end.column = int16_t(strtol(p, nullptr, 10)) - 1; |   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 { | bool Range::Contains(int line, int column) const { | ||||||
|   if (line > INT16_MAX) |   if (line > INT16_MAX) | ||||||
|     return false; |     return false; | ||||||
|   Pos p{(int16_t)line, (int16_t)std::min<int>(column, INT16_MAX)}; |   Pos p{(uint16_t)line, (int16_t)std::min<int>(column, INT16_MAX)}; | ||||||
|   return !(p < start) && p < end; |   return !(p < start) && p < end; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -22,12 +22,12 @@ limitations under the License. | |||||||
| 
 | 
 | ||||||
| namespace ccls { | namespace ccls { | ||||||
| struct Pos { | struct Pos { | ||||||
|   int16_t line = -1; |   uint16_t line = 0; | ||||||
|   int16_t column = -1; |   int16_t column = -1; | ||||||
| 
 | 
 | ||||||
|   static Pos FromString(const std::string &encoded); |   static Pos FromString(const std::string &encoded); | ||||||
| 
 | 
 | ||||||
|   bool Valid() const { return line >= 0; } |   bool Valid() const { return column >= 0; } | ||||||
|   std::string ToString(); |   std::string ToString(); | ||||||
| 
 | 
 | ||||||
|   // Compare two Positions and check if they are equal. Ignores the value of
 |   // Compare two Positions and check if they are equal. Ignores the value of
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user