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) std::string::npos)
continue; continue;
optional<QueryFileId> decl_file_id = Maybe<QueryFileId> decl_file_id =
GetDeclarationFileForSymbol(db, db->symbols[i]); GetDeclarationFileForSymbol(db, db->symbols[i]);
if (!decl_file_id) if (!decl_file_id)
continue; continue;

View File

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

View File

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

View File

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

View File

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

View File

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