-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathIndexer.h
More file actions
105 lines (71 loc) · 2.56 KB
/
Indexer.h
File metadata and controls
105 lines (71 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include <deque>
#include <vector>
#include "Config.h"
#include "Convert.h"
#include "Async/Async.h"
#include "Compiler/Command.h"
#include "Index/MergedIndex.h"
#include "Index/ProjectIndex.h"
#include "Protocol/Protocol.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringMap.h"
namespace clice {
class CompilationUnit;
class Indexer {
public:
Indexer(CompilationDatabase& database,
config::Config& config,
const PositionEncodingKind& kind) :
database(database), config(config), encoding_kind(kind) {}
async::Task<> index(llvm::StringRef path);
async::Task<> index(llvm::StringRef path, llvm::StringRef content);
async::Task<> schedule_next();
async::Task<> index_all();
index::MergedIndex& get_index(std::uint32_t path_id) {
auto [it, success] = in_memory_indices.try_emplace(path_id);
if(!success) {
return it->second;
}
auto it2 = project_index.indices.find(path_id);
if(it2 != project_index.indices.end()) {
auto path = project_index.path_pool.path(it2->second);
it->second = index::MergedIndex::load(path);
} else {
std::println(stderr,
"failed to load project index for path_id: {} {}",
path_id,
project_index.indices.size());
}
return it->second;
}
using Result = async::Task<std::vector<proto::Location>>;
void load_from_disk();
void save_to_disk();
auto lookup(llvm::StringRef path, std::uint32_t offset, RelationKind kind) -> Result;
auto declaration(llvm::StringRef path, std::uint32_t offset) -> Result;
auto definition(llvm::StringRef path, std::uint32_t offset) -> Result;
auto references(llvm::StringRef path, std::uint32_t offset) -> Result;
/// TODO: Calls ...
/// TODO: Types ...
bool empty() const {
return project_index.indices.empty();
}
size_t size() const {
return project_index.indices.size();
}
private:
CompilationDatabase& database;
config::Config& config;
const PositionEncodingKind& encoding_kind;
index::ProjectIndex project_index;
PathMapping mapping;
llvm::DenseMap<std::uint32_t, index::MergedIndex> in_memory_indices;
/// Currently indexes tasks ...
std::vector<async::Task<>> workings;
/// FIXME: Use a LRU to make sure we won't index a file twice ...
std::deque<std::uint32_t> waitings;
async::Event update_event;
};
} // namespace clice