fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

ranking: boost cpp matches based on kind (#462)

This follows the examples of other languages like Java, Kotlin and Go.

+153
+48
build/e2e_test.go
··· 809 809 t.Fatal(err) 810 810 } 811 811 812 + exampleCpp, err := os.ReadFile("./testdata/example.cc") 813 + if err != nil { 814 + t.Fatal(err) 815 + } 816 + 812 817 cases := []struct { 813 818 fileName string 814 819 content []byte ··· 956 961 wantLanguage: "Go", 957 962 // 7000 (full base match) + 800 (Go func) + 500 (word) + 400 (atom) + 10 (file order) 958 963 wantScore: 8710, 964 + }, 965 + // 966 + // C++ 967 + // 968 + { 969 + fileName: "example.cc", 970 + content: exampleCpp, 971 + query: &query.Substring{Content: true, Pattern: "FooClass"}, 972 + wantLanguage: "C++", 973 + // 7000 (Symbol) + 1000 (C++ class) + 500 (full word) + 400 (atom) + 10 (file order) 974 + wantScore: 8910, 975 + }, 976 + { 977 + fileName: "example.cc", 978 + content: exampleCpp, 979 + query: &query.Substring{Content: true, Pattern: "NestedEnum"}, 980 + wantLanguage: "C++", 981 + // 7000 (Symbol) + 900 (C++ enum) + 500 (full word) + 400 (atom) + 10 (file order) 982 + wantScore: 8810, 983 + }, 984 + { 985 + fileName: "example.cc", 986 + content: exampleCpp, 987 + query: &query.Substring{Content: true, Pattern: "main"}, 988 + wantLanguage: "C++", 989 + // 7000 (Symbol) + 800 (C++ function) + 500 (full word) + 400 (atom) + 10 (file order) 990 + wantScore: 8710, 991 + }, 992 + { 993 + fileName: "example.cc", 994 + content: exampleCpp, 995 + query: &query.Substring{Content: true, Pattern: "FooStruct"}, 996 + wantLanguage: "C++", 997 + // 7000 (Symbol) + 700 (C++ struct) + 500 (full word) + 400 (atom) + 10 (file order) 998 + wantScore: 8610, 999 + }, 1000 + { 1001 + fileName: "example.cc", 1002 + content: exampleCpp, 1003 + query: &query.Substring{Content: true, Pattern: "TheUnion"}, 1004 + wantLanguage: "C++", 1005 + // 7000 (Symbol) + 600 (C++ union) + 500 (full word) + 400 (atom) + 10 (file order) 1006 + wantScore: 8510, 959 1007 }, 960 1008 } 961 1009
+79
build/testdata/example.cc
··· 1 + // Build with "cl.exe /Zi /GR- /GX- every-type.cpp /link /debug /nodefaultlib /entry:main" 2 + 3 + // clang-format off 4 + void *__purecall = 0; 5 + 6 + void __cdecl operator delete(void *,unsigned int) {} 7 + void __cdecl operator delete(void *,unsigned __int64) {} 8 + 9 + struct FooStruct { }; // LF_STRUCTURE 10 + 11 + class FooClass { // LF_CLASS 12 + public: 13 + // LF_FIELDLIST 14 + enum NestedEnum { // LF_ENUM 15 + // LF_NESTTYPE 16 + A, B, C // LF_ENUMERATE 17 + }; 18 + 19 + void RegularMethod() {} // LF_ARGLIST 20 + // LF_ONEMETHOD 21 + // LF_MFUNCTION 22 + 23 + void OverloadedMethod(int) {} // LF_METHODLIST 24 + // LF_METHOD 25 + void OverloadedMethod(int, int) {} 26 + 27 + int HiNibble : 4; // LF_BITFIELD 28 + int LoNibble : 4; 29 + NestedEnum EnumVariable; // LF_MEMBER 30 + static void *StaticMember; // LF_POINTER 31 + // LF_STMEMBER 32 + }; 33 + 34 + void *FooClass::StaticMember = nullptr; 35 + 36 + class Inherit : public FooClass { // LF_BCLASS 37 + public: 38 + virtual ~Inherit() {} // LF_VTSHAPE 39 + // LF_VFUNCTAB 40 + }; 41 + 42 + class VInherit : public virtual FooClass { // LF_VBCLASS 43 + 44 + }; 45 + 46 + class IVInherit : public VInherit { // LF_IVBCLASS 47 + }; 48 + 49 + union TheUnion { 50 + int X; // LF_UNION 51 + }; 52 + 53 + int SomeArray[7] = {1, 2, 3, 4, 5, 6, 7}; // LF_ARRAY 54 + 55 + template<typename T> 56 + void Reference(T &t) { } 57 + 58 + const volatile FooStruct FS; // LF_MODIFIER with struct 59 + const volatile FooClass FC; // LF_MODIFIER with class 60 + const volatile TheUnion TU; // LF_MODIFIER with union 61 + const volatile FooClass::NestedEnum FCNE = FooClass::A; // LF_MODIFIER with enum 62 + 63 + 64 + int main(int argc, char **argv) { // LF_PROCEDURE 65 + const int X = 7; // LF_MODIFIER 66 + 67 + FooStruct FooStructInstance; 68 + FooClass FooClassInstance; 69 + Inherit InheritInstance; 70 + VInherit VInheritInstance; 71 + IVInherit IVInheritInstance; 72 + TheUnion UnionInstance; 73 + Reference(FS); // LF_MODIFIER with struct 74 + Reference(FC); // LF_MODIFIER with class 75 + Reference(TU); // LF_MODIFIER with union 76 + Reference(FCNE); // LF_MODIFIER with enum 77 + return SomeArray[argc]; 78 + } 79 +
+26
contentprovider.go
··· 709 709 // - package packages 710 710 // - type types 711 711 // - unknown unknown 712 + case "C++": 713 + switch kind { 714 + case "class": // classes 715 + factor = 10 716 + case "enum": // enumeration names 717 + factor = 9 718 + case "function": // function definitions 719 + factor = 8 720 + case "struct": // structure names 721 + factor = 7 722 + case "union": // union names 723 + factor = 6 724 + case "typdef": // typedefs 725 + factor = 5 726 + case "member": // class, struct, and union members 727 + factor = 4 728 + case "variable": // varialbe definitions 729 + factor = 3 730 + } 731 + // Could also rank on: 732 + // NAME DESCRIPTION 733 + // macro macro definitions 734 + // enumerator enumerators (values inside an enumeration) 735 + // header included header files 736 + // namespace namespaces 737 + // variable variable definitions 712 738 } 713 739 return factor * scoreKindMatch 714 740 }