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