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"
44class CodeCompletionResult;
76 void merge(
const CodeCompletionResult &SemaCCResult);
82llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
83 const SymbolQualitySignals &);
126 CodeCompletionContext::Kind
Context = CodeCompletionContext::CCC_Other;
170llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
189template <
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;
230std::string
sortText(
float Score, llvm::StringRef Tiebreak =
"");
235 CodeCompleteConsumer::OverloadCandidate::CandidateKind
Kind =
236 CodeCompleteConsumer::OverloadCandidate::CandidateKind::CK_Function;
238llvm::raw_ostream &
operator<<(llvm::raw_ostream &,
const Symbol * IndexResult
SignatureQualitySignals Quality
const CodeCompletionResult * SemaResult
std::optional< float > Score
A context is an immutable container for per-request data that must be propagated through layers that ...
static constexpr unsigned Unreachable
Support lookups like FileDistance, but the lookup keys are symbol scopes.
TopN<T> is a lossy container that preserves only the "best" N elements.
std::vector< value_type > items() &&
TopN(size_t N, Compare Greater=Compare())
bool push(value_type &&V)
std::string sortText(float Score, llvm::StringRef Name)
Returns a string that sorts in the same order as (-Score, Tiebreak), for LSP.
DecisionForestScores evaluateDecisionForest(const SymbolQualitySignals &Quality, const SymbolRelevanceSignals &Relevance, float Base)
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance)
Combine symbol quality and relevance into a single score.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
Signals derived from a valid AST of a file.
Same semantics as CodeComplete::Score.
uint32_t NumberOfParameters
uint32_t NumberOfOptionalParameters
CodeCompleteConsumer::OverloadCandidate::CandidateKind Kind
Attributes of a symbol that affect how much we like it.
float evaluateHeuristics() const
enum clang::clangd::SymbolQualitySignals::SymbolCategory Category
void merge(const CodeCompletionResult &SemaCCResult)
bool ImplementationDetail
Set of derived signals computed by calculateDerivedSignals().
bool NameMatchesContext
Whether Name contains some word from context.
unsigned FileProximityDistance
Min distance between SymbolURI and all the headers included by the TU.
unsigned ScopeProximityDistance
Min distance between SymbolScope and all the available scopes.
Attributes of a symbol-query pair that affect how much we like it.
float NameMatch
0-1+ fuzzy-match score for unqualified name. Must be explicitly assigned.
bool NeedsFixIts
Whether fixits needs to be applied for that completion or not.
DerivedSignals calculateDerivedSignals() const
ScopeDistance * ScopeProximityMatch
unsigned MainFileRefs
Number of references to the candidate in the main file.
llvm::StringRef Name
The name of the symbol (for ContextWords). Must be explicitly assigned.
void computeASTSignals(const CodeCompletionResult &SemaResult)
llvm::StringRef SymbolURI
These are used to calculate proximity between the index symbol and the query.
unsigned ScopeRefsInFile
Number of unique symbols in the main file which belongs to candidate's namespace.
const ASTSignals * MainFileSignals
llvm::StringSet * ContextWords
Lowercase words relevant to the context (e.g. near the completion point).
URIDistance * FileProximityMatch
unsigned FilterLength
Length of the unqualified partial name of Symbol typed in CompletionPrefix.
void merge(const CodeCompletionResult &SemaResult)
float SemaFileProximityScore
FIXME: unify with index proximity score - signals should be source-independent.
enum clang::clangd::SymbolRelevanceSignals::QueryType Query
enum clang::clangd::SymbolRelevanceSignals::AccessibleScope Scope
bool TypeMatchesPreferred
float evaluateHeuristics() const
std::optional< llvm::StringRef > SymbolScope
The class presents a C++ symbol, e.g.