mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Refactor quote extraction
This commit is contained in:
parent
f5ed2828c3
commit
2e3e1e0427
@ -144,7 +144,31 @@ bool ShouldRunIncludeCompletion(const std::string& line) {
|
|||||||
return start < line.size() && line[start] == '#';
|
return start < line.size() && line[start] == '#';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional<lsRange> ExtractQuotedRange(int line_number, const std::string& line) {
|
||||||
|
// Find starting and ending quote.
|
||||||
|
int start = 0;
|
||||||
|
while (start < line.size()) {
|
||||||
|
char c = line[start];
|
||||||
|
++start;
|
||||||
|
if (c == '"' || c == '<')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (start == line.size())
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
|
int end = (int)line.size();
|
||||||
|
while (end > 0) {
|
||||||
|
char c = line[end];
|
||||||
|
if (c == '"' || c == '>')
|
||||||
|
break;
|
||||||
|
--end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start >= end)
|
||||||
|
return nullopt;
|
||||||
|
|
||||||
|
return lsRange(lsPosition(line_number, start), lsPosition(line_number, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -2325,35 +2349,15 @@ bool QueryDbMainLoop(
|
|||||||
if (!buffer_line || !buffer_line_content)
|
if (!buffer_line || !buffer_line_content)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Find starting and ending quote.
|
// Subtract 1 from line because querydb stores 1-based lines but
|
||||||
int start = 0;
|
// vscode expects 0-based lines.
|
||||||
while (start < buffer_line_content->size()) {
|
optional<lsRange> between_quotes = ExtractQuotedRange(*buffer_line - 1, *buffer_line_content);
|
||||||
char c = (*buffer_line_content)[start];
|
if (!between_quotes)
|
||||||
++start;
|
|
||||||
if (c == '"' || c == '<')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (start == buffer_line_content->size())
|
|
||||||
continue;
|
continue;
|
||||||
int end = (int)buffer_line_content->size();
|
|
||||||
while (end > 0) {
|
|
||||||
char c = (*buffer_line_content)[end];
|
|
||||||
if (c == '"' || c == '>')
|
|
||||||
break;
|
|
||||||
--end;
|
|
||||||
}
|
|
||||||
if (start >= end)
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
lsDocumentLink link;
|
lsDocumentLink link;
|
||||||
link.target = lsDocumentUri::FromPath(include.resolved_path);
|
link.target = lsDocumentUri::FromPath(include.resolved_path);
|
||||||
// Subtract 1 from line because querydb stores 1-based lines but
|
link.range = *between_quotes;
|
||||||
// vscode expects 0-based lines.
|
|
||||||
link.range.start.line = *buffer_line - 1;
|
|
||||||
link.range.start.character = start;
|
|
||||||
link.range.end.line = *buffer_line - 1;
|
|
||||||
link.range.end.character = end;
|
|
||||||
response.result.push_back(link);
|
response.result.push_back(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user