From 85734278d87996e42c8eba633d37b6a15f28fed8 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Tue, 18 Apr 2017 17:05:14 -0700 Subject: [PATCH] Misc fixes --- README.md | 11 +++++++---- src/cache.cc | 2 +- src/command_line.cc | 12 ++++++------ src/indexer.cc | 30 ++++++++++++++++++++++++++++++ src/query.cc | 21 +++++++++++++-------- src/serializer.cc | 35 +++++++++++++++++++---------------- 6 files changed, 76 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 07211879..6517a76e 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,13 @@ $ npm install $ code . ``` -After VSCode is running, you can hit `F5` to launch the extension locally. Make -sure to open up settings and look over the configuration options. You will -probably want to increase the number of indexers that run from 7 to 40 or 50, -depending on how many cores are on your CPUs. +After VSCode is running, update the `ServerOptions` `cwd` parameter to point to +the absolute path of your build directory. + +You can hit then `F5` to launch the extension locally. Make sure to open up +settings and look over the configuration options. You will probably want to +increase the number of indexers that run from 7 to 40 or 50, depending on how +many CPU cores you have. If you run into issues, you can view debug output by running the (`F1`) `View: Toggle Output` command and opening the `cquery` output section. diff --git a/src/cache.cc b/src/cache.cc index cabb1840..5c121303 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -39,4 +39,4 @@ void WriteToCache(const std::string& cache_directory, const std::string& filenam assert(cache.good()); cache << indexed_content; cache.close(); -} \ No newline at end of file +} diff --git a/src/command_line.cc b/src/command_line.cc index df5e998c..bdca8211 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -82,7 +82,7 @@ struct IpcManager { // TODO: Rename TypedBidiMessageQueue to IpcTransport? using IpcMessageQueue = TypedBidiMessageQueue; - static constexpr const char* kIpcLanguageClientName = "language_client"; + static constexpr const char* kIpcLanguageClientName = "lanclient"; static constexpr const int kQueueSizeBytes = 1024 * 8; static IpcManager* instance_; @@ -970,8 +970,8 @@ void IndexMain( Index_DoIdMapQueue* queue_do_id_map, Index_OnIdMappedQueue* queue_on_id_mapped, Index_OnIndexedQueue* queue_on_indexed) { - SetCurrentThreadName("indexer"); + SetCurrentThreadName("indexer"); while (true) { // TODO: process all off IndexMain_DoIndex before calling IndexMain_DoCreateIndexUpdate for // better icache behavior. We need to have some threads spinning on both though @@ -1590,7 +1590,6 @@ void QueryDbMainLoop( } void QueryDbMain(IndexerConfig* config) { - SetCurrentThreadName("querydb"); //std::cerr << "Running QueryDb" << std::endl; // Create queues. @@ -1613,6 +1612,7 @@ void QueryDbMain(IndexerConfig* config) { } // Run query db main loop. + SetCurrentThreadName("querydb"); QueryDatabase db; while (true) { QueryDbMainLoop(config, &db, &queue_do_index, &queue_do_id_map, &queue_on_id_mapped, &queue_on_indexed, &project, &working_files, &completion_manager); @@ -1691,9 +1691,9 @@ void QueryDbMain(IndexerConfig* config) { // // |ipc| is connected to a server. void LanguageServerStdinLoop(IndexerConfig* config) { - SetCurrentThreadName("stdin"); IpcManager* ipc = IpcManager::instance(); + SetCurrentThreadName("stdin"); while (true) { std::unique_ptr message = MessageRegistry::instance()->ReadMessageFromStdin(); @@ -1890,12 +1890,12 @@ void LanguageServerMainLoop() { } void LanguageServerMain(IndexerConfig* config) { - SetCurrentThreadName("server"); - // Run language client. new std::thread([&config]() { LanguageServerStdinLoop(config); }); + + SetCurrentThreadName("server"); while (true) { LanguageServerMainLoop(); std::this_thread::sleep_for(std::chrono::milliseconds(2)); diff --git a/src/indexer.cc b/src/indexer.cc index b0b0395d..da386cdd 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -1406,6 +1406,9 @@ void indexEntityReference(CXClientData client_data, std::vector> Parse(IndexerConfig* config, FileConsumer::SharedState* file_consumer_shared, std::string filename, std::vector args, bool dump_ast) { + // NOTE: uncomment to disable indexer + //return {}; + filename = NormalizePath(filename); clang::Index index(0 /*excludeDeclarationsFromPCH*/, @@ -1446,6 +1449,33 @@ std::vector> Parse(IndexerConfig* config, FileConsu entry->path = NormalizePath(entry->path); entry->id_cache.primary_file = entry->path; } + + /* + TODO: Fix interesting checks. + for (auto& entry : result) { + for (auto& type : entry->types) { + if (!type.HasInterestingState()) { + std::cerr << "!!!! NO INTERSETING STATE FOR " << entry->path << " of !!! " << filename << std::endl; + std::cerr << "!!!! USR " << type.def.usr << std::endl; + assert(false); + } + } + for (auto& func : entry->funcs) { + if (!func.HasInterestingState()) { + std::cerr << "!!!! NO INTERSETING STATE FOR " << entry->path << " of !!! " << filename << std::endl; + std::cerr << "!!!! USR " << func.def.usr << std::endl; + assert(false); + } + } + for (auto& var : entry->vars) { + if (!var.HasInterestingState()) { + std::cerr << "!!!! NO INTERSETING STATE FOR " << entry->path << " of !!! " << filename << std::endl; + std::cerr << "!!!! USR " << var.def.usr << std::endl; + assert(false); + } + } + } + */ return result; } diff --git a/src/query.cc b/src/query.cc index b11b1137..b1f856da 100644 --- a/src/query.cc +++ b/src/query.cc @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -298,8 +299,9 @@ void CompareGroups( QueryFileId GetQueryFileIdFromPath(QueryDatabase* query_db, const std::string& path) { auto it = query_db->usr_to_symbol.find(path); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { - assert(it->second.kind == SymbolKind::File); - return QueryFileId(it->second.idx); + // TODO: should this be an assert? + if (it->second.kind == SymbolKind::File) + return QueryFileId(it->second.idx); } size_t idx = query_db->files.size(); @@ -311,8 +313,9 @@ QueryFileId GetQueryFileIdFromPath(QueryDatabase* query_db, const std::string& p QueryTypeId GetQueryTypeIdFromUsr(QueryDatabase* query_db, const Usr& usr) { auto it = query_db->usr_to_symbol.find(usr); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { - assert(it->second.kind == SymbolKind::Type); - return QueryTypeId(it->second.idx); + // TODO: should this be an assert? + if (it->second.kind == SymbolKind::Type) + return QueryTypeId(it->second.idx); } size_t idx = query_db->types.size(); @@ -324,8 +327,9 @@ QueryTypeId GetQueryTypeIdFromUsr(QueryDatabase* query_db, const Usr& usr) { QueryFuncId GetQueryFuncIdFromUsr(QueryDatabase* query_db, const Usr& usr) { auto it = query_db->usr_to_symbol.find(usr); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { - assert(it->second.kind == SymbolKind::Func); - return QueryFuncId(it->second.idx); + // TODO: should this be an assert? + if (it->second.kind == SymbolKind::Func) + return QueryFuncId(it->second.idx); } size_t idx = query_db->funcs.size(); @@ -337,8 +341,9 @@ QueryFuncId GetQueryFuncIdFromUsr(QueryDatabase* query_db, const Usr& usr) { QueryVarId GetQueryVarIdFromUsr(QueryDatabase* query_db, const Usr& usr) { auto it = query_db->usr_to_symbol.find(usr); if (it != query_db->usr_to_symbol.end() && it->second.kind != SymbolKind::Invalid) { - assert(it->second.kind == SymbolKind::Var); - return QueryVarId(it->second.idx); + // TODO: should this be an assert? + if (it->second.kind == SymbolKind::Var) + return QueryVarId(it->second.idx); } size_t idx = query_db->vars.size(); diff --git a/src/serializer.cc b/src/serializer.cc index 693caf21..6a5b7400 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -101,12 +101,13 @@ bool ReflectMemberStart(Reader& reader, IndexedTypeDef& value) { return true; } bool ReflectMemberStart(Writer& writer, IndexedTypeDef& value) { - if (!value.HasInterestingState()) - std::cerr << "bad"; - assert(value.HasInterestingState()); + // TODO: this is crashing + // if (!value.HasInterestingState()) + // std::cerr << "bad"; + // assert(value.HasInterestingState()); - //if (value.is_bad_def) - // return false; + if (!value.HasInterestingState()) + return false; DefaultReflectMemberStart(writer); return true; } @@ -137,12 +138,13 @@ bool ReflectMemberStart(Reader& reader, IndexedFuncDef& value) { return true; } bool ReflectMemberStart(Writer& writer, IndexedFuncDef& value) { + // TODO: this is crashing + // if (!value.HasInterestingState()) + // std::cerr << "bad"; + // assert(value.HasInterestingState()); + if (!value.HasInterestingState()) - std::cerr << "bad"; - assert(value.HasInterestingState()); - - //if (value.is_bad_def) - // return false; + return false; DefaultReflectMemberStart(writer); return true; } @@ -172,12 +174,13 @@ bool ReflectMemberStart(Reader& reader, IndexedVarDef& value) { return true; } bool ReflectMemberStart(Writer& writer, IndexedVarDef& value) { - if (!value.HasInterestingState()) - std::cerr << "bad"; - assert(value.HasInterestingState()); + // TODO: this is crashing + // if (!value.HasInterestingState()) + // std::cerr << "bad"; + // assert(value.HasInterestingState()); - //if (value.is_bad_def) - // return false; + if (!value.HasInterestingState()) + return false; DefaultReflectMemberStart(writer); return true; } @@ -246,7 +249,7 @@ optional Deserialize(std::string path, std::string serialized) { IndexedFile file(path); Reflect(reader, file); - + // Restore non-serialized state. file.path = path; file.id_cache.primary_file = file.path;