clang-tools  7.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"
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
HeaderHandle File
static llvm::Expected< std::unique_ptr< FuzzySymbolIndex > > createFromYAML(llvm::StringRef File)
StringRef Tokens
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
This class provides an interface for finding all SymbolInfos corresponding to a symbol name from a sy...
Definition: SymbolIndex.h:22
static std::string queryRegexp(const std::vector< std::string > &Tokens)
static std::vector< std::string > tokenize(llvm::StringRef Text)