Query GetFileId returns Maybe<QueryFileId>

This commit is contained in:
Jacob Dufault 2018-02-11 13:42:48 -08:00
parent 6c3cb7c5ea
commit b71cf25186
8 changed files with 28 additions and 22 deletions

View File

@ -44,4 +44,8 @@ public:
bool operator==(const Maybe& o) const { bool operator==(const Maybe& o) const {
return storage == o.storage; return storage == o.storage;
} }
bool operator!=(const Maybe& o) const {
return !(*this == o);
}
}; };

View File

@ -15,7 +15,7 @@ struct Ipc_CqueryMemberHierarchyExpand
: public RequestMessage<Ipc_CqueryMemberHierarchyExpand> { : public RequestMessage<Ipc_CqueryMemberHierarchyExpand> {
const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand; const static IpcId kIpcId = IpcId::CqueryMemberHierarchyExpand;
struct Params { struct Params {
QueryTypeId type_id; Maybe<QueryTypeId> type_id;
}; };
Params params; Params params;
}; };
@ -114,8 +114,8 @@ struct CqueryMemberHierarchyExpandHandler
Out_CqueryMemberHierarchy out; Out_CqueryMemberHierarchy out;
out.id = request->id; out.id = request->id;
// |ExpandNode| uses -1 to indicate invalid |type_id|. // |ExpandNode| uses -1 to indicate invalid |type_id|.
if (request->params.type_id.HasValue()) if (request->params.type_id.has_value())
out.result = ExpandNode(db, working_files, request->params.type_id); out.result = ExpandNode(db, working_files, *request->params.type_id);
QueueManager::WriteStdout(IpcId::CqueryMemberHierarchyExpand, out); QueueManager::WriteStdout(IpcId::CqueryMemberHierarchyExpand, out);
} }

View File

@ -73,7 +73,7 @@ optional<QueryFileId> GetImplementationFile(QueryDatabase* db,
// Note: we ignore the definition if it is in the same file (ie, // Note: we ignore the definition if it is in the same file (ie,
// possibly a header). // possibly a header).
if (func.def && func.def->extent) { 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) if (t != file_id)
return t; return t;
} }
@ -84,7 +84,7 @@ optional<QueryFileId> GetImplementationFile(QueryDatabase* db,
// Note: we ignore the definition if it is in the same file (ie, // Note: we ignore the definition if it is in the same file (ie,
// possibly a header). // possibly a header).
if (var.def && var.def->extent) { 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) if (t != file_id)
return t; return t;
} }

View File

@ -91,11 +91,13 @@ void AddCodeLens(const char* singular,
optional<lsRange> range = GetLsRange(common->working_file, loc.range); optional<lsRange> range = GetLsRange(common->working_file, loc.range);
if (!range) if (!range)
return; return;
Maybe<QueryFileId> file_id = common->db->GetFileId(loc);
if (!file_id)
return;
code_lens.range = *range; code_lens.range = *range;
code_lens.command = lsCommand<lsCodeLensCommandArguments>(); code_lens.command = lsCommand<lsCodeLensCommandArguments>();
code_lens.command->command = "cquery.showReferences"; code_lens.command->command = "cquery.showReferences";
code_lens.command->arguments.uri = code_lens.command->arguments.uri = GetLsDocumentUri(common->db, *file_id);
GetLsDocumentUri(common->db, common->db->GetFileId(loc));
code_lens.command->arguments.position = code_lens.range.start; code_lens.command->arguments.position = code_lens.range.start;
// Add unique uses. // Add unique uses.

View File

@ -16,23 +16,23 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
if (!ls_location) if (!ls_location)
continue; continue;
QueryFileId file_id = db->GetFileId(use); Maybe<QueryFileId> file_id = db->GetFileId(use);
if (!file_id.HasValue()) if (!file_id.has_value())
continue; continue;
if (path_to_edit.find(file_id) == path_to_edit.end()) { if (path_to_edit.find(*file_id) == path_to_edit.end()) {
path_to_edit[file_id] = lsTextDocumentEdit(); path_to_edit[*file_id] = lsTextDocumentEdit();
QueryFile& file = db->files[file_id.id]; QueryFile& file = db->files[file_id->id];
if (!file.def) if (!file.def)
continue; continue;
const std::string& path = file.def->path; const std::string& path = file.def->path;
path_to_edit[file_id].textDocument.uri = path_to_edit[*file_id].textDocument.uri =
lsDocumentUri::FromPath(path); lsDocumentUri::FromPath(path);
WorkingFile* working_file = working_files->GetFileByFilename(path); WorkingFile* working_file = working_files->GetFileByFilename(path);
if (working_file) if (working_file)
path_to_edit[file_id].textDocument.version = path_to_edit[*file_id].textDocument.version =
working_file->version; working_file->version;
} }
@ -41,7 +41,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
edit.newText = new_text; edit.newText = new_text;
// vscode complains if we submit overlapping text edits. // 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()) if (std::find(edits.begin(), edits.end(), edit) == edits.end())
edits.push_back(edit); edits.push_back(edit);
} }

View File

@ -129,9 +129,9 @@ void AddMergeableRange(
} }
} }
// Compares |previous| and |current|, adding all elements that are // Compares |previous| and |current|, adding all elements that are in |previous|
// in |previous| but not |current| to |removed|, and all elements // but not |current| to |removed|, and all elements that are in |current| but
// that are in |current| but not |previous| to |added|. // not |previous| to |added|.
// //
// Returns true iff |removed| or |added| are non-empty. // Returns true iff |removed| or |added| are non-empty.
template <typename T> template <typename T>

View File

@ -290,7 +290,7 @@ struct QueryDatabase {
Maybe<QueryFuncId> GetQueryFuncIdFromUsr(Usr usr); Maybe<QueryFuncId> GetQueryFuncIdFromUsr(Usr usr);
Maybe<QueryVarId> GetQueryVarIdFromUsr(Usr usr); Maybe<QueryVarId> GetQueryVarIdFromUsr(Usr usr);
QueryFileId GetFileId(SymbolIdx ref) { Maybe<QueryFileId> GetFileId(SymbolIdx ref) {
switch (ref.kind) { switch (ref.kind) {
case SymbolKind::Invalid: case SymbolKind::Invalid:
break; break;

View File

@ -379,10 +379,10 @@ optional<lsLocation> GetLsLocation(QueryDatabase* db,
WorkingFiles* working_files, WorkingFiles* working_files,
Reference ref) { Reference ref) {
std::string path; std::string path;
QueryFileId file_id = db->GetFileId(ref); Maybe<QueryFileId> file_id = db->GetFileId(ref);
if (!file_id.HasValue()) if (!file_id.has_value())
return nullopt; return nullopt;
lsDocumentUri uri = GetLsDocumentUri(db, file_id, &path); lsDocumentUri uri = GetLsDocumentUri(db, *file_id, &path);
optional<lsRange> range = optional<lsRange> range =
GetLsRange(working_files->GetFileByFilename(path), ref.range); GetLsRange(working_files->GetFileByFilename(path), ref.range);
if (!range) if (!range)