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