Commit 97a1b046ea

Loris Cro <kappaloris@gmail.com>
2023-07-01 17:38:18
autodoc: fix scoring bug when matching full decl name
1 parent 35a8e8a
Changed files (2)
lib
docs
src
lib/docs/main.js
@@ -4328,9 +4328,9 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
           // shallow path are preferable
           const path_depth = canonPath.declNames.length * 50;
           // matching the start of a decl name is good
-          const match_from_start = decl_name.startsWith(term) ? -term.length * (1 -ignoreCase) : (decl_name.length - term.length) + 1; 
+          const match_from_start = decl_name.startsWith(term) ? -term.length * (2 -ignoreCase) : (decl_name.length - term.length) + 1; 
           // being a perfect match is good
-          const is_full_match = (list == result.full) ? -decl_name.length * (2 - ignoreCase) : decl_name.length - term.length;
+          const is_full_match = (decl_name === term) ? -decl_name.length * (1 - ignoreCase) : Math.abs(decl_name.length - term.length);
           // matching the end of a decl name is good
           const matches_the_end = decl_name.endsWith(term) ? -term.length * (1 - ignoreCase) : (decl_name.length - term.length) + 1;
           // explicitly penalizing scream case decls
@@ -4409,7 +4409,7 @@ function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
 
         const href = navLink(canonPath.modNames, canonPath.declNames);
 
-        matchedItemsHTML += "<li><a href=\"" + href + "\">" +  text + "</a></li>";
+        matchedItemsHTML += "<li><a href=\"" + href + "\">" + text + "</a></li>";
       }
     }
 
src/Autodoc.zig
@@ -1630,8 +1630,6 @@ fn walkInstruction(
 
             self.exprs.items[bin_index] = .{ .builtin = .{ .name = @tagName(tags[inst_index]), .param = rhs_index } };
 
-            std.debug.print("lhs: {any}\n\n", .{lhs});
-            std.debug.print("lhs typeref: {any}\n\n", .{lhs.typeRef});
             return DocData.WalkResult{
                 .typeRef = lhs.expr,
                 .expr = .{ .builtinIndex = bin_index },