diff options
| author | Eric Liu <ioeric@google.com> | 2018-06-15 08:58:12 +0000 |
|---|---|---|
| committer | Eric Liu <ioeric@google.com> | 2018-06-15 08:58:12 +0000 |
| commit | 09c3c37b72f0fa7629e089e31e727448a032132f (patch) | |
| tree | 19b4303d3e1bac95309f369a9fa3a1307f24d477 /clang-tools-extra/clangd/Quality.h | |
| parent | 13e503f68a0ec42807c46aa76540b3eb06450b9d (diff) | |
| download | bcm5719-llvm-09c3c37b72f0fa7629e089e31e727448a032132f.tar.gz bcm5719-llvm-09c3c37b72f0fa7629e089e31e727448a032132f.zip | |
[clangd] Boost completion score according to file proximity.
Summary:
Also move unittest: URI scheme to TestFS so that it can be shared by
different tests.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47935
llvm-svn: 334810
Diffstat (limited to 'clang-tools-extra/clangd/Quality.h')
| -rw-r--r-- | clang-tools-extra/clangd/Quality.h | 31 |
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: |

