27 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H 28 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H 32 #include "clang/Sema/CodeCompleteConsumer.h" 33 #include "llvm/ADT/ArrayRef.h" 34 #include "llvm/ADT/StringRef.h" 35 #include "llvm/ADT/StringSet.h" 45 class CodeCompletionResult;
58 bool Deprecated =
false;
59 bool ReservedName =
false;
61 bool ImplementationDetail =
false;
77 void merge(
const CodeCompletionResult &SemaCCResult);
81 float evaluate()
const;
83 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
93 llvm::StringSet<>* ContextWords =
nullptr;
94 bool Forbidden =
false;
96 bool NeedsFixIts =
false;
97 bool InBaseClass =
false;
106 float SemaFileProximityScore = 0;
112 bool SemaSaysInScope =
false;
120 } Scope = GlobalScope;
130 bool IsInstanceMember =
false;
133 bool HadContextType =
false;
135 bool HadSymbolType =
false;
137 bool TypeMatchesPreferred =
false;
139 void merge(
const CodeCompletionResult &
SemaResult);
143 float evaluate()
const;
145 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
152 template <
typename T,
typename Compare = std::greater<T>>
class TopN {
155 TopN(
size_t N, Compare Greater = Compare())
156 : N(N), Greater(std::move(Greater)) {}
161 bool Dropped =
false;
162 if (Heap.size() >= N) {
164 if (N > 0 && Greater(V, Heap.front())) {
165 std::pop_heap(Heap.begin(), Heap.end(), Greater);
166 Heap.back() = std::move(V);
167 std::push_heap(Heap.begin(), Heap.end(), Greater);
170 Heap.push_back(std::move(V));
171 std::push_heap(Heap.begin(), Heap.end(), Greater);
173 assert(Heap.size() <= N);
174 assert(std::is_heap(Heap.begin(), Heap.end(), Greater));
179 std::vector<value_type>
items() && {
180 std::sort_heap(Heap.begin(), Heap.end(), Greater);
181 assert(Heap.size() <= N);
182 return std::move(Heap);
187 std::vector<value_type> Heap;
193 std::string
sortText(
float Score, llvm::StringRef Tiebreak =
"");
196 uint32_t NumberOfParameters = 0;
197 uint32_t NumberOfOptionalParameters = 0;
198 CodeCompleteConsumer::OverloadCandidate::CandidateKind
Kind =
199 CodeCompleteConsumer::OverloadCandidate::CandidateKind::CK_Function;
201 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
207 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H
Some operations such as code completion produce a set of candidates.
llvm::Optional< llvm::StringRef > SymbolScope
TopN(size_t N, Compare Greater=Compare())
std::string sortText(float Score, llvm::StringRef Name)
Returns a string that sorts in the same order as (-Score, Tiebreak), for LSP.
Attributes of a symbol that affect how much we like it.
llvm::StringRef Name
The name of the symbol (for ContextWords). Must be explicitly assigned.
llvm::Optional< float > Score
bool push(value_type &&V)
const Symbol * IndexResult
A context is an immutable container for per-request data that must be propagated through layers that ...
llvm::StringRef SymbolURI
These are used to calculate proximity between the index symbol and the query.
float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance)
Combine symbol quality and relevance into a single score.
The class presents a C++ symbol, e.g.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Support lookups like FileDistance, but the lookup keys are symbol scopes.
const CodeCompletionResult * SemaResult
std::vector< value_type > items() &&
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
Attributes of a symbol-query pair that affect how much we like it.
TopN<T> is a lossy container that preserves only the "best" N elements.