Go to the documentation of this file.
27 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H
28 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H
31 #include "clang/Sema/CodeCompleteConsumer.h"
32 #include "llvm/ADT/StringRef.h"
33 #include "llvm/ADT/StringSet.h"
44 class CodeCompletionResult;
76 void merge(
const CodeCompletionResult &SemaCCResult);
82 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
83 const SymbolQualitySignals &);
170 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
189 template <
typename T,
typename Compare = std::greater<T>>
class TopN {
192 TopN(
size_t N, Compare Greater = Compare())
193 : N(N), Greater(std::move(Greater)) {}
198 bool Dropped =
false;
199 if (Heap.size() >= N) {
201 if (N > 0 && Greater(V, Heap.front())) {
202 std::pop_heap(Heap.begin(), Heap.end(), Greater);
203 Heap.back() = std::move(V);
204 std::push_heap(Heap.begin(), Heap.end(), Greater);
207 Heap.push_back(std::move(V));
208 std::push_heap(Heap.begin(), Heap.end(), Greater);
210 assert(Heap.size() <= N);
211 assert(std::is_heap(Heap.begin(), Heap.end(), Greater));
216 std::vector<value_type>
items() && {
217 std::sort_heap(Heap.begin(), Heap.end(), Greater);
218 assert(Heap.size() <= N);
219 return std::move(Heap);
224 std::vector<value_type> Heap;
230 std::string
sortText(
float Score, llvm::StringRef Tiebreak =
"");
235 CodeCompleteConsumer::OverloadCandidate::CandidateKind
Kind =
236 CodeCompleteConsumer::OverloadCandidate::CandidateKind::CK_Function;
238 llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
244 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H
void merge(const CodeCompletionResult &SemaResult)
bool ImplementationDetail
std::unique_ptr< GlobalCompilationDatabase > Base
Some operations such as code completion produce a set of candidates.
enum clang::clangd::SymbolRelevanceSignals::AccessibleScope Scope
std::optional< llvm::StringRef > SymbolScope
enum clang::clangd::SymbolRelevanceSignals::QueryType Query
std::vector< value_type > items() &&
unsigned FilterLength
Length of the unqualified partial name of Symbol typed in CompletionPrefix.
const Symbol * IndexResult
float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance)
Combine symbol quality and relevance into a single score.
llvm::StringRef SymbolURI
These are used to calculate proximity between the index symbol and the query.
TopN(size_t N, Compare Greater=Compare())
Same semantics as CodeComplete::Score.
unsigned FileProximityDistance
Min distance between SymbolURI and all the headers included by the TU.
float evaluateHeuristics() const
Support lookups like FileDistance, but the lookup keys are symbol scopes.
Attributes of a symbol that affect how much we like it.
void computeASTSignals(const CodeCompletionResult &SemaResult)
unsigned ScopeRefsInFile
Number of unique symbols in the main file which belongs to candidate's namespace.
uint32_t NumberOfOptionalParameters
bool push(value_type &&V)
std::optional< float > Score
TopN<T> is a lossy container that preserves only the "best" N elements.
SignatureQualitySignals Quality
const CodeCompletionResult * SemaResult
The class presents a C++ symbol, e.g.
uint32_t NumberOfParameters
DecisionForestScores evaluateDecisionForest(const SymbolQualitySignals &Quality, const SymbolRelevanceSignals &Relevance, float Base)
float SemaFileProximityScore
FIXME: unify with index proximity score - signals should be source-independent.
URIDistance * FileProximityMatch
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
bool TypeMatchesPreferred
ScopeDistance * ScopeProximityMatch
llvm::StringRef Name
The name of the symbol (for ContextWords). Must be explicitly assigned.
Set of derived signals computed by calculateDerivedSignals().
bool NameMatchesContext
Whether Name contains some word from context.
Signals derived from a valid AST of a file.
const ASTSignals * MainFileSignals
bool NeedsFixIts
Whether fixits needs to be applied for that completion or not.
std::string sortText(float Score, llvm::StringRef Name)
Returns a string that sorts in the same order as (-Score, Tiebreak), for LSP.
unsigned MainFileRefs
Number of references to the candidate in the main file.
DerivedSignals calculateDerivedSignals() const
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
float evaluateHeuristics() const
llvm::StringSet * ContextWords
Lowercase words relevant to the context (e.g. near the completion point).
CodeCompleteConsumer::OverloadCandidate::CandidateKind Kind
enum clang::clangd::SymbolQualitySignals::SymbolCategory Category
unsigned ScopeProximityDistance
Min distance between SymbolScope and all the available scopes.
float NameMatch
0-1+ fuzzy-match score for unqualified name. Must be explicitly assigned.
Attributes of a symbol-query pair that affect how much we like it.
A context is an immutable container for per-request data that must be propagated through layers that ...
static constexpr unsigned Unreachable
void merge(const CodeCompletionResult &SemaCCResult)