diff --git a/src/message_handler.cc b/src/message_handler.cc index cc035691..1bf6c50e 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -142,15 +142,15 @@ void EmitSemanticHighlighting(QueryDatabase* db, // highlighted undesiredly. auto concise_name = detailed_name.substr(0, detailed_name.find('<')); if (sym.loc.range.start.line <= working_file->index_lines.size()) { - std::string& line = + const std::string& line = working_file->index_lines[sym.loc.range.start.line - 1]; - auto pos = line.find(concise_name); sym.loc.range.end.line = sym.loc.range.start.line; - if (pos == std::string::npos) - sym.loc.range.end.column = sym.loc.range.start.column; - else + int col = sym.loc.range.start.column - 1; + if (line.compare(col, concise_name.size(), concise_name) == 0) sym.loc.range.end.column = sym.loc.range.start.column + concise_name.size(); + else + sym.loc.range.end.column = sym.loc.range.start.column; } break; } diff --git a/src/working_files.cc b/src/working_files.cc index 086ee58f..5613a651 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -40,13 +40,13 @@ WorkingFile::WorkingFile(const std::string& filename, } void WorkingFile::SetIndexContent(const std::string& index_content) { - index_lines = ToLines(index_content, true /*trim_whitespace*/); + index_lines = ToLines(index_content, false /*trim_whitespace*/); // Build lookup buffer. index_lines_lookup.clear(); index_lines_lookup.reserve(index_lines.size()); for (int i = 0; i < index_lines.size(); ++i) { - const std::string& index_line = index_lines[i]; + std::string index_line = Trim(index_lines[i]); auto it = index_lines_lookup.find(index_line); if (it == index_lines_lookup.end()) @@ -97,7 +97,7 @@ optional WorkingFile::GetBufferLineFromIndexLine(int index_line) const { // Find the line in the cached index file. We'll try to find the most similar // line in the buffer and return the index for that. - std::string index = index_lines[index_line - 1]; + std::string index = Trim(index_lines[index_line - 1]); auto buffer_it = all_buffer_lines_lookup.find(index); if (buffer_it == all_buffer_lines_lookup.end()) { // TODO: Use levenshtein distance to find the best match (but only to an