clang-tools 8.0.0

FuzzySymbolIndex.h
Go to the documentation of this file.
1 //===--- FuzzySymbolIndex.h - Lookup symbols for autocomplete ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FUZZY_SYMBOL_INDEX_H
11 #define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FUZZY_SYMBOL_INDEX_H
12
13 #include "SymbolIndex.h"
14 #include "find-all-symbols/SymbolInfo.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/Error.h"
18 #include <string>
19 #include <vector>
20
21 namespace clang {
22 namespace include_fixer {
23
24 // A FuzzySymbolIndex retrieves top-level symbols matching a query string.
25 //
26 // It refines the contract of SymbolIndex::search to do fuzzy matching:
27 // - symbol names are tokenized: "unique ptr", "string ref".
28 // - query must match prefixes of symbol tokens: [upt]
29 // - if the query has multiple tokens, splits must match: [StR], not [STr].
30 // Helpers for tokenization and regex matching are provided.
31 //
32 // Implementations may choose to truncate results, refuse short queries, etc.
33 class FuzzySymbolIndex : public SymbolIndex {
34 public:
35 // Loads the specified include-fixer database and returns an index serving it.
36 static llvm::Expected<std::unique_ptr<FuzzySymbolIndex>>
37 createFromYAML(llvm::StringRef File);
38
39 // Helpers for implementing indexes:
40
41 // Transforms a symbol name or query into a sequence of tokens.
42 // - URLHandlerCallback --> [url, handler, callback]
43 // - snake_case11 --> [snake, case, 11]
44 // - _WTF$ --> [wtf]
45 static std::vector<std::string> tokenize(llvm::StringRef Text);
46
47 // Transforms query tokens into an unanchored regexp to match symbol tokens.
48 // - [fe f] --> /f(\w* )?e\w* f/, matches [fee fie foe].
49 static std::string queryRegexp(const std::vector<std::string> &Tokens);
50 };
51
52 } // namespace include_fixer
53 } // namespace clang
54
55 #endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FUZZY_SYMBOL_INDEX_H
clang::include_fixer::FuzzySymbolIndex::createFromYAML
static llvm::Expected< std::unique_ptr< FuzzySymbolIndex > > createFromYAML(llvm::StringRef File)
Definition: FuzzySymbolIndex.cpp:134
SymbolInfo.h
clang::include_fixer::FuzzySymbolIndex
Definition: FuzzySymbolIndex.h:33
Tokens
StringRef Tokens
Definition: AvoidBindCheck.cpp:40
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ChangeNamespace.cpp:18
SymbolIndex.h
clang::include_fixer::SymbolIndex
This class provides an interface for finding all SymbolInfos corresponding to a symbol name from a sy...
Definition: SymbolIndex.h:22
clang::include_fixer::FuzzySymbolIndex::queryRegexp
static std::string queryRegexp(const std::vector< std::string > &Tokens)
Definition: FuzzySymbolIndex.cpp:119
clang::include_fixer::FuzzySymbolIndex::tokenize
static std::vector< std::string > tokenize(llvm::StringRef Text)
Definition: FuzzySymbolIndex.cpp:67