[PATCH] D88844: [clangd] Add `score` extension to workspace/symbol response.
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG3cb1220709fa: [clangd] Add `score` extension to workspace/symbol response. (authored by sammccall). Changed prior to commit: https://reviews.llvm.org/D88844?vs=296263&id=296400#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D88844/new/ https://reviews.llvm.org/D88844 Files: clang-tools-extra/clangd/FindSymbols.cpp clang-tools-extra/clangd/Protocol.cpp clang-tools-extra/clangd/Protocol.h clang-tools-extra/clangd/test/symbols.test Index: clang-tools-extra/clangd/test/symbols.test === --- clang-tools-extra/clangd/test/symbols.test +++ clang-tools-extra/clangd/test/symbols.test @@ -23,7 +23,8 @@ # CHECK-NEXT: }, # CHECK-NEXT: "uri": "file://{{.*}}/vector.h" # CHECK-NEXT:}, -# CHECK-NEXT:"name": "vector" +# CHECK-NEXT:"name": "vector", +# CHECK-NEXT:"score": {{.*}} # CHECK-NEXT: } # CHECK-NEXT:] # CHECK-NEXT:} Index: clang-tools-extra/clangd/Protocol.h === --- clang-tools-extra/clangd/Protocol.h +++ clang-tools-extra/clangd/Protocol.h @@ -1015,6 +1015,14 @@ /// The name of the symbol containing this symbol. std::string containerName; + + /// The score that clangd calculates to rank the returned symbols. + /// This excludes the fuzzy-matching score between `name` and the query. + /// (Specifically, the last ::-separated component). + /// This can be used to re-rank results as the user types, using client-side + /// fuzzy-matching (that score should be multiplied with this one). + /// This is a clangd extension, set only for workspace/symbol responses. + llvm::Optional score; }; llvm::json::Value toJSON(const SymbolInformation &); llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &); @@ -1175,11 +1183,11 @@ /// Indicates if this item is deprecated. bool deprecated = false; - /// This is Clangd extension. - /// The score that Clangd calculates to rank completion items. This score can - /// be used to adjust the ranking on the client side. - /// NOTE: This excludes fuzzy matching score which is typically calculated on - /// the client side. + /// The score that clangd calculates to rank the returned completions. + /// This excludes the fuzzy-match between `filterText` and the partial word. + /// This can be used to re-rank results as the user types, using client-side + /// fuzzy-matching (that score should be multiplied with this one). + /// This is a clangd extension. float score = 0.f; // TODO: Add custom commitCharacters for some of the completion items. For Index: clang-tools-extra/clangd/Protocol.cpp === --- clang-tools-extra/clangd/Protocol.cpp +++ clang-tools-extra/clangd/Protocol.cpp @@ -662,12 +662,15 @@ } llvm::json::Value toJSON(const SymbolInformation &P) { - return llvm::json::Object{ + llvm::json::Object O{ {"name", P.name}, {"kind", static_cast(P.kind)}, {"location", P.location}, {"containerName", P.containerName}, }; + if (P.score) +O["score"] = *P.score; + return std::move(O); } llvm::raw_ostream &operator<<(llvm::raw_ostream &O, Index: clang-tools-extra/clangd/FindSymbols.cpp === --- clang-tools-extra/clangd/FindSymbols.cpp +++ clang-tools-extra/clangd/FindSymbols.cpp @@ -96,12 +96,13 @@ return; } -SymbolKind SK = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind); -std::string Scope = std::string(Sym.Scope); -llvm::StringRef ScopeRef = Scope; -ScopeRef.consume_back("::"); -SymbolInformation Info = {(Sym.Name + Sym.TemplateSpecializationArgs).str(), - SK, *Loc, std::string(ScopeRef)}; +llvm::StringRef Scope = Sym.Scope; +Scope.consume_back("::"); +SymbolInformation Info; +Info.name = (Sym.Name + Sym.TemplateSpecializationArgs).str(); +Info.kind = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind); +Info.location = *Loc; +Info.containerName = Scope.str(); SymbolQualitySignals Quality; Quality.merge(Sym); @@ -121,6 +122,8 @@ dlog("FindSymbols: {0}{1} = {2}\n{3}{4}\n", Sym.Scope, Sym.Name, Score, Quality, Relevance); +// Exposed score excludes fuzzy-match component, for client-side re-ranking. +Info.score = Score / Relevance.NameMatch; Top.push({Score, std::move(Info)}); }); for (auto &R : std::move(Top).items()) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D88844: [clangd] Add `score` extension to workspace/symbol response.
kadircet accepted this revision. kadircet added inline comments. This revision is now accepted and ready to land. Comment at: clang-tools-extra/clangd/FindSymbols.cpp:125 +Info.score = Score / Relevance.NameMatch; Top.push({Score, std::move(Info)}); nit: maybe add a comment here too, explaining why we factor-out `NameMatch`. It wasn't obivous until i've read the comment below. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D88844/new/ https://reviews.llvm.org/D88844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D88844: [clangd] Add `score` extension to workspace/symbol response.
sammccall created this revision. sammccall added a reviewer: kadircet. Herald added subscribers: cfe-commits, usaxena95, arphaman. Herald added a project: clang. sammccall requested review of this revision. Herald added subscribers: MaskRay, ilya-biryukov. The protocol doesn't really incorporate ranking. As with code completion, most clients respect what the server sends, but VSCode re-ranks items, with predictable results. See https://github.com/clangd/vscode-clangd/issues/81 There's no filterText field so we may be unable to construct a good workaround. But expose the score so we may be able to do this on the client in future. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D88844 Files: clang-tools-extra/clangd/FindSymbols.cpp clang-tools-extra/clangd/Protocol.cpp clang-tools-extra/clangd/Protocol.h clang-tools-extra/clangd/test/symbols.test Index: clang-tools-extra/clangd/test/symbols.test === --- clang-tools-extra/clangd/test/symbols.test +++ clang-tools-extra/clangd/test/symbols.test @@ -23,7 +23,8 @@ # CHECK-NEXT: }, # CHECK-NEXT: "uri": "file://{{.*}}/vector.h" # CHECK-NEXT:}, -# CHECK-NEXT:"name": "vector" +# CHECK-NEXT:"name": "vector", +# CHECK-NEXT:"score": {{.*}} # CHECK-NEXT: } # CHECK-NEXT:] # CHECK-NEXT:} Index: clang-tools-extra/clangd/Protocol.h === --- clang-tools-extra/clangd/Protocol.h +++ clang-tools-extra/clangd/Protocol.h @@ -1015,6 +1015,14 @@ /// The name of the symbol containing this symbol. std::string containerName; + + /// The score that clangd calculates to rank the returned symbols. + /// This excludes the fuzzy-matching score between `name` and the query. + /// (Specifically, the last ::-separated component). + /// This can be used to re-rank results as the user types, using client-side + /// fuzzy-matching (that score should be multiplied with this one). + /// This is a clangd extension, set only for workspace/symbol responses. + llvm::Optional score; }; llvm::json::Value toJSON(const SymbolInformation &); llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SymbolInformation &); @@ -1175,11 +1183,11 @@ /// Indicates if this item is deprecated. bool deprecated = false; - /// This is Clangd extension. - /// The score that Clangd calculates to rank completion items. This score can - /// be used to adjust the ranking on the client side. - /// NOTE: This excludes fuzzy matching score which is typically calculated on - /// the client side. + /// The score that clangd calculates to rank the returned completions. + /// This excludes the fuzzy-match between `filterText` and the partial word. + /// This can be used to re-rank results as the user types, using client-side + /// fuzzy-matching (that score should be multiplied with this one). + /// This is a clangd extension. float score = 0.f; // TODO: Add custom commitCharacters for some of the completion items. For Index: clang-tools-extra/clangd/Protocol.cpp === --- clang-tools-extra/clangd/Protocol.cpp +++ clang-tools-extra/clangd/Protocol.cpp @@ -662,12 +662,15 @@ } llvm::json::Value toJSON(const SymbolInformation &P) { - return llvm::json::Object{ + llvm::json::Object O{ {"name", P.name}, {"kind", static_cast(P.kind)}, {"location", P.location}, {"containerName", P.containerName}, }; + if (P.score) +O["score"] = *P.score; + return std::move(O); } llvm::raw_ostream &operator<<(llvm::raw_ostream &O, Index: clang-tools-extra/clangd/FindSymbols.cpp === --- clang-tools-extra/clangd/FindSymbols.cpp +++ clang-tools-extra/clangd/FindSymbols.cpp @@ -96,12 +96,13 @@ return; } -SymbolKind SK = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind); -std::string Scope = std::string(Sym.Scope); -llvm::StringRef ScopeRef = Scope; -ScopeRef.consume_back("::"); -SymbolInformation Info = {(Sym.Name + Sym.TemplateSpecializationArgs).str(), - SK, *Loc, std::string(ScopeRef)}; +llvm::StringRef Scope = Sym.Scope; +Scope.consume_back("::"); +SymbolInformation Info; +Info.name = (Sym.Name + Sym.TemplateSpecializationArgs).str(); +Info.kind = indexSymbolKindToSymbolKind(Sym.SymInfo.Kind); +Info.location = *Loc; +Info.containerName = Scope.str(); SymbolQualitySignals Quality; Quality.merge(Sym); @@ -121,6 +122,7 @@ dlog("FindSymbols: {0}{1} = {2}\n{3}{4}\n", Sym.Scope, Sym.Name, Score, Quality, Relevance); +Info.score = Score / Relevance.NameMatch; Top.push({Score, std::move(Info)}); }); for (auto &R : std::move(Top).items()) ___ cfe-commits mailing