mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
Refactor out FindSymbolsAtLocation
This commit is contained in:
parent
c946fd1b8e
commit
1791f4c3b7
@ -468,6 +468,20 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryableDatabase* db, WorkingFiles* working_
|
||||
return edit;
|
||||
}
|
||||
|
||||
std::vector<SymbolRef> FindSymbolsAtLocation(QueryableFile* file, lsPosition position) {
|
||||
std::vector<SymbolRef> symbols;
|
||||
symbols.reserve(1);
|
||||
|
||||
int target_line = position.line + 1;
|
||||
int target_column = position.character + 1;
|
||||
for (const SymbolRef& ref : file->def.all_symbols) {
|
||||
if (ref.loc.range.Contains(target_line, target_column))
|
||||
symbols.push_back(ref);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@ -489,6 +503,34 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryableDatabase* db, WorkingFiles* working_
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -889,19 +931,12 @@ void QueryDbMainLoop(
|
||||
Out_TextDocumentRename response;
|
||||
response.id = msg->id;
|
||||
|
||||
// TODO: consider refactoring into FindSymbolsAtLocation(file);
|
||||
int target_line = msg->params.position.line + 1;
|
||||
int target_column = msg->params.position.character + 1;
|
||||
for (const SymbolRef& ref : file->def.all_symbols) {
|
||||
if (ref.loc.range.start.line >= target_line && ref.loc.range.end.line <= target_line &&
|
||||
ref.loc.range.start.column <= target_column && ref.loc.range.end.column >= target_column) {
|
||||
|
||||
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
|
||||
// Found symbol. Return references to rename.
|
||||
std::vector<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx);
|
||||
response.result = BuildWorkspaceEdit(db, working_files, uses, msg->params.newName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
response.Write(std::cerr);
|
||||
SendOutMessageToClient(language_client, response);
|
||||
@ -939,8 +974,7 @@ void QueryDbMainLoop(
|
||||
int target_line = msg->params.position.line + 1;
|
||||
int target_column = msg->params.position.character + 1;
|
||||
|
||||
for (const SymbolRef& ref : file->def.all_symbols) {
|
||||
if (ref.loc.range.Contains(target_line, target_column)) {
|
||||
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
|
||||
// Found symbol. Return definition.
|
||||
|
||||
// Special cases which are handled:
|
||||
@ -982,7 +1016,6 @@ void QueryDbMainLoop(
|
||||
if (!response.result.empty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SendOutMessageToClient(language_client, response);
|
||||
break;
|
||||
@ -1000,13 +1033,7 @@ void QueryDbMainLoop(
|
||||
Out_TextDocumentDocumentHighlight response;
|
||||
response.id = msg->id;
|
||||
|
||||
// TODO: consider refactoring into FindSymbolsAtLocation(file);
|
||||
int target_line = msg->params.position.line + 1;
|
||||
int target_column = msg->params.position.character + 1;
|
||||
for (const SymbolRef& ref : file->def.all_symbols) {
|
||||
if (ref.loc.range.start.line >= target_line && ref.loc.range.end.line <= target_line &&
|
||||
ref.loc.range.start.column <= target_column && ref.loc.range.end.column >= target_column) {
|
||||
|
||||
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
|
||||
// Found symbol. Return references to highlight.
|
||||
std::vector<QueryableLocation> uses = GetUsesOfSymbol(db, ref.idx);
|
||||
response.result.reserve(uses.size());
|
||||
@ -1025,7 +1052,6 @@ void QueryDbMainLoop(
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SendOutMessageToClient(language_client, response);
|
||||
break;
|
||||
@ -1042,13 +1068,7 @@ void QueryDbMainLoop(
|
||||
Out_TextDocumentHover response;
|
||||
response.id = msg->id;
|
||||
|
||||
// TODO: consider refactoring into FindSymbolsAtLocation(file);
|
||||
int target_line = msg->params.position.line + 1;
|
||||
int target_column = msg->params.position.character + 1;
|
||||
for (const SymbolRef& ref : file->def.all_symbols) {
|
||||
if (ref.loc.range.start.line >= target_line && ref.loc.range.end.line <= target_line &&
|
||||
ref.loc.range.start.column <= target_column && ref.loc.range.end.column >= target_column) {
|
||||
|
||||
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
|
||||
// Found symbol. Return hover.
|
||||
optional<lsRange> ls_range = GetLsRange(working_files->GetFileByFilename(file->def.usr), ref.loc.range);
|
||||
if (!ls_range)
|
||||
@ -1058,7 +1078,6 @@ void QueryDbMainLoop(
|
||||
response.result.range = *ls_range;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SendOutMessageToClient(language_client, response);
|
||||
break;
|
||||
@ -1076,13 +1095,7 @@ void QueryDbMainLoop(
|
||||
Out_TextDocumentReferences response;
|
||||
response.id = msg->id;
|
||||
|
||||
// TODO: consider refactoring into FindSymbolsAtLocation(file);
|
||||
int target_line = msg->params.position.line + 1;
|
||||
int target_column = msg->params.position.character + 1;
|
||||
for (const SymbolRef& ref : file->def.all_symbols) {
|
||||
if (ref.loc.range.start.line >= target_line && ref.loc.range.end.line <= target_line &&
|
||||
ref.loc.range.start.column <= target_column && ref.loc.range.end.column >= target_column) {
|
||||
|
||||
for (const SymbolRef& ref : FindSymbolsAtLocation(file, msg->params.position)) {
|
||||
optional<QueryableLocation> excluded_declaration;
|
||||
if (!msg->params.context.includeDeclaration) {
|
||||
std::cerr << "Excluding declaration in references" << std::endl;
|
||||
@ -1102,7 +1115,6 @@ void QueryDbMainLoop(
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SendOutMessageToClient(language_client, response);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user