Cleanup some includes.

This commit is contained in:
Jacob Dufault 2017-12-29 10:29:47 -06:00
parent 48f3c75053
commit c596e55dcc
37 changed files with 135 additions and 86 deletions

View File

@ -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,

View File

@ -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<std::mutex> 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<std::mutex> 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) {}

View File

@ -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<std::string> 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<std::string> 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<CXFileUniqueID, std::unique_ptr<IndexFile>> local_;
SharedState* shared_;
FileConsumerSharedState* shared_;
std::string parse_file_;
};

View File

@ -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 <doctest/doctest.h>
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/ostreamwrapper.h>
#include <loguru.hpp>
#include <climits>
#include <fstream>
#include <functional>
#include <future>
#include <iostream>
#include <iterator>
#include <sstream>
#include <memory>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
ImportPipelineStatus::ImportPipelineStatus() : num_active_threads(0) {}
@ -67,7 +43,7 @@ std::vector<Index_DoIdMap> 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<Index_DoIdMap> 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<CXUnsavedFile>& file_contents,
const std::string& path,
@ -281,7 +257,7 @@ std::vector<Index_DoIdMap> 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<Index_DoIdMap> 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,

View File

@ -1,6 +1,7 @@
#pragma once
#include "file_consumer.h"
// FIXME: do not include clang-c outside of clang_ files.
#include <clang-c/Index.h>
#include <atomic>
#include <string>
@ -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<CXUnsavedFile>& file_contents,
const std::string& path,
const std::vector<std::string>& args);
void Indexer_Main(Config* config,
FileConsumer::SharedState* file_consumer_shared,
FileConsumerSharedState* file_consumer_shared,
TimestampManager* timestamp_manager,
ImportManager* import_manager,
ImportPipelineStatus* status,

View File

@ -1808,7 +1808,7 @@ optional<std::string> FileContentsWithOffsets::ContentsInRange(
std::vector<std::unique_ptr<IndexFile>> Parse(
Config* config,
FileConsumer::SharedState* file_consumer_shared,
FileConsumerSharedState* file_consumer_shared,
std::string file,
const std::vector<std::string>& args,
const std::vector<FileContents>& file_contents,
@ -1848,7 +1848,7 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
}
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
FileConsumer::SharedState* file_consumer_shared,
FileConsumerSharedState* file_consumer_shared,
PerformanceImportFile* perf,
ClangTranslationUnit* tu,
ClangIndex* index,

View File

@ -562,7 +562,7 @@ struct NamespaceHelper {
// reparse.
std::vector<std::unique_ptr<IndexFile>> Parse(
Config* config,
FileConsumer::SharedState* file_consumer_shared,
FileConsumerSharedState* file_consumer_shared,
std::string file,
const std::vector<std::string>& args,
const std::vector<FileContents>& file_contents,
@ -570,7 +570,7 @@ std::vector<std::unique_ptr<IndexFile>> Parse(
ClangIndex* index,
bool dump_ast = false);
std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
FileConsumer::SharedState* file_consumer_shared,
FileConsumerSharedState* file_consumer_shared,
PerformanceImportFile* perf,
ClangTranslationUnit* tu,
ClangIndex* index,

View File

@ -2,6 +2,8 @@
#include "lex_utils.h"
#include "query_utils.h"
#include "queue_manager.h"
#include "semantic_highlight_symbol_cache.h"
#include <loguru.hpp>

View File

@ -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 <optional.h>
#include <memory>
#include <vector>
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;

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_CqueryBase : public IpcMessage<Ipc_CqueryBase> {

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_CqueryCallTreeInitial

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_CqueryCallers : public IpcMessage<Ipc_CqueryCallers> {

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_CqueryDerived : public IpcMessage<Ipc_CqueryDerived> {

View File

@ -1,4 +1,6 @@
#include "clang_complete.h"
#include "message_handler.h"
#include "working_files.h"
namespace {
struct Ipc_CqueryTextDocumentDidView

View File

@ -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 <loguru.hpp>

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "platform.h"
#include "queue_manager.h"
#include <loguru/loguru.hpp>

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_CqueryTypeHierarchyTree

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_CqueryVars : public IpcMessage<Ipc_CqueryVars> {

View File

@ -1,5 +1,7 @@
#include "import_manager.h"
#include "import_pipeline.h"
#include "message_handler.h"
#include "queue_manager.h"
#include <loguru.hpp>

View File

@ -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 <loguru.hpp>
@ -174,8 +178,8 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
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);
});
}

View File

@ -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 <doctest/doctest.h>

View File

@ -1,5 +1,7 @@
#include "clang_complete.h"
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct lsDocumentCodeLensParams {

View File

@ -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<lsCompletionItem> results, bool is_cached_result) {
assert(!is_cached_result);
ClangCompleteManager::OnComplete freshen_global =
[this](std::vector<lsCompletionItem> 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_,

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
void PushBack(std::vector<lsLocation>* result, optional<lsLocation> location) {

View File

@ -1,4 +1,6 @@
#include "clang_complete.h"
#include "message_handler.h"
#include "working_files.h"
namespace {
struct Ipc_TextDocumentDidChange

View File

@ -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<Ipc_TextDocumentDidClose> {

View File

@ -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

View File

@ -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<Ipc_TextDocumentDidSave> {

View File

@ -1,5 +1,7 @@
#include "lex_utils.h"
#include "message_handler.h"
#include "queue_manager.h"
#include "working_files.h"
#include <loguru.hpp>

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct lsDocumentSymbolParams {

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {
struct Ipc_TextDocumentDocumentHighlight

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
#include <loguru.hpp>

View File

@ -1,5 +1,6 @@
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
namespace {

View File

@ -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 {

View File

@ -1,14 +1,15 @@
#include "lex_utils.h"
#include "message_handler.h"
#include "query_utils.h"
#include "queue_manager.h"
#include <loguru.hpp>
#include <ctype.h>
#include <limits.h>
#include <algorithm>
#include <functional>
#include "lex_utils.h"
#include "message_handler.h"
#include "query_utils.h"
#include <loguru.hpp>
namespace {
// Lookup |symbol| in |db| and insert the value into |result|.

View File

@ -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<std::unique_ptr<IndexFile>> dbs =
Parse(&config, &file_consumer_shared, path, flags, {}, &perf, &index,