Index: clang-tools-extra/clangd/Quality.cpp =================================================================== --- clang-tools-extra/clangd/Quality.cpp +++ clang-tools-extra/clangd/Quality.cpp @@ -283,12 +283,12 @@ } void SymbolRelevanceSignals::merge(const Symbol &IndexResult) { - // FIXME: Index results always assumed to be at global scope. If Scope becomes - // relevant to non-completion requests, we should recognize class members etc. - SymbolURI = IndexResult.CanonicalDeclaration.FileURI; SymbolScope = IndexResult.Scope; IsInstanceMember |= isInstanceMember(IndexResult.SymInfo); + if (IndexResult.Flags & Symbol::FileLocal) { + Scope = AccessibleScope::FileScope; + } } void SymbolRelevanceSignals::merge(const CodeCompletionResult &SemaCCResult) { @@ -375,6 +375,19 @@ Score *= 4; break; } + } else { + // For non-completion queries, the wider the scope where a symbol is + // visible, the more likely it is to be relevant. + switch (Scope) { + case GlobalScope: + break; + case FileScope: + Score *= 0.75; + break; + default: + // TODO: Handle other scopes as we start to use them for index results. + break; + } } if (TypeMatchesPreferred) Index: clang-tools-extra/unittests/clangd/QualityTests.cpp =================================================================== --- clang-tools-extra/unittests/clangd/QualityTests.cpp +++ clang-tools-extra/unittests/clangd/QualityTests.cpp @@ -265,7 +265,7 @@ SymbolRelevanceSignals Scoped; Scoped.Scope = SymbolRelevanceSignals::FileScope; - EXPECT_EQ(Scoped.evaluate(), Default.evaluate()); + EXPECT_LT(Scoped.evaluate(), Default.evaluate()); Scoped.Query = SymbolRelevanceSignals::CodeComplete; EXPECT_GT(Scoped.evaluate(), Default.evaluate());