/* Copyright 2017-2018 ccls Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #pragma once #include "query.h" #include "working_files.h" #include Maybe GetDefinitionSpell(DB *db, SymbolIdx sym); Maybe GetDefinitionExtent(DB *db, SymbolIdx sym); // Get defining declaration (if exists) or an arbitrary declaration (otherwise) // for each id. std::vector GetFuncDeclarations(DB *, const std::vector &); std::vector GetTypeDeclarations(DB *, const std::vector &); std::vector GetVarDeclarations(DB *, const std::vector &, unsigned); // Get non-defining declarations. std::vector GetNonDefDeclarations(DB *db, SymbolIdx sym); std::vector GetUsesForAllBases(DB *db, QueryFunc &root); std::vector GetUsesForAllDerived(DB *db, QueryFunc &root); std::optional GetLsRange(WorkingFile *working_file, const Range &location); lsDocumentUri GetLsDocumentUri(DB *db, int file_id, std::string *path); lsDocumentUri GetLsDocumentUri(DB *db, int file_id); std::optional GetLsLocation(DB *db, WorkingFiles *wfiles, Use use); std::optional GetLsLocation(DB *db, WorkingFiles *wfiles, SymbolRef sym, int file_id); std::vector GetLsLocations(DB *db, WorkingFiles *wfiles, const std::vector &uses); // Returns a symbol. The symbol will *NOT* have a location assigned. std::optional GetSymbolInfo(DB *db, SymbolIdx sym, bool detailed); std::vector FindSymbolsAtLocation(WorkingFile *working_file, QueryFile *file, lsPosition &ls_pos, bool smallest = false); template void WithEntity(DB *db, SymbolIdx sym, Fn &&fn) { switch (sym.kind) { case SymbolKind::Invalid: case SymbolKind::File: break; case SymbolKind::Func: fn(db->GetFunc(sym)); break; case SymbolKind::Type: fn(db->GetType(sym)); break; case SymbolKind::Var: fn(db->GetVar(sym)); break; } } template void EachEntityDef(DB *db, SymbolIdx sym, Fn &&fn) { WithEntity(db, sym, [&](const auto &entity) { for (auto &def : entity.def) if (!fn(def)) break; }); } template void EachOccurrence(DB *db, SymbolIdx sym, bool include_decl, Fn &&fn) { WithEntity(db, sym, [&](const auto &entity) { for (Use use : entity.uses) fn(use); if (include_decl) { for (auto &def : entity.def) if (def.spell) fn(*def.spell); for (Use use : entity.declarations) fn(use); } }); } lsSymbolKind GetSymbolKind(DB *db, SymbolIdx sym); template void EachDefinedFunc(DB *db, const std::vector &usrs, Fn &&fn) { for (Usr usr : usrs) { auto &obj = db->Func(usr); if (!obj.def.empty()) fn(obj); } }