summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/Quality.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/Quality.h')
-rw-r--r--clang-tools-extra/clangd/Quality.h31
1 files changed, 30 insertions, 1 deletions
diff --git a/clang-tools-extra/clangd/Quality.h b/clang-tools-extra/clangd/Quality.h
index 0e0b6df6ba8..fef039a3a2f 100644
--- a/clang-tools-extra/clangd/Quality.h
+++ b/clang-tools-extra/clangd/Quality.h
@@ -26,6 +26,7 @@
//===---------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_QUALITY_H
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include <algorithm>
#include <functional>
@@ -68,13 +69,22 @@ struct SymbolQualitySignals {
llvm::raw_ostream &operator<<(llvm::raw_ostream &,
const SymbolQualitySignals &);
+class FileProximityMatcher;
+
/// Attributes of a symbol-query pair that affect how much we like it.
struct SymbolRelevanceSignals {
/// 0-1+ fuzzy-match score for unqualified name. Must be explicitly assigned.
float NameMatch = 1;
bool Forbidden = false; // Unavailable (e.g const) or inaccessible (private).
+
+ const FileProximityMatcher *FileProximityMatch = nullptr;
+ /// This is used to calculate proximity between the index symbol and the
+ /// query.
+ llvm::StringRef SymbolURI;
/// Proximity between best declaration and the query. [0-1], 1 is closest.
- float ProximityScore = 0;
+ /// FIXME: unify with index proximity score - signals should be
+ /// source-independent.
+ float SemaProximityScore = 0;
// An approximate measure of where we expect the symbol to be used.
enum AccessibleScope {
@@ -101,6 +111,25 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &,
/// Combine symbol quality and relevance into a single score.
float evaluateSymbolAndRelevance(float SymbolQuality, float SymbolRelevance);
+class FileProximityMatcher {
+ public:
+ /// \p ProximityPaths are used to compute proximity scores from symbol's
+ /// declaring file. The best score will be used.
+ explicit FileProximityMatcher(
+ llvm::ArrayRef<llvm::StringRef> ProximityPaths);
+
+ /// Calculates the best proximity score from proximity paths to the symbol's
+ /// URI. Score is [0-1], 1 means \p SymbolURI exactly matches a proximity
+ /// path. When a path cannot be encoded into the same scheme as \p
+ /// SymbolURI, the proximity will be 0.
+ float uriProximity(llvm::StringRef SymbolURI) const;
+
+ private:
+ llvm::SmallVector<std::string, 2> ProximityPaths;
+ friend llvm::raw_ostream &operator<<(llvm::raw_ostream &,
+ const FileProximityMatcher &);
+};
+
/// TopN<T> is a lossy container that preserves only the "best" N elements.
template <typename T, typename Compare = std::greater<T>> class TopN {
public:
OpenPOWER on IntegriCloud