From cc4d49794d8960b82208bfa2ec8e4f4a9f9548c9 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sat, 11 Mar 2017 00:07:32 -0800 Subject: [PATCH] outline fixes --- command_line.cc | 3 ++ indexer.cpp | 19 +-------- ipc.cc | 30 +++++++++++--- ipc.h | 17 -------- language_server_api.h | 13 ++++++ test.cc | 2 +- tests/outline/outline.cc | 48 +++++++++++++++++++++++ tests/outline/outline.h | 21 ---------- tests/outline/{outline2.h => outline2.cc} | 0 9 files changed, 91 insertions(+), 62 deletions(-) create mode 100644 tests/outline/outline.cc delete mode 100644 tests/outline/outline.h rename tests/outline/{outline2.h => outline2.cc} (100%) diff --git a/command_line.cc b/command_line.cc index 1b1cce5a..ce7447f6 100644 --- a/command_line.cc +++ b/command_line.cc @@ -436,6 +436,7 @@ void QueryDbMainLoop(IpcServer* ipc, QueryableDatabase* db) { info.kind = lsSymbolKind::Class; if (def.def.definition.has_value()) { + info.location.uri.SetPath(def.def.definition->path); info.location.range.start.line = def.def.definition->line - 1; info.location.range.start.character = def.def.definition->column - 1; } @@ -455,6 +456,7 @@ void QueryDbMainLoop(IpcServer* ipc, QueryableDatabase* db) { } if (def.def.definition.has_value()) { + info.location.uri.SetPath(def.def.definition->path); info.location.range.start.line = def.def.definition->line - 1; info.location.range.start.character = def.def.definition->column - 1; } @@ -467,6 +469,7 @@ void QueryDbMainLoop(IpcServer* ipc, QueryableDatabase* db) { info.kind = lsSymbolKind::Variable; if (def.def.definition.has_value()) { + info.location.uri.SetPath(def.def.definition->path); info.location.range.start.line = def.def.definition->line - 1; info.location.range.start.character = def.def.definition->column - 1; } diff --git a/indexer.cpp b/indexer.cpp index 128afb09..de9079cf 100644 --- a/indexer.cpp +++ b/indexer.cpp @@ -237,12 +237,7 @@ int abortQuery(CXClientData client_data, void *reserved) { void diagnostic(CXClientData client_data, CXDiagnosticSet diagnostics, void *reserved) { IndexParam* param = static_cast(client_data); - std::cerr << "!! Got diagnostic" << std::endl; - /** - * \brief Determine the number of diagnostics in a CXDiagnosticSet. - */ - //CINDEX_LINKAGE unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags); - + // Print any diagnostics to std::cerr for (unsigned i = 0; i < clang_getNumDiagnosticsInSet(diagnostics); ++i) { CXDiagnostic diagnostic = clang_getDiagnosticInSet(diagnostics, i); @@ -253,18 +248,6 @@ void diagnostic(CXClientData client_data, CXDiagnosticSet diagnostics, void *res clang_disposeDiagnostic(diagnostic); } - /** - * \brief Retrieve a diagnostic associated with the given CXDiagnosticSet. - * - * \param Diags the CXDiagnosticSet to query. - * \param Index the zero-based diagnostic number to retrieve. - * - * \returns the requested diagnostic. This diagnostic must be freed - * via a call to \c clang_disposeDiagnostic(). - */ - // CINDEX_LINKAGE CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags, - // unsigned Index); - } CXIdxClientFile enteredMainFile(CXClientData client_data, CXFile mainFile, void *reserved) { diff --git a/ipc.cc b/ipc.cc index 10bc662e..22326a80 100644 --- a/ipc.cc +++ b/ipc.cc @@ -1,6 +1,26 @@ #include "ipc.h" + + + namespace { + struct JsonMessage { + int message_id; + size_t payload_size; + + const char* payload(); + void SetPayload(size_t payload_size, const char* payload); + }; + + JsonMessage* get_free_message(IpcDirectionalChannel* channel) { + return reinterpret_cast(channel->shared->shared_start + *channel->shared->shared_bytes_used); + } + // Messages are funky objects. They contain potentially variable amounts of + // data and are passed between processes. This means that they need to be + // fully relocatable, ie, it is possible to memmove them in memory to a + // completely different address. + + JsonMessage* as_message(char* ptr) { return reinterpret_cast(ptr); } @@ -75,12 +95,12 @@ void IpcDirectionalChannel::PushMessage(BaseIpcMessageElided* message) { if ((*shared->shared_bytes_used + sizeof(JsonMessage) + payload_size) >= shmem_size) continue; - get_free_message()->message_id = message->hashed_runtime_id(); - get_free_message()->SetPayload(payload_size, output.GetString()); + get_free_message(this)->message_id = message->hashed_runtime_id(); + get_free_message(this)->SetPayload(payload_size, output.GetString()); - *shared->shared_bytes_used += sizeof(JsonMessage) + get_free_message()->payload_size; + *shared->shared_bytes_used += sizeof(JsonMessage) + get_free_message(this)->payload_size; assert(*shared->shared_bytes_used < shmem_size); - get_free_message()->message_id = -1; + get_free_message(this)->message_id = -1; break; } @@ -97,7 +117,7 @@ std::vector> IpcDirectionalChannel::TakeMe memcpy(local_block, shared->shared_start, *shared->shared_bytes_used); *shared->shared_bytes_used = 0; - get_free_message()->message_id = -1; + get_free_message(this)->message_id = -1; } std::vector> result; diff --git a/ipc.h b/ipc.h index 9c0328f2..bbf1d862 100644 --- a/ipc.h +++ b/ipc.h @@ -14,18 +14,6 @@ // TODO: We need to add support for payloads larger than the maximum shared memory buffer size. -// Messages are funky objects. They contain potentially variable amounts of -// data and are passed between processes. This means that they need to be -// fully relocatable, ie, it is possible to memmove them in memory to a -// completely different address. - -struct JsonMessage { - int message_id; - size_t payload_size; - - const char* payload(); - void SetPayload(size_t payload_size, const char* payload); -}; using IpcMessageId = std::string; @@ -130,11 +118,6 @@ struct IpcDirectionalChannel { void PushMessage(BaseIpcMessageElided* message); std::vector> TakeMessages(); -private: - JsonMessage* get_free_message() { - return reinterpret_cast(shared->shared_start + *shared->shared_bytes_used); - } - // Pointer to process shared memory and process shared mutex. std::unique_ptr shared; std::unique_ptr mutex; diff --git a/language_server_api.h b/language_server_api.h index dbe62e07..03ffaed2 100644 --- a/language_server_api.h +++ b/language_server_api.h @@ -384,6 +384,19 @@ struct In_CancelRequest : public InNotificationMessage { struct lsDocumentUri { std::string raw_uri; + void SetPath(const std::string& path) { + // file:///c%3A/Users/jacob/Desktop/superindex/indexer/full_tests + raw_uri = path; + + size_t index = raw_uri.find(":"); + if (index != -1) { + raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1, "%3A"); + } + + raw_uri = "file:///" + raw_uri; + //std::cerr << "Set uri to " << raw_uri << " from " << path; + } + std::string GetPath() { // TODO: make this not a hack. std::string result = raw_uri; diff --git a/test.cc b/test.cc index 355b92ba..b08ceda0 100644 --- a/test.cc +++ b/test.cc @@ -97,7 +97,7 @@ void RunTests() { for (std::string path : GetFilesInFolder("tests", true /*recursive*/, true /*add_folder_to_path*/)) { //if (path != "tests/templates/specialized_func_definition.cc") continue; - if (path != "tests/outline/outline2.h") continue; + //if (path != "tests/outline/outline2.cc") continue; //if (path == "tests/inheritance/class_inherit_templated_parent.cc") continue; //if (path != "tests/namespaces/namespace_reference.cc") continue; //if (path != "tests/stl.cc") continue; diff --git a/tests/outline/outline.cc b/tests/outline/outline.cc new file mode 100644 index 00000000..96a06714 --- /dev/null +++ b/tests/outline/outline.cc @@ -0,0 +1,48 @@ +#include + +struct MergeableUpdate { + int a; + int b; + std::vector to_add; +}; + +/* +OUTPUT: +{ + "types": [{ + "id": 0, + "usr": "c:@S@MergeableUpdate", + "short_name": "MergeableUpdate", + "qualified_name": "MergeableUpdate", + "definition": "1:3:8", + "vars": [0, 1, 2], + "uses": ["*1:3:8"] + }], + "vars": [{ + "id": 0, + "usr": "c:@S@MergeableUpdate@FI@a", + "short_name": "a", + "qualified_name": "MergeableUpdate::a", + "definition": "1:4:7", + "declaring_type": 0, + "uses": ["1:4:7"] + }, { + "id": 1, + "usr": "c:@S@MergeableUpdate@FI@b", + "short_name": "b", + "qualified_name": "MergeableUpdate::b", + "definition": "1:5:7", + "declaring_type": 0, + "uses": ["1:5:7"] + }, { + "id": 2, + "usr": "c:@S@MergeableUpdate@FI@to_add", + "short_name": "to_add", + "qualified_name": "MergeableUpdate::to_add", + "definition": "1:6:20", + "variable_type": 1, + "declaring_type": 0, + "uses": ["1:6:20"] + }] +} +*/ diff --git a/tests/outline/outline.h b/tests/outline/outline.h deleted file mode 100644 index 5b4473f7..00000000 --- a/tests/outline/outline.h +++ /dev/null @@ -1,21 +0,0 @@ -#include - -struct MergeableUpdate { - int a; - int b; - std::vector to_add; -}; - -/* -OUTPUT: -{ - "types": [{ - "id": 0, - "usr": "c:@S@MergeableUpdate", - "short_name": "MergeableUpdate", - "qualified_name": "MergeableUpdate", - "definition": "1:1:8", - "uses": ["*1:1:8"] - }] -} -*/ diff --git a/tests/outline/outline2.h b/tests/outline/outline2.cc similarity index 100% rename from tests/outline/outline2.h rename to tests/outline/outline2.cc