9#include "llvm/Support/Regex.h"
15namespace include_fixer {
20 MemSymbolIndex(std::vector<SymbolAndSignals> Symbols) {
21 for (
auto &Symbol : Symbols) {
22 auto Tokens = tokenize(Symbol.Symbol.getName());
23 this->Symbols.emplace_back(
24 StringRef(llvm::join(Tokens.begin(), Tokens.end(),
" ")),
29 std::vector<SymbolAndSignals> search(StringRef Query)
override {
30 auto Tokens = tokenize(Query);
31 llvm::Regex Pattern(
"^" + queryRegexp(Tokens));
32 std::vector<SymbolAndSignals>
Results;
33 for (
const Entry &
E : Symbols)
34 if (Pattern.match(
E.first))
41 std::vector<Entry> Symbols;
53enum CharType { UPPER, LOWER, DIGIT, MISC };
54CharType classify(
char c) {
67 std::vector<std::string> Result;
70 TokenizeState State = EMPTY;
72 auto Flush = [&](
size_t End) {
74 Result.push_back(
Text.substr(Start, End - Start).lower());
79 for (
size_t I = 0; I <
Text.size(); ++I) {
83 else if (
Type == LOWER)
97 else if (
Type == UPPER)
108 else if (
Type == DIGIT && State != NUMBER) {
120 for (
size_t I = 0; I < Tokens.size(); ++I) {
122 Result.append(
"[[:alnum:]]* ");
123 for (
size_t J = 0; J < Tokens[I].size(); ++J) {
125 Result.append(
"([[:alnum:]]* )?");
126 Result.push_back(Tokens[I][J]);
132llvm::Expected<std::unique_ptr<FuzzySymbolIndex>>
134 auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
136 return llvm::errorCodeToError(Buffer.getError());
137 return std::make_unique<MemSymbolIndex>(
std::vector< CodeCompletionResult > Results
static std::string queryRegexp(const std::vector< std::string > &Tokens)
static llvm::Expected< std::unique_ptr< FuzzySymbolIndex > > createFromYAML(llvm::StringRef File)
static std::vector< std::string > tokenize(llvm::StringRef Text)
std::vector< SymbolAndSignals > ReadSymbolInfosFromYAML(llvm::StringRef Yaml)
Read SymbolInfos from a YAML document.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//