GetDefinitionSpellingOfSymbol: optional -> Maybe

This commit is contained in:
Fangrui Song 2018-02-10 00:19:17 -08:00
parent 749ecf0faa
commit bd4482df5e
6 changed files with 20 additions and 23 deletions

View File

@ -457,7 +457,7 @@ struct TextDocumentCodeActionHandler
std::string::npos)
continue;
optional<QueryFileId> decl_file_id =
Maybe<QueryFileId> decl_file_id =
GetDeclarationFileForSymbol(db, db->symbols[i]);
if (!decl_file_id)
continue;

View File

@ -175,8 +175,7 @@ struct TextDocumentCodeLensHandler
// extent since that is better for outline. This tries to convert the
// extent location to the spelling location.
auto try_ensure_spelling = [&](SymbolRef sym) {
optional<Reference> def =
GetDefinitionSpellingOfSymbol(db, sym);
Maybe<Reference> def = GetDefinitionSpellingOfSymbol(db, sym);
if (!def || db->GetFileId(*def) != db->GetFileId(sym) ||
def->range.start.line != sym.range.start.line) {
return sym;
@ -216,7 +215,7 @@ struct TextDocumentCodeLensHandler
// "Base"
if (func.def->base.size() == 1) {
optional<Reference> base_loc =
Maybe<Reference> base_loc =
GetDefinitionSpellingOfSymbol(db, func.def->base[0]);
if (base_loc) {
optional<lsLocation> ls_base =

View File

@ -74,12 +74,12 @@ struct TextDocumentDefinitionHandler
// - start at spelling but end at extent for better mouse tooltip
// - goto declaration while in definition of recursive type
optional<Reference> def_loc = GetDefinitionSpellingOfSymbol(db, sym);
Maybe<Reference> def_loc = GetDefinitionSpellingOfSymbol(db, sym);
// We use spelling start and extent end because this causes vscode to
// highlight the entire definition when previewing / hoving with the
// mouse.
optional<Reference> def_extent = GetDefinitionExtentOfSymbol(db, sym);
Maybe<Reference> def_extent = GetDefinitionExtentOfSymbol(db, sym);
if (def_loc && def_extent)
def_loc->range.end = def_extent->range.end;

View File

@ -22,7 +22,7 @@ bool InsertSymbolIntoResult(QueryDatabase* db,
if (!info)
return false;
optional<Reference> location = GetDefinitionExtentOfSymbol(db, symbol);
Maybe<Reference> location = GetDefinitionExtentOfSymbol(db, symbol);
Reference loc;
if (location)
loc = *location;

View File

@ -18,15 +18,15 @@ int ComputeRangeSize(const Range& range) {
} // namespace
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
const QueryFuncId& id) {
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
QueryFuncId id) {
QueryFunc& func = db->funcs[id.id];
if (func.def)
return func.def->definition_spelling;
return nullopt;
}
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
SymbolRef sym) {
switch (sym.kind) {
case SymbolKind::Type: {
@ -56,8 +56,7 @@ optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
return nullopt;
}
optional<Reference> GetDefinitionExtentOfSymbol(QueryDatabase* db,
SymbolRef sym) {
Maybe<Reference> GetDefinitionExtentOfSymbol(QueryDatabase* db, SymbolRef sym) {
switch (sym.kind) {
case SymbolKind::Type: {
QueryType& type = db->GetType(sym);
@ -87,7 +86,7 @@ optional<Reference> GetDefinitionExtentOfSymbol(QueryDatabase* db,
return nullopt;
}
optional<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
Maybe<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
SymbolRef sym) {
switch (sym.kind) {
case SymbolKind::Type: {

View File

@ -7,13 +7,12 @@
#include <optional.h>
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
const QueryFuncId& id);
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
QueryFuncId id);
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
SymbolRef sym);
optional<Reference> GetDefinitionExtentOfSymbol(QueryDatabase* db,
SymbolRef sym);
optional<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
Maybe<Reference> GetDefinitionExtentOfSymbol(QueryDatabase* db, SymbolRef sym);
Maybe<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
SymbolRef sym);
std::vector<Reference> ToReference(QueryDatabase* db,