mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 19:07:08 +00:00
Fix shrinking region. (#290)
This commit is contained in:
parent
a7215c233c
commit
16f6fdbef1
@ -142,15 +142,15 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
|||||||
// highlighted undesiredly.
|
// highlighted undesiredly.
|
||||||
auto concise_name = detailed_name.substr(0, detailed_name.find('<'));
|
auto concise_name = detailed_name.substr(0, detailed_name.find('<'));
|
||||||
if (sym.loc.range.start.line <= working_file->index_lines.size()) {
|
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];
|
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;
|
sym.loc.range.end.line = sym.loc.range.start.line;
|
||||||
if (pos == std::string::npos)
|
int col = sym.loc.range.start.column - 1;
|
||||||
sym.loc.range.end.column = sym.loc.range.start.column;
|
if (line.compare(col, concise_name.size(), concise_name) == 0)
|
||||||
else
|
|
||||||
sym.loc.range.end.column =
|
sym.loc.range.end.column =
|
||||||
sym.loc.range.start.column + concise_name.size();
|
sym.loc.range.start.column + concise_name.size();
|
||||||
|
else
|
||||||
|
sym.loc.range.end.column = sym.loc.range.start.column;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,13 @@ WorkingFile::WorkingFile(const std::string& filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorkingFile::SetIndexContent(const std::string& index_content) {
|
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.
|
// Build lookup buffer.
|
||||||
index_lines_lookup.clear();
|
index_lines_lookup.clear();
|
||||||
index_lines_lookup.reserve(index_lines.size());
|
index_lines_lookup.reserve(index_lines.size());
|
||||||
for (int i = 0; i < index_lines.size(); ++i) {
|
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);
|
auto it = index_lines_lookup.find(index_line);
|
||||||
if (it == index_lines_lookup.end())
|
if (it == index_lines_lookup.end())
|
||||||
@ -97,7 +97,7 @@ optional<int> WorkingFile::GetBufferLineFromIndexLine(int index_line) const {
|
|||||||
|
|
||||||
// Find the line in the cached index file. We'll try to find the most similar
|
// 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.
|
// 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);
|
auto buffer_it = all_buffer_lines_lookup.find(index);
|
||||||
if (buffer_it == all_buffer_lines_lookup.end()) {
|
if (buffer_it == all_buffer_lines_lookup.end()) {
|
||||||
// TODO: Use levenshtein distance to find the best match (but only to an
|
// TODO: Use levenshtein distance to find the best match (but only to an
|
||||||
|
Loading…
Reference in New Issue
Block a user