mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Query GetFileId returns Maybe<QueryFileId>
This commit is contained in:
parent
6c3cb7c5ea
commit
b71cf25186
@ -44,4 +44,8 @@ public:
|
||||
bool operator==(const Maybe& o) const {
|
||||
return storage == o.storage;
|
||||
}
|
||||
bool operator!=(const Maybe& o) const {
|
||||
return !(*this == o);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ struct Ipc_CqueryMemberHierarchyExpand
|
||||
: public RequestMessage<Ipc_CqueryMemberHierarchyExpand> {
|
||||
const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand;
|
||||
struct Params {
|
||||
QueryTypeId type_id;
|
||||
Maybe<QueryTypeId> type_id;
|
||||
};
|
||||
Params params;
|
||||
};
|
||||
@ -114,8 +114,8 @@ struct CqueryMemberHierarchyExpandHandler
|
||||
Out_CqueryMemberHierarchy out;
|
||||
out.id = request->id;
|
||||
// |ExpandNode| uses -1 to indicate invalid |type_id|.
|
||||
if (request->params.type_id.HasValue())
|
||||
out.result = ExpandNode(db, working_files, request->params.type_id);
|
||||
if (request->params.type_id.has_value())
|
||||
out.result = ExpandNode(db, working_files, *request->params.type_id);
|
||||
|
||||
QueueManager::WriteStdout(IpcId::CqueryMemberHierarchyExpand, out);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ optional<QueryFileId> GetImplementationFile(QueryDatabase* db,
|
||||
// Note: we ignore the definition if it is in the same file (ie,
|
||||
// possibly a header).
|
||||
if (func.def && func.def->extent) {
|
||||
QueryFileId t = db->GetFileId(*func.def->extent);
|
||||
Maybe<QueryFileId> t = db->GetFileId(*func.def->extent);
|
||||
if (t != file_id)
|
||||
return t;
|
||||
}
|
||||
@ -84,7 +84,7 @@ optional<QueryFileId> GetImplementationFile(QueryDatabase* db,
|
||||
// Note: we ignore the definition if it is in the same file (ie,
|
||||
// possibly a header).
|
||||
if (var.def && var.def->extent) {
|
||||
QueryFileId t = db->GetFileId(*var.def->extent);
|
||||
Maybe<QueryFileId> t = db->GetFileId(*var.def->extent);
|
||||
if (t != file_id)
|
||||
return t;
|
||||
}
|
||||
|
@ -91,11 +91,13 @@ void AddCodeLens(const char* singular,
|
||||
optional<lsRange> range = GetLsRange(common->working_file, loc.range);
|
||||
if (!range)
|
||||
return;
|
||||
Maybe<QueryFileId> file_id = common->db->GetFileId(loc);
|
||||
if (!file_id)
|
||||
return;
|
||||
code_lens.range = *range;
|
||||
code_lens.command = lsCommand<lsCodeLensCommandArguments>();
|
||||
code_lens.command->command = "cquery.showReferences";
|
||||
code_lens.command->arguments.uri =
|
||||
GetLsDocumentUri(common->db, common->db->GetFileId(loc));
|
||||
code_lens.command->arguments.uri = GetLsDocumentUri(common->db, *file_id);
|
||||
code_lens.command->arguments.position = code_lens.range.start;
|
||||
|
||||
// Add unique uses.
|
||||
|
@ -16,23 +16,23 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
|
||||
if (!ls_location)
|
||||
continue;
|
||||
|
||||
QueryFileId file_id = db->GetFileId(use);
|
||||
if (!file_id.HasValue())
|
||||
Maybe<QueryFileId> file_id = db->GetFileId(use);
|
||||
if (!file_id.has_value())
|
||||
continue;
|
||||
if (path_to_edit.find(file_id) == path_to_edit.end()) {
|
||||
path_to_edit[file_id] = lsTextDocumentEdit();
|
||||
if (path_to_edit.find(*file_id) == path_to_edit.end()) {
|
||||
path_to_edit[*file_id] = lsTextDocumentEdit();
|
||||
|
||||
QueryFile& file = db->files[file_id.id];
|
||||
QueryFile& file = db->files[file_id->id];
|
||||
if (!file.def)
|
||||
continue;
|
||||
|
||||
const std::string& path = file.def->path;
|
||||
path_to_edit[file_id].textDocument.uri =
|
||||
path_to_edit[*file_id].textDocument.uri =
|
||||
lsDocumentUri::FromPath(path);
|
||||
|
||||
WorkingFile* working_file = working_files->GetFileByFilename(path);
|
||||
if (working_file)
|
||||
path_to_edit[file_id].textDocument.version =
|
||||
path_to_edit[*file_id].textDocument.version =
|
||||
working_file->version;
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
|
||||
edit.newText = new_text;
|
||||
|
||||
// vscode complains if we submit overlapping text edits.
|
||||
auto& edits = path_to_edit[file_id].edits;
|
||||
auto& edits = path_to_edit[*file_id].edits;
|
||||
if (std::find(edits.begin(), edits.end(), edit) == edits.end())
|
||||
edits.push_back(edit);
|
||||
}
|
||||
|
@ -129,9 +129,9 @@ void AddMergeableRange(
|
||||
}
|
||||
}
|
||||
|
||||
// Compares |previous| and |current|, adding all elements that are
|
||||
// in |previous| but not |current| to |removed|, and all elements
|
||||
// that are in |current| but not |previous| to |added|.
|
||||
// Compares |previous| and |current|, adding all elements that are in |previous|
|
||||
// but not |current| to |removed|, and all elements that are in |current| but
|
||||
// not |previous| to |added|.
|
||||
//
|
||||
// Returns true iff |removed| or |added| are non-empty.
|
||||
template <typename T>
|
||||
|
@ -290,7 +290,7 @@ struct QueryDatabase {
|
||||
Maybe<QueryFuncId> GetQueryFuncIdFromUsr(Usr usr);
|
||||
Maybe<QueryVarId> GetQueryVarIdFromUsr(Usr usr);
|
||||
|
||||
QueryFileId GetFileId(SymbolIdx ref) {
|
||||
Maybe<QueryFileId> GetFileId(SymbolIdx ref) {
|
||||
switch (ref.kind) {
|
||||
case SymbolKind::Invalid:
|
||||
break;
|
||||
|
@ -379,10 +379,10 @@ optional<lsLocation> GetLsLocation(QueryDatabase* db,
|
||||
WorkingFiles* working_files,
|
||||
Reference ref) {
|
||||
std::string path;
|
||||
QueryFileId file_id = db->GetFileId(ref);
|
||||
if (!file_id.HasValue())
|
||||
Maybe<QueryFileId> file_id = db->GetFileId(ref);
|
||||
if (!file_id.has_value())
|
||||
return nullopt;
|
||||
lsDocumentUri uri = GetLsDocumentUri(db, file_id, &path);
|
||||
lsDocumentUri uri = GetLsDocumentUri(db, *file_id, &path);
|
||||
optional<lsRange> range =
|
||||
GetLsRange(working_files->GetFileByFilename(path), ref.range);
|
||||
if (!range)
|
||||
|
Loading…
Reference in New Issue
Block a user