mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
Simplify optional.
This commit is contained in:
parent
38cc501a8a
commit
062b1ad0fd
@ -2153,7 +2153,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
|
||||
std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
Config* config,
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
std::string file,
|
||||
@ -2163,7 +2163,7 @@ std::optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
|
||||
ClangIndex* index,
|
||||
bool dump_ast) {
|
||||
if (!config->index.enabled)
|
||||
return std::nullopt;
|
||||
return {};
|
||||
|
||||
file = NormalizePath(file);
|
||||
|
||||
@ -2183,7 +2183,7 @@ std::optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
|
||||
CXTranslationUnit_KeepGoing |
|
||||
CXTranslationUnit_DetailedPreprocessingRecord);
|
||||
if (!tu)
|
||||
return std::nullopt;
|
||||
return {};
|
||||
|
||||
perf->index_parse = timer.ElapsedMicrosecondsAndReset();
|
||||
|
||||
@ -2194,7 +2194,7 @@ std::optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
|
||||
args, unsaved_files);
|
||||
}
|
||||
|
||||
std::optional<std::vector<std::unique_ptr<IndexFile>>> ParseWithTu(
|
||||
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
||||
Config* config,
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
PerformanceImportFile* perf,
|
||||
@ -2239,7 +2239,7 @@ std::optional<std::vector<std::unique_ptr<IndexFile>>> ParseWithTu(
|
||||
if (index_result != CXError_Success) {
|
||||
LOG_S(ERROR) << "Indexing " << file
|
||||
<< " failed with errno=" << index_result;
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
clang_IndexAction_dispose(index_action);
|
||||
@ -2301,7 +2301,7 @@ std::optional<std::vector<std::unique_ptr<IndexFile>>> ParseWithTu(
|
||||
entry->dependencies.end());
|
||||
}
|
||||
|
||||
return std::move(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ConcatTypeAndName(std::string& type, const std::string& name) {
|
||||
|
@ -6,7 +6,7 @@ namespace {
|
||||
struct ClangIndexer : IIndexer {
|
||||
~ClangIndexer() override = default;
|
||||
|
||||
std::optional<std::vector<std::unique_ptr<IndexFile>>> Index(
|
||||
std::vector<std::unique_ptr<IndexFile>> Index(
|
||||
Config* config,
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
std::string file,
|
||||
@ -50,7 +50,7 @@ struct TestIndexer : IIndexer {
|
||||
|
||||
~TestIndexer() override = default;
|
||||
|
||||
std::optional<std::vector<std::unique_ptr<IndexFile>>> Index(
|
||||
std::vector<std::unique_ptr<IndexFile>> Index(
|
||||
Config* config,
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
std::string file,
|
||||
@ -61,14 +61,14 @@ struct TestIndexer : IIndexer {
|
||||
if (it == indexes.end()) {
|
||||
// Don't return any indexes for unexpected data.
|
||||
assert(false && "no indexes");
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
// FIXME: allow user to control how many times we return the index for a
|
||||
// specific file (atm it is always 1)
|
||||
auto result = std::move(it->second);
|
||||
indexes.erase(it);
|
||||
return std::move(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::vector<std::unique_ptr<IndexFile>>>
|
||||
|
@ -34,7 +34,7 @@ struct IIndexer {
|
||||
std::initializer_list<TestEntry> entries);
|
||||
|
||||
virtual ~IIndexer() = default;
|
||||
virtual std::optional<std::vector<std::unique_ptr<IndexFile>>> Index(
|
||||
virtual std::vector<std::unique_ptr<IndexFile>> Index(
|
||||
Config* config,
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
std::string file,
|
||||
|
@ -393,7 +393,7 @@ void ParseFile(Config* config,
|
||||
auto indexes = indexer->Index(config, file_consumer_shared, path_to_index,
|
||||
entry.args, file_contents, &perf);
|
||||
|
||||
if (!indexes) {
|
||||
if (indexes.empty()) {
|
||||
if (config->index.enabled &&
|
||||
!std::holds_alternative<std::monostate>(request.id)) {
|
||||
Out_Error out;
|
||||
@ -405,7 +405,7 @@ void ParseFile(Config* config,
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::unique_ptr<IndexFile>& new_index : *indexes) {
|
||||
for (std::unique_ptr<IndexFile>& new_index : indexes) {
|
||||
Timer time;
|
||||
|
||||
// Only emit diagnostics for non-interactive sessions, which makes it easier
|
||||
@ -556,11 +556,11 @@ void IndexWithTuFromCodeCompletion(
|
||||
ClangIndex index;
|
||||
auto indexes = ParseWithTu(config, file_consumer_shared, &perf, tu, &index,
|
||||
path, args, file_contents);
|
||||
if (!indexes)
|
||||
if (indexes.empty())
|
||||
return;
|
||||
|
||||
std::vector<Index_DoIdMap> result;
|
||||
for (std::unique_ptr<IndexFile>& new_index : *indexes) {
|
||||
for (std::unique_ptr<IndexFile>& new_index : indexes) {
|
||||
Timer time;
|
||||
|
||||
std::shared_ptr<ICacheManager> cache_manager;
|
||||
|
@ -517,7 +517,7 @@ struct NamespaceHelper {
|
||||
// |desired_index_file| is the (h or cc) file which has actually changed.
|
||||
// |dependencies| are the existing dependencies of |import_file| if this is a
|
||||
// reparse.
|
||||
std::optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
|
||||
std::vector<std::unique_ptr<IndexFile>> Parse(
|
||||
Config* config,
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
std::string file,
|
||||
@ -526,7 +526,7 @@ std::optional<std::vector<std::unique_ptr<IndexFile>>> Parse(
|
||||
PerformanceImportFile* perf,
|
||||
ClangIndex* index,
|
||||
bool dump_ast = false);
|
||||
std::optional<std::vector<std::unique_ptr<IndexFile>>> ParseWithTu(
|
||||
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
||||
Config* config,
|
||||
FileConsumerSharedState* file_consumer_shared,
|
||||
PerformanceImportFile* perf,
|
||||
|
@ -267,7 +267,6 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) {
|
||||
PerformanceImportFile perf;
|
||||
auto dbs = Parse(&config, &file_consumer_shared, path, flags, {}, &perf,
|
||||
&index, false /*dump_ast*/);
|
||||
assert(dbs);
|
||||
|
||||
for (const auto& entry : all_expected_output) {
|
||||
const std::string& expected_path = entry.first;
|
||||
@ -298,7 +297,7 @@ bool RunIndexTests(const std::string& filter_path, bool enable_update) {
|
||||
};
|
||||
|
||||
// Get output from index operation.
|
||||
IndexFile* db = FindDbForPathEnding(expected_path, *dbs);
|
||||
IndexFile* db = FindDbForPathEnding(expected_path, dbs);
|
||||
assert(db);
|
||||
if (!db->diagnostics_.empty()) {
|
||||
std::cout << "For " << path << std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user