diff --git a/src/command_line.cc b/src/command_line.cc index ab1d98c0..d7d22667 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -2,7 +2,9 @@ #include "cache.h" #include "cache_loader.h" #include "clang_complete.h" +#include "code_complete_cache.h" #include "file_consumer.h" +#include "import_manager.h" #include "import_pipeline.h" #include "include_complete.h" #include "indexer.h" @@ -17,6 +19,7 @@ #include "query.h" #include "query_utils.h" #include "queue_manager.h" +#include "semantic_highlight_symbol_cache.h" #include "serializer.h" #include "standard_includes.h" #include "test.h" @@ -96,7 +99,7 @@ bool QueryDbMainLoop(Config* config, QueryDatabase* db, MultiQueueWaiter* waiter, Project* project, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, ImportManager* import_manager, TimestampManager* timestamp_manager, SemanticHighlightSymbolCache* semantic_cache, @@ -144,7 +147,7 @@ void RunQueryDbThread(const std::string& bin_name, Project project; SemanticHighlightSymbolCache semantic_cache; WorkingFiles working_files; - FileConsumer::SharedState file_consumer_shared; + FileConsumerSharedState file_consumer_shared; ClangCompleteManager clang_complete( config, &project, &working_files, diff --git a/src/file_consumer.cc b/src/file_consumer.cc index 937f19cf..d2797376 100644 --- a/src/file_consumer.cc +++ b/src/file_consumer.cc @@ -12,19 +12,19 @@ bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b) { a.data[2] == b.data[2]; } -bool FileConsumer::SharedState::Mark(const std::string& file) { +bool FileConsumerSharedState::Mark(const std::string& file) { std::lock_guard lock(mutex); return files.insert(file).second; } -void FileConsumer::SharedState::Reset(const std::string& file) { +void FileConsumerSharedState::Reset(const std::string& file) { std::lock_guard lock(mutex); auto it = files.find(file); if (it != files.end()) files.erase(it); } -FileConsumer::FileConsumer(SharedState* shared_state, +FileConsumer::FileConsumer(FileConsumerSharedState* shared_state, const std::string& parse_file) : shared_(shared_state), parse_file_(parse_file) {} diff --git a/src/file_consumer.h b/src/file_consumer.h index e980777e..6b2b2792 100644 --- a/src/file_consumer.h +++ b/src/file_consumer.h @@ -15,6 +15,16 @@ struct IndexFile; MAKE_HASHABLE(CXFileUniqueID, t.data[0], t.data[1], t.data[2]); bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b); +struct FileConsumerSharedState { + mutable std::unordered_set files; + mutable std::mutex mutex; + + // Mark the file as used. Returns true if the file was not previously used. + bool Mark(const std::string& file); + // Reset the used state (ie, mark the file as unused). + void Reset(const std::string& file); +}; + // FileConsumer is used by the indexer. When it encouters a file, it tries to // take ownership over it. If the indexer has ownership over a file, it will // produce an index, otherwise, it will emit nothing for that declarations @@ -23,17 +33,8 @@ bool operator==(const CXFileUniqueID& a, const CXFileUniqueID& b); // The indexer does this because header files do not have their own translation // units but we still want to index them. struct FileConsumer { - struct SharedState { - mutable std::unordered_set files; - mutable std::mutex mutex; - - // Mark the file as used. Returns true if the file was not previously used. - bool Mark(const std::string& file); - // Reset the used state (ie, mark the file as unused). - void Reset(const std::string& file); - }; - - FileConsumer(SharedState* shared_state, const std::string& parse_file); + FileConsumer(FileConsumerSharedState* shared_state, + const std::string& parse_file); // Returns true if this instance owns given |file|. This will also attempt to // take ownership over |file|. @@ -53,6 +54,6 @@ struct FileConsumer { void EmitError(CXFile file) const; std::unordered_map> local_; - SharedState* shared_; + FileConsumerSharedState* shared_; std::string parse_file_; }; \ No newline at end of file diff --git a/src/import_pipeline.cc b/src/import_pipeline.cc index 1c67d5ef..b027f56a 100644 --- a/src/import_pipeline.cc +++ b/src/import_pipeline.cc @@ -1,47 +1,23 @@ #include "import_pipeline.h" -// TODO: cleanup includes #include "cache.h" #include "cache_loader.h" -#include "clang_complete.h" -#include "file_consumer.h" -#include "include_complete.h" -#include "indexer.h" +#include "config.h" +#include "import_manager.h" #include "language_server_api.h" -#include "lex_utils.h" -#include "lru_cache.h" -#include "match.h" #include "message_handler.h" -#include "options.h" #include "platform.h" #include "project.h" -#include "query.h" #include "query_utils.h" #include "queue_manager.h" -#include "serializer.h" -#include "standard_includes.h" -#include "test.h" -#include "threaded_queue.h" #include "timer.h" #include "timestamp_manager.h" -#include "work_thread.h" -#include "working_files.h" #include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include #include ImportPipelineStatus::ImportPipelineStatus() : num_active_threads(0) {} @@ -67,7 +43,7 @@ std::vector DoParseFile( Config* config, WorkingFiles* working_files, ClangIndex* index, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, TimestampManager* timestamp_manager, ImportManager* import_manager, CacheLoader* cache_loader, @@ -247,7 +223,7 @@ std::vector DoParseFile( // real-time indexing. // TODO: add option to disable this. void IndexWithTuFromCodeCompletion( - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, ClangTranslationUnit* tu, const std::vector& file_contents, const std::string& path, @@ -281,7 +257,7 @@ std::vector ParseFile( Config* config, WorkingFiles* working_files, ClangIndex* index, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, TimestampManager* timestamp_manager, ImportManager* import_manager, bool is_interactive, @@ -305,7 +281,7 @@ std::vector ParseFile( bool IndexMain_DoParse(Config* config, WorkingFiles* working_files, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, TimestampManager* timestamp_manager, ImportManager* import_manager, ClangIndex* index) { @@ -437,7 +413,7 @@ bool IndexMergeIndexUpdates() { } void Indexer_Main(Config* config, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, TimestampManager* timestamp_manager, ImportManager* import_manager, ImportPipelineStatus* status, diff --git a/src/import_pipeline.h b/src/import_pipeline.h index 314b91b5..3d3ce568 100644 --- a/src/import_pipeline.h +++ b/src/import_pipeline.h @@ -1,6 +1,7 @@ #pragma once -#include "file_consumer.h" +// FIXME: do not include clang-c outside of clang_ files. +#include #include #include @@ -8,6 +9,7 @@ struct ClangTranslationUnit; struct Config; +struct FileConsumerSharedState; struct ImportManager; struct MultiQueueWaiter; struct Project; @@ -23,14 +25,14 @@ struct ImportPipelineStatus { }; void IndexWithTuFromCodeCompletion( - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, ClangTranslationUnit* tu, const std::vector& file_contents, const std::string& path, const std::vector& args); void Indexer_Main(Config* config, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, TimestampManager* timestamp_manager, ImportManager* import_manager, ImportPipelineStatus* status, diff --git a/src/indexer.cc b/src/indexer.cc index 6df72c95..8291bcff 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1808,7 +1808,7 @@ optional FileContentsWithOffsets::ContentsInRange( std::vector> Parse( Config* config, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, std::string file, const std::vector& args, const std::vector& file_contents, @@ -1848,7 +1848,7 @@ std::vector> Parse( } std::vector> ParseWithTu( - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, PerformanceImportFile* perf, ClangTranslationUnit* tu, ClangIndex* index, diff --git a/src/indexer.h b/src/indexer.h index d6f1c032..f3f8b82b 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -562,7 +562,7 @@ struct NamespaceHelper { // reparse. std::vector> Parse( Config* config, - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, std::string file, const std::vector& args, const std::vector& file_contents, @@ -570,7 +570,7 @@ std::vector> Parse( ClangIndex* index, bool dump_ast = false); std::vector> ParseWithTu( - FileConsumer::SharedState* file_consumer_shared, + FileConsumerSharedState* file_consumer_shared, PerformanceImportFile* perf, ClangTranslationUnit* tu, ClangIndex* index, diff --git a/src/message_handler.cc b/src/message_handler.cc index 0c3e0651..f30687e4 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -2,6 +2,8 @@ #include "lex_utils.h" #include "query_utils.h" +#include "queue_manager.h" +#include "semantic_highlight_symbol_cache.h" #include diff --git a/src/message_handler.h b/src/message_handler.h index 1a2ca5b0..70387118 100644 --- a/src/message_handler.h +++ b/src/message_handler.h @@ -1,19 +1,28 @@ #pragma once -#include "cache_loader.h" -#include "clang_complete.h" -#include "code_complete_cache.h" -#include "config.h" -#include "import_manager.h" -#include "import_pipeline.h" -#include "include_complete.h" -#include "queue_manager.h" -#include "project.h" +#include "ipc.h" +#include "language_server_api.h" #include "query.h" -#include "semantic_highlight_symbol_cache.h" -#include "threaded_queue.h" -#include "timestamp_manager.h" -#include "working_files.h" + +#include + +#include +#include + +struct ClangCompleteManager; +struct CodeCompleteCache; +struct Config; +struct FileConsumerSharedState; +struct ImportManager; +struct ImportPipelineStatus; +struct IncludeComplete; +struct MultiQueueWaiter; +struct Project; +struct QueryDatabase; +struct SemanticHighlightSymbolCache; +struct TimestampManager; +struct WorkingFile; +struct WorkingFiles; // Usage: // @@ -33,7 +42,7 @@ struct MessageHandler { QueryDatabase* db = nullptr; MultiQueueWaiter* waiter = nullptr; Project* project = nullptr; - FileConsumer::SharedState* file_consumer_shared = nullptr; + FileConsumerSharedState* file_consumer_shared = nullptr; ImportManager* import_manager = nullptr; ImportPipelineStatus* import_pipeline_status = nullptr; TimestampManager* timestamp_manager = nullptr; diff --git a/src/messages/cquery_base.cc b/src/messages/cquery_base.cc index d2a20374..42cda8b9 100644 --- a/src/messages/cquery_base.cc +++ b/src/messages/cquery_base.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct Ipc_CqueryBase : public IpcMessage { diff --git a/src/messages/cquery_call_tree.cc b/src/messages/cquery_call_tree.cc index 429d5e06..13adcc06 100644 --- a/src/messages/cquery_call_tree.cc +++ b/src/messages/cquery_call_tree.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct Ipc_CqueryCallTreeInitial diff --git a/src/messages/cquery_callers.cc b/src/messages/cquery_callers.cc index f7f94656..1f2f06a5 100644 --- a/src/messages/cquery_callers.cc +++ b/src/messages/cquery_callers.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct Ipc_CqueryCallers : public IpcMessage { diff --git a/src/messages/cquery_derived.cc b/src/messages/cquery_derived.cc index bbd20eb5..290c4e4e 100644 --- a/src/messages/cquery_derived.cc +++ b/src/messages/cquery_derived.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct Ipc_CqueryDerived : public IpcMessage { diff --git a/src/messages/cquery_did_view.cc b/src/messages/cquery_did_view.cc index f0f1f185..34a9fdcd 100644 --- a/src/messages/cquery_did_view.cc +++ b/src/messages/cquery_did_view.cc @@ -1,4 +1,6 @@ +#include "clang_complete.h" #include "message_handler.h" +#include "working_files.h" namespace { struct Ipc_CqueryTextDocumentDidView diff --git a/src/messages/cquery_freshen_index.cc b/src/messages/cquery_freshen_index.cc index f5bf7083..be598f70 100644 --- a/src/messages/cquery_freshen_index.cc +++ b/src/messages/cquery_freshen_index.cc @@ -1,5 +1,10 @@ +#include "cache_loader.h" #include "message_handler.h" #include "platform.h" +#include "project.h" +#include "queue_manager.h" +#include "timestamp_manager.h" +#include "working_files.h" #include diff --git a/src/messages/cquery_index_file.cc b/src/messages/cquery_index_file.cc index 327e6dcc..ccfb7234 100644 --- a/src/messages/cquery_index_file.cc +++ b/src/messages/cquery_index_file.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "platform.h" +#include "queue_manager.h" #include diff --git a/src/messages/cquery_type_hierarchy_tree.cc b/src/messages/cquery_type_hierarchy_tree.cc index 61ba84cb..28bd2e62 100644 --- a/src/messages/cquery_type_hierarchy_tree.cc +++ b/src/messages/cquery_type_hierarchy_tree.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct Ipc_CqueryTypeHierarchyTree diff --git a/src/messages/cquery_vars.cc b/src/messages/cquery_vars.cc index eba89fcd..47fdd5ef 100644 --- a/src/messages/cquery_vars.cc +++ b/src/messages/cquery_vars.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct Ipc_CqueryVars : public IpcMessage { diff --git a/src/messages/cquery_wait.cc b/src/messages/cquery_wait.cc index 86d10e23..5211d1c4 100644 --- a/src/messages/cquery_wait.cc +++ b/src/messages/cquery_wait.cc @@ -1,5 +1,7 @@ +#include "import_manager.h" #include "import_pipeline.h" #include "message_handler.h" +#include "queue_manager.h" #include diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index abc24111..3e4c5f2d 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -1,7 +1,11 @@ #include "import_pipeline.h" +#include "include_complete.h" #include "message_handler.h" #include "platform.h" +#include "project.h" +#include "queue_manager.h" #include "timer.h" +#include "working_files.h" #include @@ -174,8 +178,8 @@ struct InitializeHandler : BaseMessageHandler { for (int i = 0; i < config->indexerCount; ++i) { WorkThread::StartThread("indexer" + std::to_string(i), [=]() { Indexer_Main(config, file_consumer_shared, timestamp_manager, - import_manager, import_pipeline_status, project, - working_files, waiter); + import_manager, import_pipeline_status, project, + working_files, waiter); }); } diff --git a/src/messages/text_document_code_action.cc b/src/messages/text_document_code_action.cc index e8fdb2c9..c38faf71 100644 --- a/src/messages/text_document_code_action.cc +++ b/src/messages/text_document_code_action.cc @@ -1,6 +1,8 @@ +#include "include_complete.h" #include "lex_utils.h" #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" #include diff --git a/src/messages/text_document_code_lens.cc b/src/messages/text_document_code_lens.cc index 06f8c02b..60f2256b 100644 --- a/src/messages/text_document_code_lens.cc +++ b/src/messages/text_document_code_lens.cc @@ -1,5 +1,7 @@ +#include "clang_complete.h" #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct lsDocumentCodeLensParams { diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index 8ad2cec7..33081501 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -1,4 +1,9 @@ +#include "clang_complete.h" +#include "code_complete_cache.h" +#include "include_complete.h" #include "message_handler.h" +#include "queue_manager.h" +#include "working_files.h" #include "lex_utils.h" @@ -222,14 +227,16 @@ struct TextDocumentCompletionHandler : MessageHandler { !global_code_complete_cache->cached_results_.empty(); }); if (is_cache_match) { - ClangCompleteManager::OnComplete freshen_global = [this]( - std::vector results, bool is_cached_result) { - assert(!is_cached_result); + ClangCompleteManager::OnComplete freshen_global = + [this](std::vector results, + bool is_cached_result) { + assert(!is_cached_result); - // note: path is updated in the normal completion handler. - global_code_complete_cache->WithLock( - [&]() { global_code_complete_cache->cached_results_ = results; }); - }; + // note: path is updated in the normal completion handler. + global_code_complete_cache->WithLock([&]() { + global_code_complete_cache->cached_results_ = results; + }); + }; global_code_complete_cache->WithLock([&]() { callback(global_code_complete_cache->cached_results_, diff --git a/src/messages/text_document_definition.cc b/src/messages/text_document_definition.cc index f7306e29..4bf83a4d 100644 --- a/src/messages/text_document_definition.cc +++ b/src/messages/text_document_definition.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { void PushBack(std::vector* result, optional location) { diff --git a/src/messages/text_document_did_change.cc b/src/messages/text_document_did_change.cc index b792a54a..b81e9c7a 100644 --- a/src/messages/text_document_did_change.cc +++ b/src/messages/text_document_did_change.cc @@ -1,4 +1,6 @@ +#include "clang_complete.h" #include "message_handler.h" +#include "working_files.h" namespace { struct Ipc_TextDocumentDidChange diff --git a/src/messages/text_document_did_close.cc b/src/messages/text_document_did_close.cc index d6e6bc85..43d21144 100644 --- a/src/messages/text_document_did_close.cc +++ b/src/messages/text_document_did_close.cc @@ -1,4 +1,7 @@ +#include "clang_complete.h" #include "message_handler.h" +#include "queue_manager.h" +#include "working_files.h" namespace { struct Ipc_TextDocumentDidClose : public IpcMessage { diff --git a/src/messages/text_document_did_open.cc b/src/messages/text_document_did_open.cc index f0477d31..8ff15855 100644 --- a/src/messages/text_document_did_open.cc +++ b/src/messages/text_document_did_open.cc @@ -1,6 +1,11 @@ #include "cache.h" +#include "clang_complete.h" +#include "include_complete.h" #include "message_handler.h" +#include "project.h" +#include "queue_manager.h" #include "timer.h" +#include "working_files.h" namespace { // Open, view, change, close file diff --git a/src/messages/text_document_did_save.cc b/src/messages/text_document_did_save.cc index 4432def6..0b9099c0 100644 --- a/src/messages/text_document_did_save.cc +++ b/src/messages/text_document_did_save.cc @@ -1,4 +1,7 @@ +#include "clang_complete.h" #include "message_handler.h" +#include "project.h" +#include "queue_manager.h" namespace { struct Ipc_TextDocumentDidSave : public IpcMessage { diff --git a/src/messages/text_document_document_link.cc b/src/messages/text_document_document_link.cc index 08bb20c1..f7248d8d 100644 --- a/src/messages/text_document_document_link.cc +++ b/src/messages/text_document_document_link.cc @@ -1,5 +1,7 @@ #include "lex_utils.h" #include "message_handler.h" +#include "queue_manager.h" +#include "working_files.h" #include diff --git a/src/messages/text_document_document_symbol.cc b/src/messages/text_document_document_symbol.cc index ea7958c9..37507a39 100644 --- a/src/messages/text_document_document_symbol.cc +++ b/src/messages/text_document_document_symbol.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct lsDocumentSymbolParams { diff --git a/src/messages/text_document_highlight.cc b/src/messages/text_document_highlight.cc index 4e988e95..d6ad3e81 100644 --- a/src/messages/text_document_highlight.cc +++ b/src/messages/text_document_highlight.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { struct Ipc_TextDocumentDocumentHighlight diff --git a/src/messages/text_document_hover.cc b/src/messages/text_document_hover.cc index 8e5e12a3..50ee1fd3 100644 --- a/src/messages/text_document_hover.cc +++ b/src/messages/text_document_hover.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { diff --git a/src/messages/text_document_references.cc b/src/messages/text_document_references.cc index 3294c6f8..8b55ebe3 100644 --- a/src/messages/text_document_references.cc +++ b/src/messages/text_document_references.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" #include diff --git a/src/messages/text_document_rename.cc b/src/messages/text_document_rename.cc index 5a5bfaf9..392a9b09 100644 --- a/src/messages/text_document_rename.cc +++ b/src/messages/text_document_rename.cc @@ -1,5 +1,6 @@ #include "message_handler.h" #include "query_utils.h" +#include "queue_manager.h" namespace { diff --git a/src/messages/text_document_signature_help.cc b/src/messages/text_document_signature_help.cc index a42aadc1..54d14605 100644 --- a/src/messages/text_document_signature_help.cc +++ b/src/messages/text_document_signature_help.cc @@ -1,4 +1,7 @@ +#include "clang_complete.h" +#include "code_complete_cache.h" #include "message_handler.h" +#include "queue_manager.h" #include "timer.h" namespace { diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index 7d803d4b..cb29ee68 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -1,14 +1,15 @@ +#include "lex_utils.h" +#include "message_handler.h" +#include "query_utils.h" +#include "queue_manager.h" + +#include + #include #include #include #include -#include "lex_utils.h" -#include "message_handler.h" -#include "query_utils.h" - -#include - namespace { // Lookup |symbol| in |db| and insert the value into |result|. diff --git a/src/test.cc b/src/test.cc index e66ec10f..80e24c01 100644 --- a/src/test.cc +++ b/src/test.cc @@ -160,7 +160,7 @@ void RunIndexTests(const std::string& filter_path) { // Run test. Config config; - FileConsumer::SharedState file_consumer_shared; + FileConsumerSharedState file_consumer_shared; PerformanceImportFile perf; std::vector> dbs = Parse(&config, &file_consumer_shared, path, flags, {}, &perf, &index,