hop
Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.
Brought by drakestapleton
hop / Omega / tests / FileScoreReference.swift
| 1 | import Foundation |
| 2 | |
| 3 | /// The Swift path scoring Hop shipped up to 0.4.0, kept only as the reference the Omega core is checked against. |
| 4 | enum FileScoreReference { |
| 5 | static func score(path: String, terms: [String]) -> Int? { |
| 6 | let lowPath = path.lowercased() |
| 7 | let name = (lowPath as NSString).lastPathComponent |
| 8 | var s = 0 |
| 9 | for t in terms { |
| 10 | if name.contains(t) { s += name.hasPrefix(t) ? 60 : 30 } |
| 11 | else if lowPath.contains(t) { s += 5 } |
| 12 | else { return nil } |
| 13 | } |
| 14 | s -= path.utf8.count / 20 |
| 15 | if name.utf8.count == terms.reduce(0, { $0 + $1.utf8.count }) { s += 40 } |
| 16 | return s |
| 17 | } |
| 18 | } |