mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-03 22:04:24 +00:00 
			
		
		
		
	Change Pos::line from int16_t to uint16_t
This allows representing line 0 ~ 65535.
This commit is contained in:
		
							parent
							
								
									dd9d21083b
								
							
						
					
					
						commit
						cafd2d4f77
					
				@ -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<int>(l, INT16_MAX),
 | 
			
		||||
  return {(uint16_t)std::min<int>(l, UINT16_MAX),
 | 
			
		||||
          (int16_t)std::min<int>(c, INT16_MAX)};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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) {}
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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<Range> res;
 | 
			
		||||
  switch (param.direction[0]) {
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@
 | 
			
		||||
namespace ccls {
 | 
			
		||||
Pos Pos::FromString(const std::string &encoded) {
 | 
			
		||||
  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 == ':');
 | 
			
		||||
  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<char *>(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<int>(column, INT16_MAX)};
 | 
			
		||||
  Pos p{(uint16_t)line, (int16_t)std::min<int>(column, INT16_MAX)};
 | 
			
		||||
  return !(p < start) && p < end;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user