mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 09:05:10 +00:00
cmake: link against zlib; use StringMap
This commit is contained in:
parent
d2e0c7ca24
commit
c279090ac5
@ -118,5 +118,6 @@ if(Clang_FOUND AND NOT TARGET Clang::Clang)
|
|||||||
INTERFACE_INCLUDE_DIRECTORIES "${Clang_INCLUDE_DIR};${Clang_BUILD_INCLUDE_DIR};${LLVM_INCLUDE_DIR};${LLVM_BUILD_INCLUDE_DIR}")
|
INTERFACE_INCLUDE_DIRECTORIES "${Clang_INCLUDE_DIR};${Clang_BUILD_INCLUDE_DIR};${LLVM_INCLUDE_DIR};${LLVM_BUILD_INCLUDE_DIR}")
|
||||||
|
|
||||||
find_package(Curses REQUIRED)
|
find_package(Curses REQUIRED)
|
||||||
set_property(TARGET Clang::Clang PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES "${_Clang_LIBRARIES};${CURSES_LIBRARIES}")
|
find_package(ZLIB REQUIRED)
|
||||||
|
set_property(TARGET Clang::Clang PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES "${_Clang_LIBRARIES};${CURSES_LIBRARIES};${ZLIB_LIBRARIES}")
|
||||||
endif()
|
endif()
|
||||||
|
@ -115,11 +115,11 @@ bool Indexer_Parse(DiagnosticsEngine* diag_engine,
|
|||||||
path_to_index, entry.args, std::nullopt))
|
path_to_index, entry.args, std::nullopt))
|
||||||
reparse = 2;
|
reparse = 2;
|
||||||
for (const auto& dep : prev->dependencies)
|
for (const auto& dep : prev->dependencies)
|
||||||
if (auto write_time1 = LastWriteTime(dep.first)) {
|
if (auto write_time1 = LastWriteTime(dep.first().str())) {
|
||||||
if (dep.second < *write_time1) {
|
if (dep.second < *write_time1) {
|
||||||
reparse = 2;
|
reparse = 2;
|
||||||
std::lock_guard<std::mutex> lock(vfs->mutex);
|
std::lock_guard<std::mutex> lock(vfs->mutex);
|
||||||
vfs->state[dep.first].stage = 0;
|
vfs->state[dep.first().str()].stage = 0;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
reparse = 2;
|
reparse = 2;
|
||||||
@ -134,8 +134,8 @@ bool Indexer_Parse(DiagnosticsEngine* diag_engine,
|
|||||||
request.is_interactive);
|
request.is_interactive);
|
||||||
}
|
}
|
||||||
for (const auto& dep : dependencies)
|
for (const auto& dep : dependencies)
|
||||||
if (vfs->Mark(dep.first, 0, 2)) {
|
if (vfs->Mark(dep.first().str(), 0, 2)) {
|
||||||
prev = cache.RawCacheLoad(dep.first);
|
prev = cache.RawCacheLoad(dep.first().str());
|
||||||
IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get());
|
IndexUpdate update = IndexUpdate::CreateDelta(nullptr, prev.get());
|
||||||
queue->on_indexed.PushBack(Index_OnIndexed(std::move(update), perf),
|
queue->on_indexed.PushBack(Index_OnIndexed(std::move(update), perf),
|
||||||
request.is_interactive);
|
request.is_interactive);
|
||||||
@ -189,7 +189,7 @@ bool Indexer_Parse(DiagnosticsEngine* diag_engine,
|
|||||||
if (entry.id >= 0) {
|
if (entry.id >= 0) {
|
||||||
std::lock_guard<std::mutex> lock(project->mutex_);
|
std::lock_guard<std::mutex> lock(project->mutex_);
|
||||||
for (auto& dep : curr->dependencies)
|
for (auto& dep : curr->dependencies)
|
||||||
project->absolute_path_to_entry_index_[dep.first] = entry.id;
|
project->absolute_path_to_entry_index_[dep.first()] = entry.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build delta update.
|
// Build delta update.
|
||||||
@ -388,7 +388,6 @@ void MainLoop(MultiQueueWaiter* querydb_waiter,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run query db main loop.
|
// Run query db main loop.
|
||||||
SetThreadName("querydb");
|
|
||||||
auto* queue = QueueManager::instance();
|
auto* queue = QueueManager::instance();
|
||||||
while (true) {
|
while (true) {
|
||||||
std::vector<std::unique_ptr<InMessage>> messages =
|
std::vector<std::unique_ptr<InMessage>> messages =
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#include <llvm/ADT/StringMap.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -297,7 +299,7 @@ struct IndexFile {
|
|||||||
std::vector<Range> skipped_by_preprocessor;
|
std::vector<Range> skipped_by_preprocessor;
|
||||||
|
|
||||||
std::vector<IndexInclude> includes;
|
std::vector<IndexInclude> includes;
|
||||||
std::unordered_map<std::string, int64_t> dependencies;
|
llvm::StringMap<int64_t> dependencies;
|
||||||
std::unordered_map<Usr, IndexFunc> usr2func;
|
std::unordered_map<Usr, IndexFunc> usr2func;
|
||||||
std::unordered_map<Usr, IndexType> usr2type;
|
std::unordered_map<Usr, IndexType> usr2type;
|
||||||
std::unordered_map<Usr, IndexVar> usr2var;
|
std::unordered_map<Usr, IndexVar> usr2var;
|
||||||
|
@ -245,15 +245,14 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
|||||||
detailed_name.substr(0, detailed_name.find('<'));
|
detailed_name.substr(0, detailed_name.find('<'));
|
||||||
int16_t start_line = sym.range.start.line;
|
int16_t start_line = sym.range.start.line;
|
||||||
int16_t start_col = sym.range.start.column;
|
int16_t start_col = sym.range.start.column;
|
||||||
if (start_line >= 0 && start_line < working_file->index_lines.size()) {
|
if (start_line < 0 || start_line >= working_file->index_lines.size())
|
||||||
std::string_view line = working_file->index_lines[start_line];
|
continue;
|
||||||
sym.range.end.line = start_line;
|
std::string_view line = working_file->index_lines[start_line];
|
||||||
if (start_col + concise_name.size() <= line.size() &&
|
sym.range.end.line = start_line;
|
||||||
line.compare(start_col, concise_name.size(), concise_name) == 0)
|
if (!(start_col + concise_name.size() <= line.size() &&
|
||||||
sym.range.end.column = start_col + concise_name.size();
|
line.compare(start_col, concise_name.size(), concise_name) == 0))
|
||||||
else
|
continue;
|
||||||
continue; // applies to for loop
|
sym.range.end.column = start_col + concise_name.size();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SymbolKind::Type:
|
case SymbolKind::Type:
|
||||||
|
@ -155,7 +155,7 @@ struct Handler_TextDocumentDefinition
|
|||||||
auto pos = name.rfind(query);
|
auto pos = name.rfind(query);
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
std::get<0>(score) = int(name.size() - query.size());
|
std::get<0>(score) = int(name.size() - query.size());
|
||||||
std::get<1>(score) = -pos;
|
std::get<1>(score) = -int(pos);
|
||||||
}
|
}
|
||||||
if (score < best_score) {
|
if (score < best_score) {
|
||||||
best_score = score;
|
best_score = score;
|
||||||
|
@ -12,7 +12,7 @@ MethodType kMethodType_CclsPublishSemanticHighlighting =
|
|||||||
void Reflect(Reader& visitor, lsRequestId& value) {
|
void Reflect(Reader& visitor, lsRequestId& value) {
|
||||||
if (visitor.IsInt64()) {
|
if (visitor.IsInt64()) {
|
||||||
value.type = lsRequestId::kInt;
|
value.type = lsRequestId::kInt;
|
||||||
value.value = visitor.GetInt64();
|
value.value = int(visitor.GetInt64());
|
||||||
} else if (visitor.IsInt()) {
|
} else if (visitor.IsInt()) {
|
||||||
value.type = lsRequestId::kInt;
|
value.type = lsRequestId::kInt;
|
||||||
value.value = visitor.GetInt();
|
value.value = visitor.GetInt();
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
#include <llvm/ADT/ArrayRef.h>
|
#include <llvm/ADT/ArrayRef.h>
|
||||||
#include <llvm/Option/ArgList.h>
|
#include <llvm/Option/ArgList.h>
|
||||||
#include <llvm/Option/OptTable.h>
|
#include <llvm/Option/OptTable.h>
|
||||||
|
#include <llvm/Support/MemoryBuffer.h>
|
||||||
|
#include <llvm/Support/LineIterator.h>
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvm::opt;
|
using namespace llvm::opt;
|
||||||
@ -29,7 +31,6 @@ using namespace llvm::opt;
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -145,14 +146,11 @@ Project::Entry GetCompilationEntryFromCompileCommandEntry(
|
|||||||
|
|
||||||
std::vector<std::string> ReadCompilerArgumentsFromFile(
|
std::vector<std::string> ReadCompilerArgumentsFromFile(
|
||||||
const std::string& path) {
|
const std::string& path) {
|
||||||
|
auto MBOrErr = MemoryBuffer::getFile(path);
|
||||||
|
if (!MBOrErr) return {};
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
std::ifstream fin(path);
|
for (line_iterator I(*MBOrErr.get(), true, '#'), E; I != E; ++I)
|
||||||
for (std::string line; std::getline(fin, line);) {
|
args.push_back(*I);
|
||||||
TrimInPlace(line);
|
|
||||||
if (line.empty() || StartsWith(line, "#"))
|
|
||||||
continue;
|
|
||||||
args.push_back(line);
|
|
||||||
}
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IndexFile& indexed) {
|
|||||||
def.inactive_regions = std::move(indexed.skipped_by_preprocessor);
|
def.inactive_regions = std::move(indexed.skipped_by_preprocessor);
|
||||||
def.dependencies.reserve(indexed.dependencies.size());
|
def.dependencies.reserve(indexed.dependencies.size());
|
||||||
for (auto& dep : indexed.dependencies)
|
for (auto& dep : indexed.dependencies)
|
||||||
def.dependencies.push_back(dep.first);
|
def.dependencies.push_back(dep.first());
|
||||||
def.language = indexed.language;
|
def.language = indexed.language;
|
||||||
|
|
||||||
auto add_all_symbols = [&](Use use, Usr usr, SymbolKind kind) {
|
auto add_all_symbols = [&](Use use, Usr usr, SymbolKind kind) {
|
||||||
|
10
src/query.h
10
src/query.h
@ -3,8 +3,8 @@
|
|||||||
#include "indexer.h"
|
#include "indexer.h"
|
||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
|
|
||||||
#include <llvm/ADT/DenseMap.h>
|
|
||||||
#include <llvm/ADT/SmallVector.h>
|
#include <llvm/ADT/SmallVector.h>
|
||||||
|
#include <llvm/ADT/StringMap.h>
|
||||||
|
|
||||||
struct QueryFile;
|
struct QueryFile;
|
||||||
struct QueryType;
|
struct QueryType;
|
||||||
@ -136,10 +136,10 @@ struct QueryDatabase {
|
|||||||
std::vector<SymbolIdx> symbols;
|
std::vector<SymbolIdx> symbols;
|
||||||
|
|
||||||
std::vector<QueryFile> files;
|
std::vector<QueryFile> files;
|
||||||
std::unordered_map<std::string, int> name2file_id;
|
llvm::StringMap<int> name2file_id;
|
||||||
llvm::DenseMap<Usr, QueryFunc> usr2func;
|
std::unordered_map<Usr, QueryFunc> usr2func;
|
||||||
llvm::DenseMap<Usr, QueryType> usr2type;
|
std::unordered_map<Usr, QueryType> usr2type;
|
||||||
llvm::DenseMap<Usr, QueryVar> usr2var;
|
std::unordered_map<Usr, QueryVar> usr2var;
|
||||||
|
|
||||||
// Marks the given Usrs as invalid.
|
// Marks the given Usrs as invalid.
|
||||||
void RemoveUsrs(SymbolKind usr_kind, const std::vector<Usr>& to_remove);
|
void RemoveUsrs(SymbolKind usr_kind, const std::vector<Usr>& to_remove);
|
||||||
|
@ -11,7 +11,7 @@ Maybe<Use> GetDefinitionExtent(QueryDatabase* db, SymbolIdx sym);
|
|||||||
// Get defining declaration (if exists) or an arbitrary declaration (otherwise)
|
// Get defining declaration (if exists) or an arbitrary declaration (otherwise)
|
||||||
// for each id.
|
// for each id.
|
||||||
template <typename Q>
|
template <typename Q>
|
||||||
std::vector<Use> GetDeclarations(llvm::DenseMap<Usr, Q>& usr2entity,
|
std::vector<Use> GetDeclarations(std::unordered_map<Usr, Q>& usr2entity,
|
||||||
const std::vector<Usr>& usrs) {
|
const std::vector<Usr>& usrs) {
|
||||||
std::vector<Use> ret;
|
std::vector<Use> ret;
|
||||||
ret.reserve(usrs.size());
|
ret.reserve(usrs.size());
|
||||||
@ -135,7 +135,7 @@ void EachOccurrenceWithParent(QueryDatabase* db,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Q, typename Fn>
|
template <typename Q, typename Fn>
|
||||||
void EachDefinedEntity(llvm::DenseMap<Usr, Q>& collection,
|
void EachDefinedEntity(std::unordered_map<Usr, Q>& collection,
|
||||||
const std::vector<Usr>& usrs,
|
const std::vector<Usr>& usrs,
|
||||||
Fn&& fn) {
|
Fn&& fn) {
|
||||||
for (Usr usr : usrs) {
|
for (Usr usr : usrs) {
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
using namespace llvm;
|
||||||
|
|
||||||
bool gTestOutputMode = false;
|
bool gTestOutputMode = false;
|
||||||
|
|
||||||
//// Elementary types
|
//// Elementary types
|
||||||
@ -149,6 +151,49 @@ void Reflect(Writer& visitor, JsonNull& value) {
|
|||||||
visitor.Null();
|
visitor.Null();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// std::unordered_map
|
||||||
|
template <typename V>
|
||||||
|
void Reflect(Reader& visitor, std::unordered_map<Usr, V>& map) {
|
||||||
|
visitor.IterArray([&](Reader& entry) {
|
||||||
|
V val;
|
||||||
|
Reflect(entry, val);
|
||||||
|
auto usr = val.usr;
|
||||||
|
map[usr] = std::move(val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
template <typename V>
|
||||||
|
void Reflect(Writer& visitor, std::unordered_map<Usr, V>& map) {
|
||||||
|
std::vector<std::pair<uint64_t, V>> xs(map.begin(), map.end());
|
||||||
|
std::sort(xs.begin(), xs.end(),
|
||||||
|
[](const auto& a, const auto& b) { return a.first < b.first; });
|
||||||
|
visitor.StartArray(xs.size());
|
||||||
|
for (auto& it : xs)
|
||||||
|
Reflect(visitor, it.second);
|
||||||
|
visitor.EndArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used by IndexFile::dependencies. Timestamps are emitted for Binary.
|
||||||
|
void Reflect(Reader& visitor, StringMap<int64_t>& map) {
|
||||||
|
visitor.IterArray([&](Reader& entry) {
|
||||||
|
std::string name;
|
||||||
|
Reflect(entry, name);
|
||||||
|
if (visitor.Format() == SerializeFormat::Binary)
|
||||||
|
Reflect(entry, map[name]);
|
||||||
|
else
|
||||||
|
map[name] = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
void Reflect(Writer& visitor, StringMap<int64_t>& map) {
|
||||||
|
visitor.StartArray(map.size());
|
||||||
|
for (auto& it : map) {
|
||||||
|
std::string key = it.first();
|
||||||
|
Reflect(visitor, key);
|
||||||
|
if (visitor.Format() == SerializeFormat::Binary)
|
||||||
|
Reflect(visitor, it.second);
|
||||||
|
}
|
||||||
|
visitor.EndArray();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Move this to indexer.cc
|
// TODO: Move this to indexer.cc
|
||||||
void Reflect(Reader& visitor, IndexInclude& value) {
|
void Reflect(Reader& visitor, IndexInclude& value) {
|
||||||
REFLECT_MEMBER_START();
|
REFLECT_MEMBER_START();
|
||||||
@ -313,27 +358,6 @@ void Reflect(Writer& visitor, SerializeFormat& value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reflect(Reader& visitor, std::unordered_map<std::string, int64_t>& map) {
|
|
||||||
visitor.IterArray([&](Reader& entry) {
|
|
||||||
std::string name;
|
|
||||||
Reflect(entry, name);
|
|
||||||
if (visitor.Format() == SerializeFormat::Binary)
|
|
||||||
Reflect(entry, map[name]);
|
|
||||||
else
|
|
||||||
map[name] = 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
void Reflect(Writer& visitor, std::unordered_map<std::string, int64_t>& map) {
|
|
||||||
visitor.StartArray(map.size());
|
|
||||||
for (auto& it : map) {
|
|
||||||
std::string key = it.first;
|
|
||||||
Reflect(visitor, key);
|
|
||||||
if (visitor.Format() == SerializeFormat::Binary)
|
|
||||||
Reflect(visitor, it.second);
|
|
||||||
}
|
|
||||||
visitor.EndArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Serialize(SerializeFormat format, IndexFile& file) {
|
std::string Serialize(SerializeFormat format, IndexFile& file) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case SerializeFormat::Binary: {
|
case SerializeFormat::Binary: {
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
enum class SerializeFormat { Binary, Json };
|
enum class SerializeFormat { Binary, Json };
|
||||||
@ -282,31 +281,6 @@ void Reflect(Writer& visitor, std::vector<T>& values) {
|
|||||||
visitor.EndArray();
|
visitor.EndArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::unordered_map
|
|
||||||
template <typename V>
|
|
||||||
void Reflect(Reader& visitor, std::unordered_map<uint64_t, V>& map) {
|
|
||||||
visitor.IterArray([&](Reader& entry) {
|
|
||||||
V val;
|
|
||||||
Reflect(entry, val);
|
|
||||||
auto usr = val.usr;
|
|
||||||
map[usr] = std::move(val);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
template <typename V>
|
|
||||||
void Reflect(Writer& visitor, std::unordered_map<uint64_t, V>& map) {
|
|
||||||
std::vector<std::pair<uint64_t, V>> xs(map.begin(), map.end());
|
|
||||||
std::sort(xs.begin(), xs.end(),
|
|
||||||
[](const auto& a, const auto& b) { return a.first < b.first; });
|
|
||||||
visitor.StartArray(xs.size());
|
|
||||||
for (auto& it : xs)
|
|
||||||
Reflect(visitor, it.second);
|
|
||||||
visitor.EndArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used by IndexFile::dependencies. Timestamps are emitted for Binary.
|
|
||||||
void Reflect(Reader& visitor, std::unordered_map<std::string, int64_t>& map);
|
|
||||||
void Reflect(Writer& visitor, std::unordered_map<std::string, int64_t>& map);
|
|
||||||
|
|
||||||
// ReflectMember
|
// ReflectMember
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
Loading…
Reference in New Issue
Block a user