presentation/CommandCompletion.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "CommandCompletion.h" | ||
| 2 | |||
| 3 | #include "EventQuickInput.h" | ||
| 4 | #include "TaskConsoleInput.h" | ||
| 5 | #include "app/NamedCommandCatalog.h" | ||
| 6 | #include "app/SearchVocabulary.h" | ||
| 7 | #include <QCoreApplication> | ||
| 8 | #include <QHash> | ||
| 9 | #include <QLocale> | ||
| 10 | #include <QLoggingCategory> | ||
| 11 | #include <algorithm> | ||
| 12 | |||
| 13 |
4/7✓ Branch 2 → 3 taken 14 times.
✓ Branch 2 → 8 taken 1224 times.
✓ Branch 4 → 5 taken 14 times.
✗ Branch 4 → 8 not taken.
✓ Branch 5 → 6 taken 14 times.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
|
1238 | Q_LOGGING_CATEGORY(lcCommandBar, "mailjd.commandbar") |
| 14 | |||
| 15 | namespace CommandCompletion { | ||
| 16 | namespace { | ||
| 17 | |||
| 18 | 504 | QString tr(const char *text) { return QCoreApplication::translate("CommandCompletion", text); } | |
| 19 | |||
| 20 | // A word of the typed text: [start, end) in the input. | ||
| 21 | struct Token { | ||
| 22 | QString text; | ||
| 23 | int start = 0; | ||
| 24 | int end = 0; | ||
| 25 | }; | ||
| 26 | |||
| 27 | // The word that ends at `cursor` (scanning back to the previous space). | ||
| 28 | 956 | Token tokenAt(const QString &text, int cursor) { | |
| 29 | 956 | int start = cursor; | |
| 30 |
6/6✓ Branch 4 → 5 taken 6003 times.
✓ Branch 4 → 9 taken 241 times.
✓ Branch 7 → 8 taken 5288 times.
✓ Branch 7 → 9 taken 715 times.
✓ Branch 10 → 3 taken 5288 times.
✓ Branch 10 → 11 taken 956 times.
|
6244 | while (start > 0 && !text.at(start - 1).isSpace()) --start; |
| 31 | 956 | int end = cursor; | |
| 32 |
4/6✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 19 taken 955 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 1 time.
✗ Branch 20 → 12 not taken.
✓ Branch 20 → 21 taken 956 times.
|
956 | while (end < text.size() && !text.at(end).isSpace()) ++end; |
| 33 | 2868 | return {text.mid(start, cursor - start), start, end}; | |
| 34 | 956 | } | |
| 35 | |||
| 36 | 49350 | bool anyWordStartsWith(const QString &words, const QString &needle) { | |
| 37 |
5/5✓ Branch 5 → 6 taken 49350 times.
✓ Branch 6 → 7 taken 49350 times.
✓ Branch 7 → 8 taken 49350 times.
✓ Branch 15 → 9 taken 133946 times.
✓ Branch 15 → 16 taken 48666 times.
|
182612 | for (const QString &word : words.split(QLatin1Char(' '), Qt::SkipEmptyParts)) |
| 38 |
5/5✓ Branch 10 → 11 taken 133946 times.
✓ Branch 11 → 12 taken 684 times.
✓ Branch 11 → 13 taken 133262 times.
✓ Branch 18 → 19 taken 48666 times.
✓ Branch 18 → 21 taken 684 times.
|
182612 | if (word.startsWith(needle, Qt::CaseInsensitive)) return true; |
| 39 | 48666 | return false; | |
| 40 | } | ||
| 41 | |||
| 42 | // §5.2 tiers for a name or value: 0 exact, 1 prefix, 2 keyword prefix, | ||
| 43 | // 3 word start in the description, 4 substring of the name, 5 substring of | ||
| 44 | // a keyword or the description; -1 = no match. | ||
| 45 | 25590 | int tierOf(const QString &word, const QString &keywords, const QString &description, const QString &needle) { | |
| 46 |
2/2✓ Branch 3 → 4 taken 301 times.
✓ Branch 3 → 5 taken 25289 times.
|
25590 | if (needle.isEmpty()) return 1; |
| 47 |
2/2✓ Branch 6 → 7 taken 230 times.
✓ Branch 6 → 8 taken 25059 times.
|
25289 | if (word.compare(needle, Qt::CaseInsensitive) == 0) return 0; |
| 48 |
2/2✓ Branch 9 → 10 taken 253 times.
✓ Branch 9 → 11 taken 24806 times.
|
25059 | if (word.startsWith(needle, Qt::CaseInsensitive)) return 1; |
| 49 |
2/2✓ Branch 12 → 13 taken 262 times.
✓ Branch 12 → 14 taken 24544 times.
|
24806 | if (anyWordStartsWith(keywords, needle)) return 2; |
| 50 |
2/2✓ Branch 15 → 16 taken 422 times.
✓ Branch 15 → 17 taken 24122 times.
|
24544 | if (anyWordStartsWith(description, needle)) return 3; |
| 51 |
2/2✓ Branch 18 → 19 taken 310 times.
✓ Branch 18 → 20 taken 23812 times.
|
24122 | if (word.contains(needle, Qt::CaseInsensitive)) return 4; |
| 52 | // Inner substrings of keywords and descriptions only from three letters on | ||
| 53 | // ("ar" would list every command with "markierung" or "Calendar"). | ||
| 54 |
4/4✓ Branch 21 → 22 taken 20682 times.
✓ Branch 21 → 27 taken 3130 times.
✓ Branch 28 → 29 taken 54 times.
✓ Branch 28 → 30 taken 23758 times.
|
44494 | if (needle.size() >= 3 && |
| 55 |
4/4✓ Branch 23 → 24 taken 20662 times.
✓ Branch 23 → 26 taken 20 times.
✓ Branch 25 → 26 taken 34 times.
✓ Branch 25 → 27 taken 20628 times.
|
20682 | (keywords.contains(needle, Qt::CaseInsensitive) || description.contains(needle, Qt::CaseInsensitive))) |
| 56 | 54 | return 5; | |
| 57 | 23758 | return -1; | |
| 58 | } | ||
| 59 | |||
| 60 | 3071 | QList<QPair<int, int>> matchRanges(const QString &title, const QString &needle) { | |
| 61 |
2/2✓ Branch 3 → 4 taken 403 times.
✓ Branch 3 → 5 taken 2668 times.
|
3071 | if (needle.isEmpty()) return {}; |
| 62 |
1/1✓ Branch 5 → 6 taken 2668 times.
|
2668 | const int at = title.indexOf(needle, 0, Qt::CaseInsensitive); |
| 63 |
3/3✓ Branch 6 → 7 taken 12 times.
✓ Branch 6 → 8 taken 2656 times.
✓ Branch 10 → 11 taken 2656 times.
|
2668 | return at < 0 ? QList<QPair<int, int>>{} : QList<QPair<int, int>>{{at, int(needle.size())}}; |
| 64 | } | ||
| 65 | |||
| 66 | // History frecency of a command line or name (D-9): recent and frequent | ||
| 67 | // lines rank first within their tier. | ||
| 68 | 1515 | double frecency(const QStringList &history, const QString &line) { | |
| 69 | 1515 | double score = 0; | |
| 70 |
2/2✓ Branch 20 → 3 taken 373 times.
✓ Branch 20 → 21 taken 1515 times.
|
1888 | for (int i = 0; i < history.size(); ++i) |
| 71 |
9/12✓ Branch 5 → 6 taken 371 times.
✓ Branch 5 → 12 taken 2 times.
✓ Branch 9 → 10 taken 371 times.
✓ Branch 10 → 11 taken 371 times.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 371 times.
✓ Branch 14 → 15 taken 371 times.
✓ Branch 14 → 16 taken 2 times.
✓ Branch 16 → 17 taken 2 times.
✓ Branch 16 → 18 taken 371 times.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
|
373 | if (history.at(i) == line || history.at(i).startsWith(line + QLatin1Char(' '))) score += 1.0 / (1 + i); |
| 72 | 1515 | return score; | |
| 73 | } | ||
| 74 | |||
| 75 | 3099 | QString shortcutOf(const char *registryId, const Sources &sources) { | |
| 76 |
7/10✓ Branch 2 → 3 taken 2007 times.
✓ Branch 2 → 9 taken 1092 times.
✓ Branch 4 → 5 taken 2007 times.
✗ Branch 4 → 9 not taken.
✓ Branch 6 → 7 taken 2007 times.
✓ Branch 7 → 8 taken 2007 times.
✓ Branch 11 → 12 taken 2007 times.
✓ Branch 11 → 13 taken 1092 times.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
|
6198 | return registryId && sources.shortcut ? sources.shortcut(QString::fromLatin1(registryId)) : QString{}; |
| 77 | } | ||
| 78 | |||
| 79 | 3099 | QString detailOf(const QString &line, const QString &fallback, const Sources &sources) { | |
| 80 |
3/3✓ Branch 3 → 4 taken 2262 times.
✓ Branch 3 → 5 taken 837 times.
✓ Branch 4 → 6 taken 2262 times.
|
3099 | const QString contextual = sources.contextDetail ? sources.contextDetail(line) : QString{}; |
| 81 |
2/2✓ Branch 7 → 8 taken 2993 times.
✓ Branch 7 → 9 taken 106 times.
|
6198 | return contextual.isEmpty() ? fallback : contextual; |
| 82 | 3099 | } | |
| 83 | |||
| 84 | 2437 | Candidate commandRow(const NamedCommandSpec &spec, int tier, const QString &needle, const Token &token, | |
| 85 | const Sources &sources) { | ||
| 86 | 2437 | Candidate row; | |
| 87 |
1/1✓ Branch 6 → 7 taken 2437 times.
|
4874 | row.key = QStringLiteral("cmd:") + spec.name; |
| 88 | 2437 | row.insertText = spec.name; | |
| 89 | 2437 | row.replaceStart = token.start; | |
| 90 | 2437 | row.replaceEnd = token.end; | |
| 91 | 2437 | row.appendSpace = spec.requiresArgument(); | |
| 92 | 2437 | row.title = spec.name; | |
| 93 |
5/5✓ Branch 14 → 15 taken 2271 times.
✓ Branch 14 → 16 taken 166 times.
✓ Branch 15 → 16 taken 250 times.
✓ Branch 15 → 18 taken 2021 times.
✓ Branch 16 → 17 taken 416 times.
|
2853 | row.titleMatches = tier == 1 || tier == 4 ? matchRanges(spec.name, needle) : QList<QPair<int, int>>{}; |
| 94 |
1/1✓ Branch 22 → 23 taken 2437 times.
|
2437 | row.argumentHint = QString::fromUtf8(spec.syntax); |
| 95 |
2/2✓ Branch 25 → 26 taken 2437 times.
✓ Branch 26 → 27 taken 2437 times.
|
2437 | row.detail = detailOf(spec.name, NamedCommandCatalog::description(spec), sources); |
| 96 |
1/1✓ Branch 30 → 31 taken 2437 times.
|
2437 | row.shortcut = shortcutOf(spec.registryId, sources); |
| 97 |
1/1✓ Branch 33 → 34 taken 2437 times.
|
2437 | row.reason = availabilityReason(spec, spec.name, sources); |
| 98 | 2437 | row.available = row.reason.isEmpty(); | |
| 99 |
2/2✓ Branch 37 → 38 taken 226 times.
✓ Branch 37 → 39 taken 2211 times.
|
2437 | if (!row.available) row.shortcut.clear(); |
| 100 | 2437 | row.destructive = spec.destructive; | |
| 101 |
2/2✓ Branch 39 → 40 taken 181 times.
✓ Branch 39 → 57 taken 2256 times.
|
2437 | if (spec.stateKey) { |
| 102 | 181 | row.rowType = QStringLiteral("toggle"); | |
| 103 |
4/8✓ Branch 47 → 48 taken 181 times.
✗ Branch 47 → 51 not taken.
✓ Branch 49 → 50 taken 181 times.
✓ Branch 50 → 52 taken 181 times.
✓ Branch 54 → 55 taken 181 times.
✗ Branch 54 → 56 not taken.
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 77 not taken.
|
181 | row.state = sources.state ? sources.state(QString::fromLatin1(spec.stateKey)) : QString{}; |
| 104 | } | ||
| 105 | 2437 | row.tier = tier; | |
| 106 | 2437 | return row; | |
| 107 | ✗ | } | |
| 108 | |||
| 109 | // A whole line "command value" offered at command level (§5.2: "unread" → | ||
| 110 | // "filter unread", "wichtig" → "mark important"). | ||
| 111 | 108 | Candidate lineRow(const NamedCommandSpec &spec, const NamedCommandValue &value, int tier, const Token &token, | |
| 112 | const Sources &sources) { | ||
| 113 |
3/3✓ Branch 3 → 4 taken 108 times.
✓ Branch 6 → 7 taken 108 times.
✓ Branch 7 → 8 taken 108 times.
|
108 | const QString line = spec.name + QLatin1Char(' ') + QString::fromLatin1(value.word); |
| 114 |
1/1✓ Branch 10 → 11 taken 108 times.
|
108 | Candidate row; |
| 115 |
1/1✓ Branch 14 → 15 taken 108 times.
|
108 | row.key = QStringLiteral("line:") + line; |
| 116 | 108 | row.insertText = line; | |
| 117 | 108 | row.replaceStart = token.start; | |
| 118 | 108 | row.replaceEnd = token.end; | |
| 119 | 108 | row.appendSpace = value.thenRequired; | |
| 120 | 108 | row.title = line; | |
| 121 |
1/1✓ Branch 22 → 23 taken 108 times.
|
108 | row.argumentHint = QString::fromUtf8(value.thenSyntax); |
| 122 |
2/2✓ Branch 25 → 26 taken 108 times.
✓ Branch 26 → 27 taken 108 times.
|
108 | row.detail = detailOf(line, NamedCommandCatalog::description(value), sources); |
| 123 |
3/3✓ Branch 30 → 31 taken 75 times.
✓ Branch 30 → 32 taken 33 times.
✓ Branch 33 → 34 taken 108 times.
|
108 | row.shortcut = shortcutOf(value.registryId ? value.registryId : spec.registryId, sources); |
| 124 |
1/1✓ Branch 36 → 37 taken 108 times.
|
108 | row.reason = availabilityReason(spec, line, sources); |
| 125 | 108 | row.available = row.reason.isEmpty(); | |
| 126 |
2/2✓ Branch 40 → 41 taken 6 times.
✓ Branch 40 → 42 taken 102 times.
|
108 | if (!row.available) row.shortcut.clear(); |
| 127 | 108 | row.rowType = QStringLiteral("value"); | |
| 128 |
7/8✓ Branch 48 → 49 taken 5 times.
✓ Branch 48 → 52 taken 103 times.
✓ Branch 50 → 51 taken 5 times.
✗ Branch 50 → 52 not taken.
✓ Branch 53 → 54 taken 5 times.
✓ Branch 53 → 61 taken 103 times.
✓ Branch 55 → 56 taken 5 times.
✓ Branch 56 → 57 taken 5 times.
|
108 | if (value.stateKey && sources.state) row.state = sources.state(QString::fromLatin1(value.stateKey)); |
| 129 | 108 | row.tier = tier; | |
| 130 | 108 | return row; | |
| 131 | 108 | } | |
| 132 | |||
| 133 | // Sort by availability (D-8), tier, frecency; then commands before offered | ||
| 134 | // whole lines, shorter names first among name prefixes ("fo" → folder | ||
| 135 | // before forward), and | ||
| 136 | // finally the order the provider produced; cap at MaxCandidates. | ||
| 137 | 489 | void rank(QList<Candidate> &rows, const QStringList &history) { | |
| 138 | 489 | QHash<QString, double> scores; | |
| 139 |
6/6✓ Branch 2 → 3 taken 489 times.
✓ Branch 3 → 4 taken 489 times.
✓ Branch 6 → 7 taken 1515 times.
✓ Branch 7 → 8 taken 1515 times.
✓ Branch 10 → 5 taken 1515 times.
✓ Branch 10 → 11 taken 489 times.
|
2004 | for (const auto &row : rows) scores.insert(row.key, frecency(history, row.insertText)); |
| 140 |
3/3✓ Branch 11 → 12 taken 489 times.
✓ Branch 12 → 13 taken 489 times.
✓ Branch 13 → 14 taken 489 times.
|
489 | std::stable_sort(rows.begin(), rows.end(), [&scores](const Candidate &a, const Candidate &b) { |
| 141 |
2/2✓ Branch 2 → 3 taken 80 times.
✓ Branch 2 → 4 taken 2840 times.
|
2920 | if (a.available != b.available) return a.available; |
| 142 |
2/2✓ Branch 4 → 5 taken 1212 times.
✓ Branch 4 → 6 taken 1628 times.
|
2840 | if (a.tier != b.tier) return a.tier < b.tier; |
| 143 | 1628 | const double scoreA = scores.value(a.key); | |
| 144 | 1628 | const double scoreB = scores.value(b.key); | |
| 145 |
2/2✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 10 taken 1627 times.
|
1628 | if (scoreA != scoreB) return scoreA > scoreB; |
| 146 |
1/1✓ Branch 11 → 12 taken 1627 times.
|
1627 | const bool lineA = a.key.startsWith(QLatin1String("line:")); |
| 147 |
1/1✓ Branch 13 → 14 taken 1627 times.
|
1627 | const bool lineB = b.key.startsWith(QLatin1String("line:")); |
| 148 |
2/2✓ Branch 14 → 15 taken 36 times.
✓ Branch 14 → 16 taken 1591 times.
|
1627 | if (lineA != lineB) return lineB; |
| 149 |
5/6✓ Branch 17 → 18 taken 1591 times.
✓ Branch 18 → 19 taken 1097 times.
✓ Branch 18 → 23 taken 494 times.
✓ Branch 20 → 21 taken 1097 times.
✓ Branch 21 → 22 taken 1097 times.
✗ Branch 21 → 23 not taken.
|
1591 | const bool commands = a.key.startsWith(QLatin1String("cmd:")) && b.key.startsWith(QLatin1String("cmd:")); |
| 150 |
8/8✓ Branch 24 → 25 taken 1097 times.
✓ Branch 24 → 30 taken 494 times.
✓ Branch 25 → 26 taken 70 times.
✓ Branch 25 → 30 taken 1027 times.
✓ Branch 28 → 29 taken 47 times.
✓ Branch 28 → 30 taken 23 times.
✓ Branch 31 → 32 taken 47 times.
✓ Branch 31 → 35 taken 1544 times.
|
1591 | if (commands && a.tier == 1 && a.title.size() != b.title.size()) return a.title.size() < b.title.size(); |
| 151 | 1544 | return false; | |
| 152 | }); | ||
| 153 |
1/3✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 489 times.
✗ Branch 16 → 17 not taken.
|
489 | if (rows.size() > MaxCandidates) rows.resize(MaxCandidates); |
| 154 | 489 | } | |
| 155 | |||
| 156 |
1/2✓ Branch 3 → 4 taken 522 times.
✗ Branch 3 → 5 not taken.
|
522 | QStringList historyOf(const Sources &sources) { return sources.history ? sources.history() : QStringList{}; } |
| 157 | |||
| 158 | 241 | Result commandNames(const QString &text, const Token &token, const Sources &sources) { | |
| 159 | 241 | Result result; | |
| 160 | 241 | const QString needle = token.text; | |
| 161 | 241 | QList<Candidate> rows; | |
| 162 |
3/3✓ Branch 3 → 4 taken 241 times.
✓ Branch 28 → 6 taken 12532 times.
✓ Branch 28 → 29 taken 241 times.
|
12773 | for (const auto &spec : NamedCommandCatalog::specs()) { |
| 163 |
3/3✓ Branch 7 → 8 taken 12532 times.
✓ Branch 9 → 10 taken 12532 times.
✓ Branch 10 → 11 taken 12532 times.
|
12532 | const int tier = tierOf(spec.name, QString::fromUtf8(spec.keywords), NamedCommandCatalog::description(spec), needle); |
| 164 |
2/2✓ Branch 13 → 14 taken 11438 times.
✓ Branch 13 → 15 taken 1094 times.
|
12652 | if (tier < 0) continue; |
| 165 |
1/1✓ Branch 15 → 16 taken 1094 times.
|
1094 | Candidate row = commandRow(spec, tier, needle, token, sources); |
| 166 | // D-8: commands that cannot run here appear only when asked for by name. | ||
| 167 |
4/4✓ Branch 16 → 17 taken 156 times.
✓ Branch 16 → 19 taken 938 times.
✓ Branch 17 → 18 taken 120 times.
✓ Branch 17 → 19 taken 36 times.
|
1094 | if (!row.available && tier > 1) continue; |
| 168 |
1/1✓ Branch 19 → 20 taken 974 times.
|
974 | rows.append(row); |
| 169 | 1094 | } | |
| 170 |
2/2✓ Branch 30 → 31 taken 177 times.
✓ Branch 30 → 67 taken 64 times.
|
241 | if (needle.size() >= 3) { |
| 171 |
3/3✓ Branch 31 → 32 taken 177 times.
✓ Branch 65 → 34 taken 9204 times.
✓ Branch 65 → 66 taken 177 times.
|
9381 | for (const auto &spec : NamedCommandCatalog::specs()) { |
| 172 |
2/2✓ Branch 62 → 37 taken 9912 times.
✓ Branch 62 → 63 taken 9204 times.
|
19116 | for (const auto &value : spec.values) { |
| 173 |
3/3✓ Branch 40 → 41 taken 9912 times.
✓ Branch 42 → 43 taken 9912 times.
✓ Branch 43 → 44 taken 9912 times.
|
9912 | const int tier = tierOf(QString::fromLatin1(value.word), QString::fromUtf8(value.keywords), QString{}, needle); |
| 174 |
4/4✓ Branch 47 → 48 taken 67 times.
✓ Branch 47 → 49 taken 9845 times.
✓ Branch 48 → 49 taken 18 times.
✓ Branch 48 → 50 taken 49 times.
|
9918 | if (tier < 0 || tier > 2) continue; |
| 175 |
1/1✓ Branch 50 → 51 taken 49 times.
|
49 | Candidate row = lineRow(spec, value, tier, token, sources); |
| 176 |
2/2✓ Branch 51 → 52 taken 6 times.
✓ Branch 51 → 53 taken 43 times.
|
49 | if (!row.available) continue; |
| 177 |
1/1✓ Branch 53 → 54 taken 43 times.
|
43 | rows.append(row); |
| 178 | 49 | } | |
| 179 | } | ||
| 180 | } | ||
| 181 |
2/2✓ Branch 67 → 68 taken 241 times.
✓ Branch 68 → 69 taken 241 times.
|
241 | rank(rows, historyOf(sources)); |
| 182 | 241 | result.candidates = rows; | |
| 183 | Q_UNUSED(text) | ||
| 184 | 241 | return result; | |
| 185 | 241 | } | |
| 186 | |||
| 187 | // The empty input (S98.5.1): Recent (≤ 3 history lines that can run here) | ||
| 188 | // and Here (≤ 5 featured commands of the context). | ||
| 189 | 281 | Result emptyState(const Sources &sources) { | |
| 190 | 281 | Result result; | |
| 191 | 281 | const Token token{QString{}, 0, 0}; | |
| 192 | 281 | QStringList seen; | |
| 193 |
5/5✓ Branch 2 → 3 taken 281 times.
✓ Branch 3 → 4 taken 281 times.
✓ Branch 4 → 5 taken 281 times.
✓ Branch 66 → 6 taken 253 times.
✓ Branch 66 → 67 taken 231 times.
|
484 | for (const QString &line : historyOf(sources)) { |
| 194 |
2/2✓ Branch 8 → 9 taken 50 times.
✓ Branch 8 → 10 taken 203 times.
|
253 | if (result.candidates.size() >= 3) break; |
| 195 |
1/1✓ Branch 10 → 11 taken 203 times.
|
203 | const auto parsed = NamedCommandCatalog::parse(line); |
| 196 |
10/12✓ Branch 11 → 12 taken 203 times.
✓ Branch 12 → 13 taken 202 times.
✓ Branch 12 → 16 taken 1 time.
✓ Branch 13 → 14 taken 202 times.
✓ Branch 15 → 16 taken 4 times.
✓ Branch 15 → 17 taken 198 times.
✓ Branch 18 → 19 taken 202 times.
✓ Branch 18 → 20 taken 1 time.
✓ Branch 20 → 21 taken 5 times.
✓ Branch 20 → 22 taken 198 times.
✗ Branch 146 → 147 not taken.
✗ Branch 146 → 148 not taken.
|
203 | if (!NamedCommandCatalog::storable(parsed) || !availabilityReason(*parsed.spec, line, sources).isEmpty()) continue; |
| 197 |
1/1✓ Branch 23 → 24 taken 198 times.
|
198 | Candidate row = commandRow(*parsed.spec, 0, QString{}, token, sources); |
| 198 | // S106-231: the line passed the gate above with its value; commandRow() | ||
| 199 | // judged the bare command name, which may differ ("move Archive"). | ||
| 200 | 198 | row.reason.clear(); | |
| 201 | 198 | row.available = true; | |
| 202 |
1/1✓ Branch 26 → 27 taken 198 times.
|
198 | row.shortcut = shortcutOf(parsed.spec->registryId, sources); |
| 203 |
1/1✓ Branch 32 → 33 taken 198 times.
|
198 | row.key = QStringLiteral("history:") + line; |
| 204 | 198 | row.insertText = row.title = line; | |
| 205 | 198 | row.argumentHint.clear(); | |
| 206 | 198 | row.appendSpace = false; | |
| 207 | 198 | row.group = QStringLiteral("recent"); | |
| 208 | 198 | row.rowType = QStringLiteral("history"); | |
| 209 |
1/1✓ Branch 52 → 53 taken 198 times.
|
198 | row.detail = detailOf(line, row.detail, sources); |
| 210 |
1/1✓ Branch 55 → 56 taken 198 times.
|
198 | result.candidates.append(row); |
| 211 |
1/1✓ Branch 56 → 57 taken 198 times.
|
198 | seen << line; |
| 212 | 484 | } | |
| 213 | 281 | int here = 0; | |
| 214 |
3/3✓ Branch 68 → 69 taken 281 times.
✓ Branch 141 → 71 taken 8132 times.
✓ Branch 141 → 142 taken 101 times.
|
8233 | for (const auto &spec : NamedCommandCatalog::specs()) { |
| 215 |
2/2✓ Branch 72 → 73 taken 180 times.
✓ Branch 72 → 74 taken 7952 times.
|
8132 | if (here >= 5) break; |
| 216 | 7952 | bool valueFeatured = false; | |
| 217 |
2/2✓ Branch 107 → 76 taken 7456 times.
✓ Branch 107 → 108 taken 7952 times.
|
15408 | for (const auto &value : spec.values) { |
| 218 |
5/6✓ Branch 78 → 79 taken 59 times.
✓ Branch 78 → 80 taken 7397 times.
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 81 taken 59 times.
✓ Branch 82 → 83 taken 7397 times.
✓ Branch 82 → 84 taken 59 times.
|
7464 | if (!value.featured.testFlag(sources.context) || here >= 5) continue; |
| 219 | 59 | valueFeatured = true; | |
| 220 |
1/1✓ Branch 84 → 85 taken 59 times.
|
59 | Candidate row = lineRow(spec, value, 0, token, sources); |
| 221 |
5/6✓ Branch 85 → 86 taken 59 times.
✗ Branch 85 → 88 not taken.
✓ Branch 87 → 88 taken 8 times.
✓ Branch 87 → 89 taken 51 times.
✓ Branch 90 → 91 taken 8 times.
✓ Branch 90 → 92 taken 51 times.
|
59 | if (!row.available || seen.contains(row.insertText)) continue; |
| 222 | 51 | row.group = QStringLiteral("here"); | |
| 223 |
1/1✓ Branch 98 → 99 taken 51 times.
|
51 | result.candidates.append(row); |
| 224 | 51 | ++here; | |
| 225 | 59 | } | |
| 226 |
7/8✓ Branch 108 → 109 taken 7931 times.
✓ Branch 108 → 112 taken 21 times.
✓ Branch 110 → 111 taken 1145 times.
✓ Branch 110 → 112 taken 6786 times.
✗ Branch 111 → 112 not taken.
✓ Branch 111 → 113 taken 1145 times.
✓ Branch 114 → 115 taken 6807 times.
✓ Branch 114 → 116 taken 1145 times.
|
8023 | if (valueFeatured || !spec.featured.testFlag(sources.context) || here >= 5) continue; |
| 227 |
1/1✓ Branch 117 → 118 taken 1145 times.
|
1145 | Candidate row = commandRow(spec, 0, QString{}, token, sources); |
| 228 |
6/6✓ Branch 119 → 120 taken 1076 times.
✓ Branch 119 → 122 taken 69 times.
✓ Branch 121 → 122 taken 2 times.
✓ Branch 121 → 123 taken 1074 times.
✓ Branch 124 → 125 taken 71 times.
✓ Branch 124 → 126 taken 1074 times.
|
1145 | if (!row.available || seen.contains(spec.name)) continue; |
| 229 | 1074 | row.group = QStringLiteral("here"); | |
| 230 |
1/1✓ Branch 132 → 133 taken 1074 times.
|
1074 | result.candidates.append(row); |
| 231 | 1074 | ++here; | |
| 232 | 1145 | } | |
| 233 | 281 | return result; | |
| 234 | 281 | } | |
| 235 | |||
| 236 | 356 | Candidate valueRow(const NamedCommandSpec &spec, const NamedCommandValue &value, int tier, const QString &needle, | |
| 237 | const Token &token, const Sources &sources) { | ||
| 238 |
1/1✓ Branch 3 → 4 taken 356 times.
|
356 | const QString word = QString::fromLatin1(value.word); |
| 239 |
2/2✓ Branch 6 → 7 taken 356 times.
✓ Branch 7 → 8 taken 356 times.
|
356 | const QString line = spec.name + QLatin1Char(' ') + word; |
| 240 |
1/1✓ Branch 9 → 10 taken 356 times.
|
356 | Candidate row; |
| 241 |
3/3✓ Branch 15 → 16 taken 356 times.
✓ Branch 16 → 17 taken 356 times.
✓ Branch 17 → 18 taken 356 times.
|
712 | row.key = QStringLiteral("value:") + spec.name + QLatin1Char(':') + word; |
| 242 | 356 | row.insertText = word; | |
| 243 | 356 | row.replaceStart = token.start; | |
| 244 | 356 | row.replaceEnd = token.end; | |
| 245 | 356 | row.appendSpace = value.thenRequired; | |
| 246 | 356 | row.title = word; | |
| 247 |
5/5✓ Branch 26 → 27 taken 190 times.
✓ Branch 26 → 28 taken 166 times.
✓ Branch 27 → 28 taken 14 times.
✓ Branch 27 → 30 taken 176 times.
✓ Branch 28 → 29 taken 180 times.
|
536 | row.titleMatches = tier == 1 || tier == 4 ? matchRanges(word, needle) : QList<QPair<int, int>>{}; |
| 248 |
1/1✓ Branch 34 → 35 taken 356 times.
|
356 | row.argumentHint = QString::fromUtf8(value.thenSyntax); |
| 249 |
2/2✓ Branch 37 → 38 taken 356 times.
✓ Branch 38 → 39 taken 356 times.
|
356 | row.detail = detailOf(line, NamedCommandCatalog::description(value), sources); |
| 250 |
1/1✓ Branch 42 → 43 taken 356 times.
|
356 | row.shortcut = shortcutOf(value.registryId, sources); |
| 251 |
1/1✓ Branch 45 → 46 taken 356 times.
|
356 | row.reason = availabilityReason(spec, line, sources); |
| 252 | 356 | row.available = row.reason.isEmpty(); | |
| 253 | 356 | row.rowType = QStringLiteral("value"); | |
| 254 |
7/8✓ Branch 55 → 56 taken 172 times.
✓ Branch 55 → 59 taken 184 times.
✓ Branch 57 → 58 taken 172 times.
✗ Branch 57 → 59 not taken.
✓ Branch 60 → 61 taken 172 times.
✓ Branch 60 → 68 taken 184 times.
✓ Branch 62 → 63 taken 172 times.
✓ Branch 63 → 64 taken 172 times.
|
356 | if (value.stateKey && sources.state) row.state = sources.state(QString::fromLatin1(value.stateKey)); |
| 255 | 356 | row.tier = tier; | |
| 256 | 356 | return row; | |
| 257 | 356 | } | |
| 258 | |||
| 259 |
2/2✓ Branch 2 → 3 taken 22 times.
✓ Branch 6 → 7 taken 22 times.
|
44 | QString shortDate(const QDate &date) { return QLocale().toString(date, QStringLiteral("ddd d MMM")); } |
| 260 | |||
| 261 | // Date words of EventQuickParse; `minimum` letters must be typed first (an | ||
| 262 | // "@" alone offers the relative words, a bare word needs two letters). | ||
| 263 | 31 | QList<Candidate> dateWordRows(const QString &prefix, const QString &needle, int minimum, const Token &token, | |
| 264 | const Sources &sources) { | ||
| 265 | 31 | QList<Candidate> rows; | |
| 266 |
2/2✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 30 times.
|
31 | if (needle.size() < minimum) return rows; |
| 267 |
1/1✓ Branch 5 → 6 taken 30 times.
|
30 | const QStringList words = EventQuickParse::dateWords(); |
| 268 |
3/5✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 30 times.
✗ Branch 8 → 10 not taken.
✓ Branch 49 → 12 taken 600 times.
✓ Branch 49 → 50 taken 30 times.
|
630 | for (const QString &word : needle.isEmpty() ? words.mid(0, 5) : words) { |
| 269 |
3/3✓ Branch 13 → 14 taken 600 times.
✓ Branch 14 → 15 taken 578 times.
✓ Branch 14 → 16 taken 22 times.
|
600 | if (!word.startsWith(needle, Qt::CaseInsensitive)) continue; |
| 270 |
1/1✓ Branch 16 → 17 taken 22 times.
|
22 | Candidate row; |
| 271 |
1/1✓ Branch 20 → 21 taken 22 times.
|
22 | row.key = QStringLiteral("token:date:") + word; |
| 272 |
1/1✓ Branch 25 → 26 taken 22 times.
|
22 | row.insertText = prefix + word; |
| 273 | 22 | row.replaceStart = token.start; | |
| 274 | 22 | row.replaceEnd = token.end; | |
| 275 | 22 | row.appendSpace = true; | |
| 276 | 22 | row.title = word; | |
| 277 |
1/1✓ Branch 29 → 30 taken 22 times.
|
22 | row.titleMatches = matchRanges(word, needle); |
| 278 |
2/2✓ Branch 32 → 33 taken 22 times.
✓ Branch 33 → 34 taken 22 times.
|
22 | row.trailing = shortDate(EventQuickParse::parseDate(word, sources.today)); |
| 279 | 22 | row.rowType = QStringLiteral("date"); | |
| 280 | 22 | row.tier = word.compare(needle, Qt::CaseInsensitive) == 0 ? 0 : 1; | |
| 281 |
1/1✓ Branch 43 → 44 taken 22 times.
|
22 | rows.append(row); |
| 282 | 52 | } | |
| 283 | 30 | return rows; | |
| 284 | 30 | } | |
| 285 | |||
| 286 | 500 | Candidate hintRow(const QString &key, const QString &syntax, const QString &example) { | |
| 287 | 500 | Candidate row; | |
| 288 |
1/1✓ Branch 6 → 7 taken 500 times.
|
500 | row.key = QStringLiteral("hint:") + key; |
| 289 | 500 | row.kind = QStringLiteral("hint"); | |
| 290 | 500 | row.title = syntax; | |
| 291 |
6/8✓ Branch 19 → 20 taken 319 times.
✓ Branch 19 → 21 taken 181 times.
✓ Branch 21 → 22 taken 181 times.
✓ Branch 23 → 24 taken 181 times.
✓ Branch 26 → 27 taken 181 times.
✓ Branch 26 → 28 taken 319 times.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 46 not taken.
|
500 | row.detail = example.isEmpty() ? QString{} : tr("e.g. %1").arg(example); |
| 292 | 500 | row.rowType = QStringLiteral("hint"); | |
| 293 | 500 | return row; | |
| 294 | ✗ | } | |
| 295 | |||
| 296 | 147 | QList<Candidate> folderRows(const QString &prefix, const QString &text, bool move, const Token &token, | |
| 297 | const Sources &sources) { | ||
| 298 | 147 | QList<Candidate> rows; | |
| 299 |
2/2✓ Branch 3 → 4 taken 2 times.
✓ Branch 3 → 5 taken 145 times.
|
147 | if (!sources.folders) return rows; |
| 300 | 145 | int order = 0; | |
| 301 |
5/5✓ Branch 5 → 6 taken 145 times.
✓ Branch 6 → 7 taken 145 times.
✓ Branch 7 → 8 taken 145 times.
✓ Branch 71 → 9 taken 2243 times.
✓ Branch 71 → 72 taken 145 times.
|
2388 | for (const FolderEntry &folder : sources.folders(text, move)) { |
| 302 |
1/1✓ Branch 10 → 11 taken 2243 times.
|
2243 | Candidate row; |
| 303 |
1/1✓ Branch 14 → 15 taken 2243 times.
|
4486 | row.key = QStringLiteral("folder:") + folder.path; |
| 304 |
4/5✓ Branch 20 → 21 taken 2 times.
✓ Branch 20 → 26 taken 2241 times.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 2 times.
|
2243 | const bool quote = !prefix.isEmpty() && folder.path.contains(QLatin1Char(' ')); |
| 305 |
3/9✗ Branch 27 → 28 not taken.
✓ Branch 27 → 34 taken 2243 times.
✗ Branch 32 → 33 not taken.
✗ Branch 33 → 35 not taken.
✓ Branch 35 → 36 taken 2243 times.
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 2243 times.
✗ Branch 86 → 87 not taken.
✗ Branch 86 → 88 not taken.
|
2243 | row.insertText = prefix + (quote ? QLatin1Char('"') + folder.path + QLatin1Char('"') : folder.path); |
| 306 | 2243 | row.replaceStart = token.start; | |
| 307 | 2243 | row.replaceEnd = token.end; | |
| 308 | 2243 | row.title = folder.name; | |
| 309 |
2/2✓ Branch 45 → 46 taken 2243 times.
✓ Branch 46 → 47 taken 2243 times.
|
2243 | row.titleMatches = matchRanges(folder.name, text.section(QLatin1Char('/'), -1)); |
| 310 | 2243 | row.secondary = folder.parent; | |
| 311 |
1/3✗ Branch 51 → 52 not taken.
✓ Branch 51 → 53 taken 2243 times.
✗ Branch 52 → 54 not taken.
|
2243 | row.trailing = folder.unread > 0 ? QString::number(folder.unread) : QString{}; |
| 312 |
3/3✓ Branch 56 → 57 taken 5 times.
✓ Branch 56 → 58 taken 2238 times.
✓ Branch 57 → 59 taken 5 times.
|
2243 | row.detail = folder.suggested ? tr("Suggested") : QString{}; |
| 313 | 2243 | row.rowType = QStringLiteral("folder"); | |
| 314 | 2243 | row.tier = order++; | |
| 315 |
1/1✓ Branch 67 → 68 taken 2243 times.
|
2243 | rows.append(row); |
| 316 | 2388 | } | |
| 317 | 145 | return rows; | |
| 318 | ✗ | } | |
| 319 | |||
| 320 | // Values of a command whose argument is a fixed word (filter, mark, tasks, | ||
| 321 | // threads, folder …) and, for calendar, date words. | ||
| 322 | 177 | Result valueArgument(const NamedCommandSpec &spec, const QString &text, const Token &token, const Sources &sources) { | |
| 323 | 177 | Result result; | |
| 324 | 177 | const QString needle = token.text; | |
| 325 | 177 | QList<Candidate> rows; | |
| 326 |
2/2✓ Branch 30 → 5 taken 734 times.
✓ Branch 30 → 31 taken 177 times.
|
911 | for (const auto &value : spec.values) { |
| 327 |
3/3✓ Branch 8 → 9 taken 734 times.
✓ Branch 10 → 11 taken 734 times.
✓ Branch 11 → 12 taken 734 times.
|
734 | const int tier = tierOf(QString::fromLatin1(value.word), QString::fromUtf8(value.keywords), |
| 328 |
1/1✓ Branch 6 → 7 taken 734 times.
|
1468 | NamedCommandCatalog::description(value), needle); |
| 329 |
2/2✓ Branch 15 → 16 taken 381 times.
✓ Branch 15 → 17 taken 353 times.
|
734 | if (tier < 0) continue; |
| 330 |
1/1✓ Branch 17 → 18 taken 353 times.
|
353 | Candidate row = valueRow(spec, value, tier, needle, token, sources); |
| 331 |
3/4✓ Branch 18 → 19 taken 15 times.
✓ Branch 18 → 21 taken 338 times.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 15 times.
|
353 | if (!row.available && tier > 1) continue; |
| 332 |
1/1✓ Branch 21 → 22 taken 353 times.
|
353 | rows.append(row); |
| 333 | 353 | } | |
| 334 |
2/2✓ Branch 31 → 32 taken 11 times.
✓ Branch 31 → 48 taken 166 times.
|
177 | if (spec.argument == CommandArgument::Date) { |
| 335 | // A date word ("heute") ranks after the values and their keywords. | ||
| 336 |
5/5✓ Branch 33 → 34 taken 11 times.
✓ Branch 35 → 36 taken 11 times.
✓ Branch 36 → 37 taken 11 times.
✓ Branch 45 → 38 taken 8 times.
✓ Branch 45 → 46 taken 11 times.
|
19 | for (Candidate row : dateWordRows(QString{}, needle, 2, token, sources)) { |
| 337 | 8 | row.tier = std::max(row.tier, 3); | |
| 338 |
1/1✓ Branch 41 → 42 taken 8 times.
|
8 | rows << row; |
| 339 | 19 | } | |
| 340 | } | ||
| 341 |
1/1✓ Branch 49 → 50 taken 177 times.
|
177 | rank(rows, {}); |
| 342 | 177 | result.candidates = rows; | |
| 343 | // D-6: place-like values (calendar views, task lists) are pre-highlighted | ||
| 344 | // once something is typed that is not already the exact value. | ||
| 345 |
4/4✓ Branch 54 → 55 taken 166 times.
✓ Branch 54 → 58 taken 11 times.
✓ Branch 57 → 58 taken 5 times.
✓ Branch 57 → 59 taken 161 times.
|
177 | const bool placeLike = spec.name == QLatin1String("calendar") || spec.name == QLatin1String("tasks"); |
| 346 |
11/14✓ Branch 60 → 61 taken 16 times.
✓ Branch 60 → 70 taken 161 times.
✓ Branch 62 → 63 taken 16 times.
✗ Branch 62 → 70 not taken.
✓ Branch 64 → 65 taken 16 times.
✗ Branch 64 → 70 not taken.
✓ Branch 65 → 66 taken 16 times.
✓ Branch 66 → 67 taken 8 times.
✓ Branch 66 → 70 taken 8 times.
✓ Branch 67 → 68 taken 8 times.
✓ Branch 68 → 69 taken 8 times.
✗ Branch 68 → 70 not taken.
✓ Branch 71 → 72 taken 8 times.
✓ Branch 71 → 74 taken 169 times.
|
177 | if (placeLike && !needle.isEmpty() && !rows.isEmpty() && rows.first().tier > 0 && rows.first().available) |
| 347 |
1/1✓ Branch 72 → 73 taken 8 times.
|
8 | result.preselectKey = rows.first().key; |
| 348 | Q_UNUSED(text) | ||
| 349 | 177 | return result; | |
| 350 | 177 | } | |
| 351 | |||
| 352 | 135 | Result folderArgument(const NamedCommandSpec &spec, const QString &argument, int argumentStart, int end, bool move, | |
| 353 | const Sources &sources) { | ||
| 354 | 135 | Result result; | |
| 355 | 135 | const Token token{argument, argumentStart, end}; | |
| 356 |
1/1✓ Branch 4 → 5 taken 135 times.
|
135 | result.candidates = folderRows(QString{}, argument, move, token, sources); |
| 357 |
5/5✓ Branch 9 → 10 taken 132 times.
✓ Branch 9 → 14 taken 3 times.
✓ Branch 10 → 11 taken 132 times.
✓ Branch 12 → 13 taken 25 times.
✓ Branch 12 → 14 taken 107 times.
|
135 | const bool exact = !result.candidates.isEmpty() && result.candidates.first().insertText == argument; |
| 358 | // D-6: folders name a place; Enter on a partial name uses the first row | ||
| 359 | // (BB-04). An empty "move" pre-highlights the predicted target. | ||
| 360 |
15/17✓ Branch 16 → 17 taken 132 times.
✓ Branch 16 → 26 taken 3 times.
✓ Branch 17 → 18 taken 107 times.
✓ Branch 17 → 26 taken 25 times.
✓ Branch 19 → 20 taken 42 times.
✓ Branch 19 → 25 taken 65 times.
✓ Branch 20 → 21 taken 20 times.
✓ Branch 20 → 26 taken 22 times.
✓ Branch 22 → 23 taken 20 times.
✓ Branch 24 → 25 taken 3 times.
✓ Branch 24 → 26 taken 17 times.
✓ Branch 27 → 28 taken 20 times.
✓ Branch 27 → 29 taken 115 times.
✓ Branch 29 → 30 taken 68 times.
✓ Branch 29 → 32 taken 67 times.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
|
135 | if (!result.candidates.isEmpty() && !exact && (!argument.isEmpty() || (move && result.candidates.first().detail != QString{}))) |
| 361 |
1/1✓ Branch 30 → 31 taken 68 times.
|
68 | result.preselectKey = result.candidates.first().key; |
| 362 | Q_UNUSED(spec) | ||
| 363 | 135 | return result; | |
| 364 | 135 | } | |
| 365 | |||
| 366 | // `typed`: the labels earlier in the line (D-15a: "label Work Later"); they | ||
| 367 | // and "all" (only by itself) are not offered again. | ||
| 368 | 41 | Result labelArgument(const NamedCommandSpec &spec, const Token &token, const QStringList &typed, const Sources &sources) { | |
| 369 | 41 | Result result; | |
| 370 | 41 | const QString needle = token.text; | |
| 371 | 41 | QList<Candidate> rows; | |
| 372 |
2/2✓ Branch 37 → 5 taken 9 times.
✓ Branch 37 → 38 taken 41 times.
|
50 | for (const auto &value : spec.values) { |
| 373 |
5/6✓ Branch 6 → 7 taken 9 times.
✗ Branch 6 → 10 not taken.
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 10 taken 7 times.
✓ Branch 11 → 12 taken 2 times.
✓ Branch 11 → 13 taken 7 times.
|
13 | if (value.alone && !typed.isEmpty()) continue; |
| 374 |
3/3✓ Branch 15 → 16 taken 7 times.
✓ Branch 17 → 18 taken 7 times.
✓ Branch 18 → 19 taken 7 times.
|
7 | const int tier = tierOf(QString::fromLatin1(value.word), QString::fromUtf8(value.keywords), QString{}, needle); |
| 375 |
2/2✓ Branch 22 → 23 taken 4 times.
✓ Branch 22 → 24 taken 3 times.
|
7 | if (tier < 0) continue; |
| 376 |
1/1✓ Branch 24 → 25 taken 3 times.
|
3 | Candidate row = valueRow(spec, value, tier, needle, token, sources); |
| 377 | // S106-232: D-8 as for every other value provider — what cannot run | ||
| 378 | // here shows only when asked for by name. | ||
| 379 |
1/4✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 3 times.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
|
3 | if (!row.available && tier > 1) continue; |
| 380 |
1/1✓ Branch 28 → 29 taken 3 times.
|
3 | rows << row; |
| 381 | 3 | } | |
| 382 |
1/2✓ Branch 39 → 40 taken 41 times.
✗ Branch 39 → 125 not taken.
|
41 | if (sources.labels) { |
| 383 |
5/5✓ Branch 40 → 41 taken 41 times.
✓ Branch 41 → 42 taken 41 times.
✓ Branch 42 → 43 taken 41 times.
✓ Branch 122 → 44 taken 222 times.
✓ Branch 122 → 123 taken 41 times.
|
263 | for (const LabelEntry &label : sources.labels()) { |
| 384 |
2/2✓ Branch 46 → 47 taken 4 times.
✓ Branch 46 → 48 taken 218 times.
|
332 | if (typed.contains(label.keyword, Qt::CaseInsensitive)) continue; |
| 385 |
1/1✓ Branch 49 → 50 taken 218 times.
|
218 | const int tier = tierOf(label.keyword, label.name, QString{}, needle); |
| 386 |
1/1✓ Branch 53 → 54 taken 218 times.
|
218 | const int nameTier = tierOf(label.name, QString{}, QString{}, needle); |
| 387 |
4/4✓ Branch 56 → 57 taken 113 times.
✓ Branch 56 → 62 taken 105 times.
✓ Branch 57 → 58 taken 111 times.
✓ Branch 57 → 60 taken 2 times.
|
218 | const int best = tier < 0 ? nameTier : nameTier < 0 ? tier : std::min(tier, nameTier); |
| 388 |
2/2✓ Branch 63 → 64 taken 105 times.
✓ Branch 63 → 65 taken 113 times.
|
218 | if (best < 0) continue; |
| 389 |
1/1✓ Branch 65 → 66 taken 113 times.
|
113 | Candidate row; |
| 390 |
1/1✓ Branch 69 → 70 taken 113 times.
|
226 | row.key = QStringLiteral("label:") + label.keyword; |
| 391 | 113 | row.insertText = label.keyword; | |
| 392 | 113 | row.replaceStart = token.start; | |
| 393 | 113 | row.replaceEnd = token.end; | |
| 394 | 113 | row.title = label.name; | |
| 395 |
1/1✓ Branch 76 → 77 taken 113 times.
|
113 | row.titleMatches = matchRanges(label.name, needle); |
| 396 |
2/2✓ Branch 80 → 81 taken 105 times.
✓ Branch 80 → 82 taken 8 times.
|
113 | row.secondary = label.name != label.keyword ? label.keyword : QString{}; |
| 397 |
4/4✓ Branch 85 → 86 taken 14 times.
✓ Branch 85 → 89 taken 99 times.
✓ Branch 92 → 93 taken 14 times.
✓ Branch 92 → 94 taken 99 times.
|
127 | row.trailing = label.onSelection ? QStringLiteral("✓") : QString{}; |
| 398 | 113 | row.rowType = QStringLiteral("label"); | |
| 399 | 113 | row.tier = best; | |
| 400 |
3/3✓ Branch 102 → 103 taken 113 times.
✓ Branch 103 → 104 taken 113 times.
✓ Branch 104 → 105 taken 113 times.
|
113 | row.reason = availabilityReason(spec, spec.name + QLatin1Char(' ') + label.keyword, sources); |
| 401 | 113 | row.available = row.reason.isEmpty(); | |
| 402 |
4/4✓ Branch 110 → 111 taken 41 times.
✓ Branch 110 → 113 taken 72 times.
✓ Branch 111 → 112 taken 5 times.
✓ Branch 111 → 113 taken 36 times.
|
113 | if (!row.available && best > 1) continue; // S106-232 (D-8) |
| 403 |
1/1✓ Branch 113 → 114 taken 108 times.
|
108 | rows << row; |
| 404 | 154 | } | |
| 405 | } | ||
| 406 |
1/1✓ Branch 126 → 127 taken 41 times.
|
41 | rank(rows, {}); |
| 407 | 41 | result.candidates = rows; | |
| 408 | 41 | return result; | |
| 409 | 41 | } | |
| 410 | |||
| 411 | // The task line (P-14): the token under the cursor completes from its owner | ||
| 412 | // (rule 8): /list, @date, !priority, #tag. Quoted title text is never | ||
| 413 | // completed. | ||
| 414 | 52 | Result taskLine(const NamedCommandSpec &spec, const QString &text, const Token &token, const Sources &sources) { | |
| 415 | 52 | Result result; | |
| 416 |
2/2✓ Branch 2 → 3 taken 52 times.
✓ Branch 5 → 6 taken 52 times.
|
52 | const bool inQuotes = text.left(token.start).count(QLatin1Char('"')) % 2 == 1; |
| 417 | 52 | const QString word = token.text; | |
| 418 |
6/6✓ Branch 8 → 9 taken 51 times.
✓ Branch 8 → 11 taken 1 time.
✓ Branch 10 → 11 taken 21 times.
✓ Branch 10 → 12 taken 30 times.
✓ Branch 13 → 14 taken 22 times.
✓ Branch 13 → 29 taken 30 times.
|
52 | if (inQuotes || word.isEmpty()) { |
| 419 |
4/4✓ Branch 15 → 16 taken 22 times.
✓ Branch 17 → 18 taken 22 times.
✓ Branch 21 → 22 taken 22 times.
✓ Branch 22 → 23 taken 22 times.
|
44 | result.candidates << hintRow(QStringLiteral("task"), QString::fromUtf8(spec.syntax), QString::fromUtf8(spec.example)); |
| 420 | 22 | return result; | |
| 421 | } | ||
| 422 | 30 | const QChar sigil = word.at(0); | |
| 423 |
1/1✓ Branch 30 → 31 taken 30 times.
|
30 | const QString needle = word.mid(1); |
| 424 | 30 | QList<Candidate> rows; | |
| 425 |
5/6✓ Branch 34 → 35 taken 7 times.
✓ Branch 34 → 38 taken 23 times.
✓ Branch 36 → 37 taken 7 times.
✗ Branch 36 → 38 not taken.
✓ Branch 39 → 40 taken 7 times.
✓ Branch 39 → 94 taken 23 times.
|
30 | if (sigil == QLatin1Char('/') && sources.taskLists) { |
| 426 |
5/5✓ Branch 40 → 41 taken 7 times.
✓ Branch 41 → 42 taken 7 times.
✓ Branch 42 → 43 taken 7 times.
✓ Branch 91 → 44 taken 14 times.
✓ Branch 91 → 92 taken 7 times.
|
21 | for (const TaskListEntry &list : sources.taskLists()) { |
| 427 |
1/1✓ Branch 47 → 48 taken 14 times.
|
14 | const int tier = tierOf(list.name, QString{}, QString{}, needle); |
| 428 |
2/2✓ Branch 50 → 51 taken 7 times.
✓ Branch 50 → 52 taken 7 times.
|
14 | if (tier < 0) continue; |
| 429 |
1/1✓ Branch 52 → 53 taken 7 times.
|
7 | Candidate row; |
| 430 |
5/5✓ Branch 53 → 54 taken 2 times.
✓ Branch 53 → 57 taken 5 times.
✓ Branch 56 → 58 taken 2 times.
✓ Branch 60 → 61 taken 7 times.
✓ Branch 61 → 62 taken 7 times.
|
7 | row.insertText = QLatin1Char('/') + list.name + (list.ambiguous ? QLatin1Char('@') + list.account : QString{}); |
| 431 |
1/1✓ Branch 69 → 70 taken 7 times.
|
7 | row.key = QStringLiteral("token:list:") + row.insertText; |
| 432 | 7 | row.replaceStart = token.start; | |
| 433 | 7 | row.replaceEnd = token.end; | |
| 434 | 7 | row.appendSpace = true; | |
| 435 | 7 | row.title = list.name; | |
| 436 |
1/1✓ Branch 75 → 76 taken 7 times.
|
7 | row.titleMatches = matchRanges(list.name, needle); |
| 437 | 7 | row.secondary = list.account; | |
| 438 | 7 | row.rowType = QStringLiteral("value"); | |
| 439 | 7 | row.tier = tier; | |
| 440 |
1/1✓ Branch 85 → 86 taken 7 times.
|
7 | rows << row; |
| 441 | 14 | } | |
| 442 |
2/2✓ Branch 97 → 98 taken 13 times.
✓ Branch 97 → 107 taken 10 times.
|
23 | } else if (sigil == QLatin1Char('@')) { |
| 443 |
2/2✓ Branch 101 → 102 taken 13 times.
✓ Branch 102 → 103 taken 13 times.
|
13 | rows << dateWordRows(QStringLiteral("@"), needle, 0, token, sources); |
| 444 |
2/2✓ Branch 110 → 111 taken 6 times.
✓ Branch 110 → 170 taken 4 times.
|
10 | } else if (sigil == QLatin1Char('!')) { |
| 445 |
3/3✓ Branch 111 → 112 taken 6 times.
✓ Branch 168 → 114 taken 54 times.
✓ Branch 168 → 169 taken 6 times.
|
60 | for (const auto &priority : TaskConsoleInput::priorityWords()) { |
| 446 |
1/1✓ Branch 116 → 117 taken 54 times.
|
54 | const QString value = QString::fromLatin1(priority.word); |
| 447 |
7/7✓ Branch 117 → 118 taken 36 times.
✓ Branch 117 → 120 taken 18 times.
✓ Branch 118 → 119 taken 36 times.
✓ Branch 119 → 120 taken 31 times.
✓ Branch 119 → 121 taken 5 times.
✓ Branch 122 → 123 taken 49 times.
✓ Branch 122 → 124 taken 5 times.
|
54 | if (!priority.offered || !value.startsWith(needle, Qt::CaseInsensitive)) continue; |
| 448 |
1/1✓ Branch 124 → 125 taken 5 times.
|
5 | Candidate row; |
| 449 |
1/1✓ Branch 128 → 129 taken 5 times.
|
5 | row.key = QStringLiteral("token:priority:") + value; |
| 450 |
1/1✓ Branch 135 → 136 taken 5 times.
|
5 | row.insertText = QLatin1Char('!') + value; |
| 451 | 5 | row.replaceStart = token.start; | |
| 452 | 5 | row.replaceEnd = token.end; | |
| 453 | 5 | row.appendSpace = true; | |
| 454 | 5 | row.title = value; | |
| 455 |
1/1✓ Branch 139 → 140 taken 5 times.
|
5 | row.titleMatches = matchRanges(value, needle); |
| 456 |
2/8✓ Branch 142 → 143 taken 5 times.
✗ Branch 142 → 144 not taken.
✓ Branch 143 → 149 taken 5 times.
✗ Branch 144 → 145 not taken.
✗ Branch 144 → 146 not taken.
✗ Branch 145 → 149 not taken.
✗ Branch 147 → 149 not taken.
✗ Branch 148 → 149 not taken.
|
10 | row.detail = priority.level == 1 ? tr("High priority") : priority.level == 5 ? tr("Normal priority") |
| 457 |
0/2✗ Branch 146 → 147 not taken.
✗ Branch 146 → 148 not taken.
|
5 | : priority.level == 9 ? tr("Low priority") : tr("No priority"); |
| 458 | 5 | row.rowType = QStringLiteral("value"); | |
| 459 | 5 | row.tier = value.compare(needle, Qt::CaseInsensitive) == 0 ? 0 : 1; | |
| 460 |
1/1✓ Branch 158 → 159 taken 5 times.
|
5 | rows << row; |
| 461 | 54 | } | |
| 462 |
5/6✓ Branch 173 → 174 taken 1 time.
✓ Branch 173 → 177 taken 3 times.
✓ Branch 175 → 176 taken 1 time.
✗ Branch 175 → 177 not taken.
✓ Branch 178 → 179 taken 1 time.
✓ Branch 178 → 224 taken 3 times.
|
4 | } else if (sigil == QLatin1Char('#') && sources.tags) { |
| 463 |
5/5✓ Branch 179 → 180 taken 1 time.
✓ Branch 180 → 181 taken 1 time.
✓ Branch 181 → 182 taken 1 time.
✓ Branch 221 → 183 taken 2 times.
✓ Branch 221 → 222 taken 1 time.
|
3 | for (const QString &tag : sources.tags()) { |
| 464 |
1/1✓ Branch 186 → 187 taken 2 times.
|
2 | const int tier = tierOf(tag, QString{}, QString{}, needle); |
| 465 |
2/2✓ Branch 189 → 190 taken 1 time.
✓ Branch 189 → 191 taken 1 time.
|
2 | if (tier < 0) continue; |
| 466 |
1/1✓ Branch 191 → 192 taken 1 time.
|
1 | Candidate row; |
| 467 |
1/1✓ Branch 195 → 196 taken 1 time.
|
1 | row.key = QStringLiteral("token:tag:") + tag; |
| 468 |
1/1✓ Branch 202 → 203 taken 1 time.
|
1 | row.insertText = QLatin1Char('#') + tag; |
| 469 | 1 | row.replaceStart = token.start; | |
| 470 | 1 | row.replaceEnd = token.end; | |
| 471 | 1 | row.appendSpace = true; | |
| 472 | 1 | row.title = tag; | |
| 473 |
1/1✓ Branch 206 → 207 taken 1 time.
|
1 | row.titleMatches = matchRanges(tag, needle); |
| 474 | 1 | row.rowType = QStringLiteral("value"); | |
| 475 | 1 | row.tier = tier; | |
| 476 |
1/1✓ Branch 215 → 216 taken 1 time.
|
1 | rows << row; |
| 477 | 2 | } | |
| 478 | } | ||
| 479 |
1/1✓ Branch 225 → 226 taken 30 times.
|
30 | rank(rows, {}); |
| 480 | 30 | result.candidates = rows; | |
| 481 |
2/2✓ Branch 229 → 230 taken 5 times.
✓ Branch 229 → 245 taken 25 times.
|
30 | if (rows.isEmpty()) |
| 482 |
4/4✓ Branch 231 → 232 taken 5 times.
✓ Branch 233 → 234 taken 5 times.
✓ Branch 237 → 238 taken 5 times.
✓ Branch 238 → 239 taken 5 times.
|
10 | result.candidates << hintRow(QStringLiteral("task"), QString::fromUtf8(spec.syntax), QString::fromUtf8(spec.example)); |
| 483 | 30 | return result; | |
| 484 | 52 | } | |
| 485 | |||
| 486 | 7 | Result eventLine(const NamedCommandSpec &spec, const Token &token, const Sources &sources) { | |
| 487 | 7 | Result result; | |
| 488 |
1/1✓ Branch 3 → 4 taken 7 times.
|
7 | result.candidates = dateWordRows(QString{}, token.text, 2, token, sources); |
| 489 |
2/2✓ Branch 8 → 9 taken 6 times.
✓ Branch 8 → 24 taken 1 time.
|
7 | if (result.candidates.isEmpty()) |
| 490 |
4/4✓ Branch 10 → 11 taken 6 times.
✓ Branch 12 → 13 taken 6 times.
✓ Branch 16 → 17 taken 6 times.
✓ Branch 17 → 18 taken 6 times.
|
12 | result.candidates << hintRow(QStringLiteral("event"), QString::fromUtf8(spec.syntax), QString::fromUtf8(spec.example)); |
| 491 | 7 | return result; | |
| 492 | ✗ | } | |
| 493 | |||
| 494 | // Sprint 95's rule line: after the arrow the last word completes to a | ||
| 495 | // folder (the former rule-mode completer, now a provider, rule 10). | ||
| 496 | 17 | Result ruleLine(const NamedCommandSpec &spec, const QString &argument, const Token &token, const Sources &sources) { | |
| 497 | 17 | Result result; | |
| 498 |
5/20✓ Branch 5 → 6 taken 17 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 17 taken 17 times.
✗ Branch 10 → 11 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 17 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 17 times.
✓ Branch 27 → 28 taken 17 times.
✗ Branch 27 → 29 not taken.
✓ Branch 29 → 30 taken 17 times.
✗ Branch 29 → 31 not taken.
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 85 not taken.
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 89 not taken.
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
|
51 | const bool afterArrow = argument.contains(QStringLiteral("→")) || argument.contains(QStringLiteral("->")) || |
| 499 |
3/13✗ Branch 15 → 16 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 17 times.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 23 taken 17 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 17 times.
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 77 not taken.
✗ Branch 79 → 80 not taken.
✗ Branch 79 → 81 not taken.
|
17 | argument.contains(QStringLiteral("=>")); |
| 500 |
12/19✓ Branch 31 → 32 taken 17 times.
✗ Branch 31 → 44 not taken.
✓ Branch 33 → 34 taken 10 times.
✓ Branch 33 → 44 taken 7 times.
✓ Branch 36 → 37 taken 10 times.
✓ Branch 37 → 38 taken 10 times.
✗ Branch 37 → 44 not taken.
✓ Branch 42 → 43 taken 10 times.
✗ Branch 42 → 44 not taken.
✓ Branch 45 → 46 taken 10 times.
✓ Branch 45 → 47 taken 7 times.
✓ Branch 47 → 48 taken 10 times.
✓ Branch 47 → 49 taken 7 times.
✓ Branch 49 → 50 taken 10 times.
✓ Branch 49 → 56 taken 7 times.
✗ Branch 99 → 100 not taken.
✗ Branch 99 → 101 not taken.
✗ Branch 103 → 104 not taken.
✗ Branch 103 → 105 not taken.
|
27 | if (afterArrow && !token.text.isEmpty() && !token.text.contains(QLatin1Char('>')) && token.text != QStringLiteral("→")) |
| 501 |
1/1✓ Branch 51 → 52 taken 10 times.
|
10 | result.candidates = folderRows(QString{}, token.text, false, token, sources); |
| 502 |
2/2✓ Branch 57 → 58 taken 15 times.
✓ Branch 57 → 73 taken 2 times.
|
17 | if (result.candidates.isEmpty()) |
| 503 |
4/4✓ Branch 59 → 60 taken 15 times.
✓ Branch 61 → 62 taken 15 times.
✓ Branch 65 → 66 taken 15 times.
✓ Branch 66 → 67 taken 15 times.
|
30 | result.candidates << hintRow(QStringLiteral("rule"), QString::fromUtf8(spec.syntax), QString::fromUtf8(spec.example)); |
| 504 | 17 | return result; | |
| 505 | ✗ | } | |
| 506 | |||
| 507 | 3 | Candidate addressRow(const AddressEntry &address, const QString &needle, const Token &token) { | |
| 508 | 3 | Candidate row; | |
| 509 |
1/1✓ Branch 6 → 7 taken 3 times.
|
6 | row.key = QStringLiteral("address:") + address.address; |
| 510 | 3 | row.insertText = address.address; | |
| 511 | 3 | row.replaceStart = token.start; | |
| 512 | 3 | row.replaceEnd = token.end; | |
| 513 | 3 | row.title = address.address; | |
| 514 |
1/1✓ Branch 13 → 14 taken 3 times.
|
3 | row.titleMatches = matchRanges(address.address, needle); |
| 515 | 3 | row.secondary = address.name; | |
| 516 | 3 | row.detail = address.source; | |
| 517 | 3 | row.rowType = QStringLiteral("address"); | |
| 518 | 3 | return row; | |
| 519 | ✗ | } | |
| 520 | |||
| 521 | 157 | QList<Candidate> searchPrefixRows(const Token &token) { | |
| 522 | 157 | QList<Candidate> rows; | |
| 523 |
3/3✓ Branch 2 → 3 taken 157 times.
✓ Branch 55 → 5 taken 1727 times.
✓ Branch 55 → 56 taken 157 times.
|
1884 | for (const auto &prefix : SearchVocabulary::prefixes()) { |
| 524 |
3/3✓ Branch 8 → 9 taken 1727 times.
✓ Branch 10 → 11 taken 1727 times.
✓ Branch 11 → 12 taken 1727 times.
|
1727 | const int tier = tierOf(QString::fromLatin1(prefix.word), QString::fromUtf8(prefix.keywords), QString{}, token.text); |
| 525 |
3/4✓ Branch 15 → 16 taken 40 times.
✓ Branch 15 → 17 taken 1687 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 40 times.
|
1727 | if (tier < 0 || tier > 2) continue; |
| 526 |
1/1✓ Branch 18 → 19 taken 40 times.
|
40 | Candidate row; |
| 527 |
2/2✓ Branch 20 → 21 taken 40 times.
✓ Branch 24 → 25 taken 40 times.
|
80 | row.key = QStringLiteral("token:prefix:") + QString::fromLatin1(prefix.word); |
| 528 |
1/1✓ Branch 31 → 32 taken 40 times.
|
40 | row.insertText = QString::fromLatin1(prefix.word); |
| 529 | 40 | row.replaceStart = token.start; | |
| 530 | 40 | row.replaceEnd = token.end; | |
| 531 | 40 | row.title = row.insertText; | |
| 532 |
3/3✓ Branch 35 → 36 taken 39 times.
✓ Branch 35 → 37 taken 1 time.
✓ Branch 36 → 38 taken 39 times.
|
40 | row.titleMatches = tier == 1 ? matchRanges(row.title, token.text) : QList<QPair<int, int>>{}; |
| 533 |
1/1✓ Branch 40 → 41 taken 40 times.
|
40 | row.detail = SearchVocabulary::description(prefix); |
| 534 | 40 | row.rowType = QStringLiteral("value"); | |
| 535 | 40 | row.tier = tier; | |
| 536 |
1/1✓ Branch 49 → 50 taken 40 times.
|
40 | rows << row; |
| 537 | 40 | } | |
| 538 | 157 | return rows; | |
| 539 | ✗ | } | |
| 540 | |||
| 541 | 56 | QList<Candidate> searchValueRows(const QString &prefix, const QString &value, const Token &token, const Sources &sources) { | |
| 542 | 56 | QList<Candidate> rows; | |
| 543 |
3/3✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 7 taken 54 times.
✓ Branch 5 → 6 taken 2 times.
|
56 | if (prefix == QLatin1String("folder:")) return folderRows(prefix, value, false, token, sources); |
| 544 |
5/6✓ Branch 9 → 10 taken 39 times.
✓ Branch 9 → 13 taken 15 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 39 times.
✓ Branch 15 → 16 taken 15 times.
✓ Branch 15 → 40 taken 39 times.
|
54 | if (prefix == QLatin1String("from:") || prefix == QLatin1String("to:")) { |
| 545 |
5/6✓ Branch 17 → 18 taken 15 times.
✗ Branch 17 → 20 not taken.
✓ Branch 19 → 20 taken 4 times.
✓ Branch 19 → 21 taken 11 times.
✓ Branch 22 → 23 taken 4 times.
✓ Branch 22 → 24 taken 11 times.
|
15 | if (!sources.addresses || value.isEmpty()) return rows; |
| 546 |
5/5✓ Branch 24 → 25 taken 11 times.
✓ Branch 25 → 26 taken 11 times.
✓ Branch 26 → 27 taken 11 times.
✓ Branch 37 → 28 taken 2 times.
✓ Branch 37 → 38 taken 11 times.
|
13 | for (const AddressEntry &address : sources.addresses(value)) { |
| 547 |
1/1✓ Branch 29 → 30 taken 2 times.
|
2 | Candidate row = addressRow(address, value, token); |
| 548 |
1/1✓ Branch 30 → 31 taken 2 times.
|
2 | row.insertText = prefix + address.address; |
| 549 | 2 | row.appendSpace = true; | |
| 550 |
1/1✓ Branch 33 → 34 taken 2 times.
|
2 | rows << row; |
| 551 | 13 | } | |
| 552 | 11 | return rows; | |
| 553 | } | ||
| 554 |
5/5✓ Branch 40 → 41 taken 39 times.
✓ Branch 41 → 42 taken 39 times.
✓ Branch 42 → 43 taken 39 times.
✓ Branch 98 → 44 taken 226 times.
✓ Branch 98 → 99 taken 39 times.
|
265 | for (const auto &word : SearchVocabulary::valuesFor(prefix)) { |
| 555 |
3/3✓ Branch 47 → 48 taken 226 times.
✓ Branch 49 → 50 taken 226 times.
✓ Branch 50 → 51 taken 226 times.
|
226 | const int tier = tierOf(QString::fromLatin1(word.word), QString::fromUtf8(word.keywords), QString{}, value); |
| 556 |
4/4✓ Branch 54 → 55 taken 43 times.
✓ Branch 54 → 56 taken 183 times.
✓ Branch 55 → 56 taken 1 time.
✓ Branch 55 → 57 taken 42 times.
|
226 | if (tier < 0 || tier > 2) continue; |
| 557 |
1/1✓ Branch 57 → 58 taken 42 times.
|
42 | Candidate row; |
| 558 |
3/3✓ Branch 59 → 60 taken 42 times.
✓ Branch 63 → 64 taken 42 times.
✓ Branch 64 → 65 taken 42 times.
|
84 | row.key = QStringLiteral("token:") + prefix + QString::fromLatin1(word.word); |
| 559 |
2/2✓ Branch 72 → 73 taken 42 times.
✓ Branch 73 → 74 taken 42 times.
|
42 | row.insertText = prefix + QString::fromLatin1(word.word); |
| 560 | 42 | row.replaceStart = token.start; | |
| 561 | 42 | row.replaceEnd = token.end; | |
| 562 | 42 | row.appendSpace = true; | |
| 563 | 42 | row.title = row.insertText; | |
| 564 |
2/2✓ Branch 78 → 79 taken 42 times.
✓ Branch 79 → 80 taken 42 times.
|
42 | row.titleMatches = matchRanges(row.title, prefix + value); |
| 565 |
1/1✓ Branch 83 → 84 taken 42 times.
|
42 | row.detail = SearchVocabulary::description(word); |
| 566 | 42 | row.rowType = QStringLiteral("value"); | |
| 567 | 42 | row.tier = tier; | |
| 568 |
1/1✓ Branch 92 → 93 taken 42 times.
|
42 | rows << row; |
| 569 | 81 | } | |
| 570 | 39 | return rows; | |
| 571 | 56 | } | |
| 572 | |||
| 573 | 242 | Result searchQuery(const QString &argument, const Token &token, const Sources &sources) { | |
| 574 | 242 | Result result; | |
| 575 | 242 | QList<Candidate> rows; | |
| 576 | 242 | const int colon = token.text.indexOf(QLatin1Char(':')); | |
| 577 |
6/6✓ Branch 5 → 6 taken 56 times.
✓ Branch 5 → 16 taken 186 times.
✓ Branch 6 → 7 taken 56 times.
✓ Branch 7 → 8 taken 56 times.
✓ Branch 8 → 9 taken 56 times.
✓ Branch 9 → 10 taken 56 times.
|
242 | if (colon > 0) rows = searchValueRows(token.text.left(colon + 1).toLower(), token.text.mid(colon + 1), token, sources); |
| 578 |
3/3✓ Branch 17 → 18 taken 157 times.
✓ Branch 17 → 22 taken 29 times.
✓ Branch 18 → 19 taken 157 times.
|
186 | else if (!token.text.isEmpty()) rows = searchPrefixRows(token); |
| 579 |
3/3✓ Branch 22 → 23 taken 242 times.
✓ Branch 23 → 24 taken 242 times.
✓ Branch 24 → 25 taken 242 times.
|
246 | std::stable_sort(rows.begin(), rows.end(), [](const Candidate &a, const Candidate &b) { return a.tier < b.tier; }); |
| 580 | // Previews of the debounced lane follow the completions; they are | ||
| 581 | // results (↑↓ + Enter open them), never inserted by Tab. | ||
| 582 |
2/2✓ Branch 25 → 26 taken 242 times.
✓ Branch 29 → 30 taken 242 times.
|
484 | const bool areaSearch = argument.trimmed().startsWith(QStringLiteral("in:"), Qt::CaseInsensitive); |
| 583 |
11/13✓ Branch 34 → 35 taken 240 times.
✓ Branch 34 → 40 taken 2 times.
✓ Branch 35 → 36 taken 240 times.
✓ Branch 37 → 38 taken 213 times.
✓ Branch 37 → 40 taken 27 times.
✓ Branch 38 → 39 taken 210 times.
✓ Branch 38 → 40 taken 3 times.
✓ Branch 41 → 42 taken 240 times.
✓ Branch 41 → 43 taken 2 times.
✓ Branch 43 → 44 taken 210 times.
✓ Branch 43 → 117 taken 32 times.
✗ Branch 144 → 145 not taken.
✗ Branch 144 → 146 not taken.
|
242 | if (sources.results && !argument.trimmed().isEmpty() && !areaSearch) { |
| 584 |
5/5✓ Branch 44 → 45 taken 210 times.
✓ Branch 45 → 46 taken 210 times.
✓ Branch 46 → 47 taken 210 times.
✓ Branch 78 → 48 taken 134 times.
✓ Branch 78 → 79 taken 210 times.
|
344 | for (const ResultEntry &entry : sources.results(argument)) { |
| 585 |
1/1✓ Branch 49 → 50 taken 134 times.
|
134 | Candidate row; |
| 586 |
1/1✓ Branch 53 → 54 taken 134 times.
|
268 | row.key = QStringLiteral("result:") + entry.key; |
| 587 | 134 | row.kind = QStringLiteral("result"); | |
| 588 | 134 | row.title = entry.subject; | |
| 589 | 134 | row.secondary = entry.sender; | |
| 590 | 134 | row.detail = entry.folder; | |
| 591 | 134 | row.trailing = entry.date; | |
| 592 | 134 | row.rowType = QStringLiteral("result"); | |
| 593 |
1/1✓ Branch 74 → 75 taken 134 times.
|
134 | rows << row; |
| 594 | 344 | } | |
| 595 | // S101.6.7 (CB-07): the last preview row opens the whole search in a | ||
| 596 | // search tab; its second column says how. | ||
| 597 |
7/7✓ Branch 81 → 82 taken 100 times.
✓ Branch 81 → 87 taken 110 times.
✓ Branch 83 → 84 taken 100 times.
✓ Branch 85 → 86 taken 25 times.
✓ Branch 85 → 87 taken 75 times.
✓ Branch 88 → 89 taken 25 times.
✓ Branch 88 → 117 taken 185 times.
|
210 | if (!rows.isEmpty() && rows.last().kind == QLatin1String("result")) { |
| 598 |
1/1✓ Branch 89 → 90 taken 25 times.
|
25 | Candidate all; |
| 599 | 25 | all.key = QStringLiteral("result:all"); | |
| 600 | 25 | all.kind = QStringLiteral("result"); | |
| 601 |
1/1✓ Branch 102 → 103 taken 25 times.
|
25 | all.title = tr("Show all results"); |
| 602 |
1/1✓ Branch 105 → 106 taken 25 times.
|
25 | all.secondary = tr("Enter · Alt+Enter in a new tab"); |
| 603 | 25 | all.rowType = QStringLiteral("result"); | |
| 604 |
1/1✓ Branch 114 → 115 taken 25 times.
|
25 | rows << all; |
| 605 | 25 | } | |
| 606 | } | ||
| 607 |
1/3✗ Branch 118 → 119 not taken.
✓ Branch 118 → 120 taken 242 times.
✗ Branch 119 → 120 not taken.
|
242 | if (rows.size() > MaxCandidates) rows.resize(MaxCandidates); |
| 608 | 242 | result.candidates = rows; | |
| 609 | 242 | return result; | |
| 610 | 242 | } | |
| 611 | |||
| 612 | 1 | Result addressArgument(const Token &token, const Sources &sources) { | |
| 613 | 1 | Result result; | |
| 614 |
3/6✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 1 time.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 1 time.
|
1 | if (!sources.addresses || token.text.size() < 2) return result; |
| 615 |
7/7✓ Branch 10 → 11 taken 1 time.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 15 → 16 taken 1 time.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 20 → 14 taken 1 time.
✓ Branch 20 → 21 taken 1 time.
|
2 | for (const AddressEntry &address : sources.addresses(token.text)) result.candidates << addressRow(address, token.text, token); |
| 616 | 1 | return result; | |
| 617 | ✗ | } | |
| 618 | |||
| 619 | // Sprint 100 D-29: `settings <place>` — the whole argument is the needle | ||
| 620 | // (places have no spaces, keywords may); the row shows the label and | ||
| 621 | // "Page › Group", Tab inserts the place id. | ||
| 622 | ✗ | Result placeArgument(const QString &argument, int argumentStart, int end, const Sources &sources) { | |
| 623 | ✗ | Result result; | |
| 624 | ✗ | if (!sources.places) return result; | |
| 625 | ✗ | const QString needle = argument.trimmed(); | |
| 626 | ✗ | int index = 0; | |
| 627 | ✗ | for (const PlaceEntry &place : sources.places(needle)) { | |
| 628 | ✗ | Candidate row; | |
| 629 | ✗ | row.key = QStringLiteral("place:") + place.place; | |
| 630 | ✗ | row.insertText = place.place; | |
| 631 | ✗ | row.replaceStart = argumentStart; | |
| 632 | ✗ | row.replaceEnd = end; | |
| 633 | ✗ | row.title = place.label; | |
| 634 | ✗ | row.titleMatches = matchRanges(place.label, needle); | |
| 635 | ✗ | row.secondary = place.path; | |
| 636 | ✗ | row.detail = tr("Open the settings here"); | |
| 637 | ✗ | row.rowType = QStringLiteral("place"); | |
| 638 | ✗ | row.tier = index++; | |
| 639 | ✗ | result.candidates << row; | |
| 640 | ✗ | } | |
| 641 | // D-6: a place is pre-highlighted once something is typed. | ||
| 642 | ✗ | if (!needle.isEmpty() && !result.candidates.isEmpty()) result.preselectKey = result.candidates.first().key; | |
| 643 | ✗ | return result; | |
| 644 | ✗ | } | |
| 645 | |||
| 646 | // Sprint 100 D-29: `account password|remove|switch <account>` — addresses, | ||
| 647 | // the active account first. Never stored (D-9). | ||
| 648 | ✗ | Result accountArgument(const Token &token, int start, int end, const Sources &sources) { | |
| 649 | ✗ | Result result; | |
| 650 | ✗ | if (!sources.accounts) return result; | |
| 651 | ✗ | const QString needle = token.text.trimmed(); | |
| 652 | ✗ | QList<AccountEntry> accounts = sources.accounts(); | |
| 653 | ✗ | std::stable_sort(accounts.begin(), accounts.end(), [](const AccountEntry &a, const AccountEntry &b) { | |
| 654 | ✗ | if (a.active != b.active) return a.active; | |
| 655 | ✗ | return a.address.compare(b.address, Qt::CaseInsensitive) < 0; | |
| 656 | }); | ||
| 657 | ✗ | for (const AccountEntry &account : accounts) { | |
| 658 | ✗ | if (!needle.isEmpty() && !account.address.contains(needle, Qt::CaseInsensitive) && | |
| 659 | ✗ | !account.name.contains(needle, Qt::CaseInsensitive)) | |
| 660 | ✗ | continue; | |
| 661 | ✗ | Candidate row; | |
| 662 | ✗ | row.key = QStringLiteral("account:") + account.address; | |
| 663 | ✗ | row.insertText = account.address; | |
| 664 | ✗ | row.replaceStart = start; | |
| 665 | ✗ | row.replaceEnd = end; | |
| 666 | ✗ | row.title = account.address; | |
| 667 | ✗ | row.titleMatches = matchRanges(account.address, needle); | |
| 668 | ✗ | row.secondary = account.name; | |
| 669 | ✗ | row.trailing = account.active ? tr("Active") : QString{}; | |
| 670 | ✗ | row.rowType = QStringLiteral("address"); | |
| 671 | ✗ | row.tier = account.active ? 0 : 1; | |
| 672 | ✗ | result.candidates << row; | |
| 673 | ✗ | } | |
| 674 | ✗ | if (!needle.isEmpty() && !result.candidates.isEmpty()) result.preselectKey = result.candidates.first().key; | |
| 675 | ✗ | return result; | |
| 676 | ✗ | } | |
| 677 | |||
| 678 | // D-15a: after "filter unread " or "mark read " the values that still go | ||
| 679 | // with the chosen ones; none once a word that is no value was typed | ||
| 680 | // ("filter invoice "). | ||
| 681 | 15 | Result nextValues(const NamedCommandSpec &spec, const QString &text, int argumentStart, const Token &token, | |
| 682 | const Sources &sources) { | ||
| 683 |
1/1✓ Branch 2 → 3 taken 15 times.
|
15 | const QString before = text.mid(argumentStart, token.start - argumentStart); |
| 684 |
3/3✓ Branch 5 → 6 taken 15 times.
✓ Branch 6 → 7 taken 15 times.
✓ Branch 7 → 8 taken 15 times.
|
15 | const auto parsed = NamedCommandCatalog::parse(spec.name + QLatin1Char(' ') + before); |
| 685 |
3/3✓ Branch 10 → 11 taken 15 times.
✓ Branch 13 → 14 taken 4 times.
✓ Branch 13 → 15 taken 11 times.
|
15 | if (!parsed.rest().isEmpty()) return {}; |
| 686 |
1/1✓ Branch 15 → 16 taken 11 times.
|
11 | const auto chosen = parsed.values(); |
| 687 |
1/1✓ Branch 16 → 17 taken 11 times.
|
11 | Result result = valueArgument(spec, text, token, sources); |
| 688 |
1/1✓ Branch 17 → 18 taken 11 times.
|
11 | result.candidates.removeIf([&](const Candidate &row) { |
| 689 | 26 | const auto *value = spec.value(row.insertText); | |
| 690 |
7/13✓ Branch 3 → 4 taken 26 times.
✗ Branch 3 → 10 not taken.
✓ Branch 4 → 5 taken 26 times.
✓ Branch 5 → 6 taken 26 times.
✓ Branch 6 → 7 taken 26 times.
✓ Branch 7 → 8 taken 14 times.
✓ Branch 7 → 10 taken 12 times.
✓ Branch 14 → 15 taken 26 times.
✗ Branch 14 → 16 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
|
66 | return !value || !NamedCommandCatalog::combinable(chosen + QList<const NamedCommandValue *>{value}, false) || |
| 691 |
5/6✓ Branch 8 → 9 taken 7 times.
✓ Branch 8 → 11 taken 7 times.
✓ Branch 9 → 10 taken 2 times.
✓ Branch 9 → 11 taken 5 times.
✓ Branch 12 → 13 taken 26 times.
✗ Branch 12 → 14 not taken.
|
66 | (spec.freeText && row.tier > 2); |
| 692 | }); | ||
| 693 | 11 | return result; | |
| 694 | 15 | } | |
| 695 | |||
| 696 | // Everything after "<command> ": the provider of the argument kind (§5.2). | ||
| 697 | 715 | Result argument(const NamedCommandSpec &spec, const QString &text, int cursor, int argumentStart, | |
| 698 | const Sources &sources) { | ||
| 699 |
1/1✓ Branch 2 → 3 taken 715 times.
|
715 | const QString argument = text.mid(argumentStart, cursor - argumentStart); |
| 700 |
1/1✓ Branch 3 → 4 taken 715 times.
|
715 | const Token token = tokenAt(text, cursor); |
| 701 |
2/2✓ Branch 7 → 8 taken 715 times.
✓ Branch 8 → 9 taken 715 times.
|
715 | const auto *value = spec.value(argument.section(QLatin1Char(' '), 0, 0)); |
| 702 |
1/1✓ Branch 12 → 13 taken 715 times.
|
715 | const bool inFirstWord = !argument.contains(QLatin1Char(' ')); |
| 703 | // F100-74: "filter <words>" also takes any text; a hint row says so, and | ||
| 704 | // values only show for their word or keywords ("mess" is no value). | ||
| 705 | 103 | const auto wordsHint = [&spec] { | |
| 706 |
2/2✓ Branch 4 → 5 taken 103 times.
✓ Branch 8 → 9 taken 103 times.
|
309 | return hintRow(spec.name + QStringLiteral(":text"), tr("words — subject or sender contains them"), |
| 707 |
2/2✓ Branch 3 → 4 taken 103 times.
✓ Branch 9 → 10 taken 103 times.
|
309 | QString::fromUtf8(spec.example)); |
| 708 | 715 | }; | |
| 709 |
8/8✓ Branch 14 → 15 taken 204 times.
✓ Branch 14 → 19 taken 511 times.
✓ Branch 15 → 16 taken 173 times.
✓ Branch 15 → 19 taken 31 times.
✓ Branch 16 → 17 taken 166 times.
✓ Branch 16 → 19 taken 7 times.
✓ Branch 20 → 21 taken 166 times.
✓ Branch 20 → 31 taken 549 times.
|
881 | if (!spec.values.isEmpty() && inFirstWord && spec.argument != CommandArgument::Label && |
| 710 |
1/2✓ Branch 17 → 18 taken 166 times.
✗ Branch 17 → 19 not taken.
|
166 | spec.argument != CommandArgument::Folder) { |
| 711 |
1/3✓ Branch 21 → 22 taken 166 times.
✗ Branch 235 → 236 not taken.
✗ Branch 235 → 237 not taken.
|
166 | Result values = valueArgument(spec, text, token, sources); |
| 712 |
2/2✓ Branch 22 → 23 taken 93 times.
✓ Branch 22 → 28 taken 73 times.
|
166 | if (spec.freeText) { |
| 713 |
1/1✓ Branch 23 → 24 taken 93 times.
|
309 | values.candidates.removeIf([](const Candidate &row) { return row.tier > 2; }); |
| 714 |
2/2✓ Branch 24 → 25 taken 93 times.
✓ Branch 25 → 26 taken 93 times.
|
93 | values.candidates << wordsHint(); |
| 715 | } | ||
| 716 |
1/2✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 166 times.
|
166 | return values; |
| 717 | ✗ | } | |
| 718 |
4/4✓ Branch 31 → 32 taken 56 times.
✓ Branch 31 → 43 taken 493 times.
✓ Branch 32 → 33 taken 15 times.
✓ Branch 32 → 43 taken 41 times.
|
549 | if (spec.several && spec.argument == CommandArgument::Values) { |
| 719 |
1/1✓ Branch 33 → 34 taken 15 times.
|
15 | Result next = nextValues(spec, text, argumentStart, token, sources); |
| 720 |
4/4✓ Branch 34 → 35 taken 10 times.
✓ Branch 34 → 39 taken 5 times.
✓ Branch 35 → 36 taken 10 times.
✓ Branch 36 → 37 taken 10 times.
|
15 | if (spec.freeText) next.candidates << wordsHint(); |
| 721 | 15 | return next; | |
| 722 | 15 | } | |
| 723 |
1/6✗ Branch 43 → 44 not taken.
✓ Branch 43 → 52 taken 534 times.
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 52 not taken.
✗ Branch 45 → 46 not taken.
✗ Branch 46 → 47 not taken.
|
534 | if (spec.freeText && !value) { Result words; words.candidates << wordsHint(); return words; } |
| 724 |
4/4✓ Branch 52 → 53 taken 15 times.
✓ Branch 52 → 111 taken 519 times.
✓ Branch 53 → 54 taken 14 times.
✓ Branch 53 → 111 taken 1 time.
|
534 | if (value && !inFirstWord) { |
| 725 | // "folder move <parent>", "folder rename <name>": the value's argument. | ||
| 726 | 14 | const int restStart = argumentStart + int(argument.indexOf(QLatin1Char(' '))) + 1; | |
| 727 |
2/2✓ Branch 57 → 58 taken 13 times.
✓ Branch 57 → 64 taken 1 time.
|
14 | if (value->then == CommandArgument::Folder) |
| 728 |
2/2✓ Branch 59 → 60 taken 13 times.
✓ Branch 60 → 61 taken 13 times.
|
13 | return folderArgument(spec, text.mid(restStart, cursor - restStart), restStart, int(text.size()), false, sources); |
| 729 |
1/2✗ Branch 64 → 65 not taken.
✓ Branch 64 → 90 taken 1 time.
|
1 | if (value->then == CommandArgument::Account) { |
| 730 | ✗ | Result accounts = accountArgument(tokenAt(text, cursor), restStart, int(text.size()), sources); | |
| 731 | ✗ | if (value->thenRequired && text.mid(restStart).trimmed().isEmpty()) accounts.hint = QString::fromUtf8(value->thenSyntax); | |
| 732 | ✗ | return accounts; | |
| 733 | ✗ | } | |
| 734 | 1 | Result hint; | |
| 735 |
7/17✓ Branch 90 → 91 taken 1 time.
✗ Branch 90 → 96 not taken.
✓ Branch 91 → 92 taken 1 time.
✓ Branch 92 → 93 taken 1 time.
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 1 time.
✓ Branch 97 → 98 taken 1 time.
✗ Branch 97 → 99 not taken.
✓ Branch 99 → 100 taken 1 time.
✗ Branch 99 → 101 not taken.
✗ Branch 101 → 102 not taken.
✓ Branch 101 → 107 taken 1 time.
✗ Branch 103 → 104 not taken.
✗ Branch 269 → 270 not taken.
✗ Branch 269 → 271 not taken.
✗ Branch 273 → 274 not taken.
✗ Branch 273 → 275 not taken.
|
1 | if (value->thenRequired && text.mid(restStart).trimmed().isEmpty()) hint.hint = QString::fromUtf8(value->thenSyntax); |
| 736 | 1 | return hint; | |
| 737 | 1 | } | |
| 738 |
8/13✓ Branch 111 → 112 taken 122 times.
✓ Branch 111 → 118 taken 41 times.
✓ Branch 111 → 128 taken 52 times.
✓ Branch 111 → 130 taken 7 times.
✓ Branch 111 → 132 taken 17 times.
✓ Branch 111 → 134 taken 242 times.
✓ Branch 111 → 192 taken 1 time.
✗ Branch 111 → 194 not taken.
✗ Branch 111 → 196 not taken.
✗ Branch 111 → 199 not taken.
✓ Branch 111 → 202 taken 38 times.
✗ Branch 111 → 218 not taken.
✗ Branch 111 → 219 not taken.
|
520 | switch (spec.argument) { |
| 739 | 122 | case CommandArgument::Folder: | |
| 740 |
1/1✓ Branch 115 → 116 taken 122 times.
|
122 | return folderArgument(spec, argument, argumentStart, int(text.size()), spec.name == QLatin1String("move"), sources); |
| 741 | 41 | case CommandArgument::Label: { | |
| 742 |
1/1✓ Branch 118 → 119 taken 41 times.
|
41 | const QString before = text.mid(argumentStart, token.start - argumentStart); |
| 743 |
2/2✓ Branch 122 → 123 taken 41 times.
✓ Branch 123 → 124 taken 41 times.
|
41 | return labelArgument(spec, token, before.split(QLatin1Char(' '), Qt::SkipEmptyParts), sources); |
| 744 | 41 | } | |
| 745 |
1/1✓ Branch 128 → 129 taken 52 times.
|
52 | case CommandArgument::TaskLine: return taskLine(spec, text, token, sources); |
| 746 |
1/1✓ Branch 130 → 131 taken 7 times.
|
7 | case CommandArgument::EventLine: return eventLine(spec, token, sources); |
| 747 |
1/1✓ Branch 132 → 133 taken 17 times.
|
17 | case CommandArgument::RuleLine: return ruleLine(spec, argument, token, sources); |
| 748 | 242 | case CommandArgument::Query: { | |
| 749 |
2/2✓ Branch 134 → 135 taken 242 times.
✓ Branch 135 → 136 taken 242 times.
|
242 | Result search = searchQuery(text.mid(argumentStart), token, sources); |
| 750 | // F100-75: the syntax and the operators stay visible after "search "; | ||
| 751 | // hint rows (never inserted or run), so no grey text pretends a choice. | ||
| 752 |
3/3✓ Branch 137 → 138 taken 242 times.
✓ Branch 140 → 141 taken 29 times.
✓ Branch 140 → 188 taken 213 times.
|
242 | if (argument.trimmed().isEmpty()) { |
| 753 |
4/6✓ Branch 142 → 143 taken 29 times.
✓ Branch 144 → 145 taken 29 times.
✓ Branch 148 → 149 taken 29 times.
✓ Branch 148 → 150 taken 29 times.
✗ Branch 297 → 298 not taken.
✗ Branch 297 → 299 not taken.
|
87 | QList<Candidate> help{hintRow(spec.name, QString::fromUtf8(spec.syntax), QString::fromUtf8(spec.example))}; |
| 754 |
3/3✓ Branch 152 → 153 taken 29 times.
✓ Branch 182 → 155 taken 319 times.
✓ Branch 182 → 183 taken 29 times.
|
348 | for (const auto &prefix : SearchVocabulary::prefixes()) { |
| 755 |
1/2✗ Branch 157 → 158 not taken.
✓ Branch 157 → 159 taken 319 times.
|
319 | if (help.size() >= MaxCandidates) break; |
| 756 |
2/2✓ Branch 163 → 164 taken 319 times.
✓ Branch 167 → 168 taken 319 times.
|
957 | Candidate row = hintRow(QStringLiteral("operator:") + QString::fromLatin1(prefix.word), |
| 757 |
2/2✓ Branch 161 → 162 taken 319 times.
✓ Branch 168 → 169 taken 319 times.
|
957 | QString::fromLatin1(prefix.word), QString{}); |
| 758 |
1/1✓ Branch 175 → 176 taken 319 times.
|
319 | row.detail = SearchVocabulary::description(prefix); |
| 759 |
1/1✓ Branch 178 → 179 taken 319 times.
|
319 | help << row; |
| 760 | 319 | } | |
| 761 |
1/1✓ Branch 183 → 184 taken 29 times.
|
29 | search.candidates = help + search.candidates; |
| 762 | 29 | } | |
| 763 | 242 | return search; | |
| 764 | 242 | } | |
| 765 |
1/1✓ Branch 192 → 193 taken 1 time.
|
1 | case CommandArgument::Address: return addressArgument(token, sources); |
| 766 | ✗ | case CommandArgument::Date: return valueArgument(spec, text, token, sources); | |
| 767 | ✗ | case CommandArgument::Place: return placeArgument(argument, argumentStart, int(text.size()), sources); | |
| 768 | ✗ | case CommandArgument::Account: return accountArgument(token, argumentStart, int(text.size()), sources); | |
| 769 | 38 | case CommandArgument::ContactLine: | |
| 770 | case CommandArgument::Text: { | ||
| 771 | 38 | Result hint; | |
| 772 |
2/2✓ Branch 203 → 204 taken 1 time.
✓ Branch 203 → 214 taken 37 times.
|
38 | if (argument.isEmpty()) |
| 773 |
4/4✓ Branch 205 → 206 taken 1 time.
✓ Branch 207 → 208 taken 1 time.
✓ Branch 208 → 209 taken 1 time.
✓ Branch 209 → 210 taken 1 time.
|
1 | hint.candidates << hintRow(spec.name, QString::fromUtf8(spec.syntax), QString::fromUtf8(spec.example)); |
| 774 | 38 | return hint; | |
| 775 | 38 | } | |
| 776 | ✗ | case CommandArgument::Values: | |
| 777 | ✗ | case CommandArgument::None: break; | |
| 778 | } | ||
| 779 | ✗ | return {}; | |
| 780 | 773 | } | |
| 781 | |||
| 782 | // Ghost text (D-5): what Tab inserts — the pre-highlighted row, else the | ||
| 783 | // first completion. Inline when it continues the typed word, else arrow. | ||
| 784 | 1238 | void setGhost(Result &result, const QString &text, int cursor) { | |
| 785 | // No ghost over the placeholder of the empty state. | ||
| 786 |
9/11✓ Branch 3 → 4 taken 1237 times.
✓ Branch 3 → 7 taken 1 time.
✓ Branch 4 → 5 taken 1237 times.
✓ Branch 6 → 7 taken 281 times.
✓ Branch 6 → 8 taken 956 times.
✓ Branch 9 → 10 taken 1237 times.
✓ Branch 9 → 11 taken 1 time.
✓ Branch 11 → 12 taken 282 times.
✓ Branch 11 → 13 taken 956 times.
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 102 not taken.
|
1560 | if (cursor != text.size() || text.trimmed().isEmpty()) return; |
| 787 | 956 | const Candidate *target = nullptr; | |
| 788 |
4/4✓ Branch 13 → 14 taken 956 times.
✓ Branch 14 → 15 taken 956 times.
✓ Branch 32 → 16 taken 1219 times.
✓ Branch 32 → 33 taken 322 times.
|
1541 | for (const auto &row : result.candidates) { |
| 789 |
2/2✓ Branch 19 → 20 taken 585 times.
✓ Branch 19 → 21 taken 634 times.
|
1219 | if (row.kind != QLatin1String("completion")) continue; |
| 790 |
4/6✓ Branch 22 → 23 taken 76 times.
✓ Branch 22 → 26 taken 558 times.
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 76 times.
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 634 times.
|
634 | if (!result.preselectKey.isEmpty() && row.key != result.preselectKey) continue; |
| 791 | 634 | target = &row; | |
| 792 | 634 | break; | |
| 793 | } | ||
| 794 |
2/2✓ Branch 33 → 34 taken 322 times.
✓ Branch 33 → 52 taken 634 times.
|
956 | if (!target) { |
| 795 |
2/7✗ Branch 35 → 36 not taken.
✓ Branch 35 → 41 taken 322 times.
✗ Branch 38 → 39 not taken.
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 51 taken 322 times.
|
322 | if (!result.hint.isEmpty() && text.endsWith(QLatin1Char(' '))) { |
| 796 | ✗ | result.ghost = result.hint; | |
| 797 | ✗ | result.ghostForm = QStringLiteral("hint"); | |
| 798 | } | ||
| 799 | 322 | return; | |
| 800 | } | ||
| 801 |
1/1✓ Branch 52 → 53 taken 634 times.
|
634 | const QString typed = text.mid(target->replaceStart, cursor - target->replaceStart); |
| 802 |
3/3✓ Branch 53 → 54 taken 634 times.
✓ Branch 54 → 55 taken 531 times.
✓ Branch 54 → 88 taken 103 times.
|
634 | if (target->insertText.startsWith(typed, Qt::CaseInsensitive)) { |
| 803 |
1/1✓ Branch 56 → 57 taken 531 times.
|
531 | result.ghost = target->insertText.mid(typed.size()); |
| 804 |
4/4✓ Branch 60 → 61 taken 235 times.
✓ Branch 60 → 62 taken 296 times.
✓ Branch 67 → 68 taken 296 times.
✓ Branch 67 → 69 taken 235 times.
|
827 | result.ghostForm = result.ghost.isEmpty() ? QString{} : QStringLiteral("inline"); |
| 805 |
6/6✓ Branch 70 → 71 taken 235 times.
✓ Branch 70 → 74 taken 296 times.
✓ Branch 72 → 73 taken 57 times.
✓ Branch 72 → 74 taken 178 times.
✓ Branch 75 → 76 taken 57 times.
✓ Branch 75 → 96 taken 474 times.
|
531 | if (result.ghost.isEmpty() && !target->argumentHint.isEmpty()) { |
| 806 |
1/1✓ Branch 78 → 79 taken 57 times.
|
57 | result.ghost = QLatin1Char(' ') + target->argumentHint; |
| 807 | 57 | result.ghostForm = QStringLiteral("hint"); | |
| 808 | } | ||
| 809 | } else { | ||
| 810 | 103 | result.ghost = target->insertText; | |
| 811 | 103 | result.ghostForm = QStringLiteral("arrow"); | |
| 812 | } | ||
| 813 | 634 | } | |
| 814 | |||
| 815 | } // namespace | ||
| 816 | |||
| 817 | 4360 | QString availabilityReason(const NamedCommandSpec &spec, const QString &line, const Sources &sources) { | |
| 818 |
2/2✓ Branch 3 → 4 taken 160 times.
✓ Branch 3 → 5 taken 4200 times.
|
4360 | if (!spec.contexts.testFlag(sources.context)) return tr("Not available here"); |
| 819 | // D-8: the design preview has no backend; every command of the context counts as available. | ||
| 820 |
2/2✓ Branch 5 → 6 taken 479 times.
✓ Branch 5 → 7 taken 3721 times.
|
4200 | if (sources.designPreview) return {}; |
| 821 |
3/6✓ Branch 8 → 9 taken 3721 times.
✗ Branch 8 → 12 not taken.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 3721 times.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 3721 times.
|
3721 | if (sources.connected && !sources.connected(spec.name)) return tr("Not available here"); |
| 822 |
1/2✓ Branch 16 → 17 taken 3721 times.
✗ Branch 16 → 18 not taken.
|
3721 | return sources.unavailableReason ? sources.unavailableReason(line) : QString{}; |
| 823 | } | ||
| 824 | |||
| 825 | 3362 | QVariantMap Candidate::toMap() const { | |
| 826 | 3362 | QVariantList matches; | |
| 827 | // QVariant(...) keeps each range one element (append(QVariantList) would splice it). | ||
| 828 |
5/7✓ Branch 9 → 10 taken 505 times.
✓ Branch 13 → 14 taken 1010 times.
✓ Branch 13 → 15 taken 505 times.
✓ Branch 17 → 4 taken 505 times.
✓ Branch 17 → 18 taken 3362 times.
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 51 not taken.
|
4877 | for (const auto &range : titleMatches) matches.append(QVariant(QVariantList{range.first, range.second})); |
| 829 | 13448 | return {{"key", key}, {"kind", kind}, {"insertText", insertText}, {"replaceStart", replaceStart}, | |
| 830 | 10086 | {"replaceEnd", replaceEnd}, {"appendSpace", appendSpace}, {"title", title}, {"titleMatches", matches}, | |
| 831 | 13448 | {"argumentHint", argumentHint}, {"detail", detail}, {"shortcut", shortcut}, {"available", available}, | |
| 832 | 13448 | {"reason", reason}, {"group", group}, {"rowType", rowType}, {"secondary", secondary}, | |
| 833 |
2/4✓ Branch 39 → 40 taken 63878 times.
✓ Branch 39 → 41 taken 3362 times.
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 64 not taken.
|
70602 | {"trailing", trailing}, {"state", state}, {"destructive", destructive}}; |
| 834 | 7229 | } | |
| 835 | |||
| 836 | 1065 | QVariantMap Result::toMap() const { | |
| 837 | 1065 | QVariantList rows; | |
| 838 |
4/4✓ Branch 5 → 6 taken 3361 times.
✓ Branch 7 → 8 taken 3361 times.
✓ Branch 12 → 4 taken 3361 times.
✓ Branch 12 → 13 taken 1065 times.
|
4426 | for (const auto &candidate : candidates) rows.append(candidate.toMap()); |
| 839 | 3195 | return {{"candidates", rows}, {"preselectKey", preselectKey}, {"ghost", ghost}, {"ghostForm", ghostForm}, | |
| 840 |
2/4✓ Branch 22 → 23 taken 7455 times.
✓ Branch 22 → 24 taken 1065 times.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
|
9585 | {"command", command}, {"hint", hint}, {"preview", preview}}; |
| 841 | 2130 | } | |
| 842 | |||
| 843 | 1238 | Result complete(const QString &input, int cursor, const Sources &sources) { | |
| 844 |
1/1✓ Branch 2 → 3 taken 1238 times.
|
1238 | const QString text = input.left(MaxInput); |
| 845 | 1238 | cursor = std::clamp(cursor, 0, int(text.size())); | |
| 846 | 1238 | Result result; | |
| 847 |
3/3✓ Branch 5 → 6 taken 1238 times.
✓ Branch 8 → 9 taken 281 times.
✓ Branch 8 → 13 taken 957 times.
|
1238 | if (text.trimmed().isEmpty()) { |
| 848 |
1/1✓ Branch 9 → 10 taken 281 times.
|
281 | result = emptyState(sources); |
| 849 | } else { | ||
| 850 | 957 | int nameStart = 0; | |
| 851 |
3/6✓ Branch 16 → 17 taken 957 times.
✗ Branch 16 → 21 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 957 times.
✗ Branch 22 → 14 not taken.
✓ Branch 22 → 23 taken 957 times.
|
957 | while (nameStart < text.size() && text.at(nameStart).isSpace()) ++nameStart; |
| 852 | 957 | const int space = text.indexOf(QLatin1Char(' '), nameStart); | |
| 853 |
4/4✓ Branch 26 → 27 taken 717 times.
✓ Branch 26 → 28 taken 240 times.
✓ Branch 27 → 28 taken 1 time.
✓ Branch 27 → 34 taken 716 times.
|
957 | if (space < 0 || cursor <= space) { |
| 854 |
2/2✓ Branch 28 → 29 taken 241 times.
✓ Branch 29 → 30 taken 241 times.
|
241 | result = commandNames(text, tokenAt(text, cursor), sources); |
| 855 |
4/4✓ Branch 34 → 35 taken 716 times.
✓ Branch 35 → 36 taken 716 times.
✓ Branch 37 → 38 taken 715 times.
✓ Branch 37 → 89 taken 1 time.
|
716 | } else if (const auto *spec = NamedCommandCatalog::find(text.mid(nameStart, space - nameStart))) { |
| 856 |
1/1✓ Branch 38 → 39 taken 715 times.
|
715 | result = argument(*spec, text, cursor, space + 1, sources); |
| 857 | 715 | result.command = spec->name; | |
| 858 | // Trailing space kept: it tells a finished token from one being typed. | ||
| 859 |
1/1✓ Branch 42 → 43 taken 715 times.
|
715 | QString line = text.mid(space + 1); |
| 860 |
8/8✓ Branch 44 → 45 taken 1 time.
✓ Branch 46 → 47 taken 591 times.
✓ Branch 46 → 51 taken 125 times.
✓ Branch 47 → 48 taken 591 times.
✓ Branch 49 → 50 taken 1 time.
✓ Branch 49 → 51 taken 590 times.
✓ Branch 52 → 44 taken 1 time.
✓ Branch 52 → 53 taken 715 times.
|
716 | while (!line.isEmpty() && line.front().isSpace()) line.remove(0, 1); |
| 861 |
10/12✓ Branch 54 → 55 taken 574 times.
✓ Branch 54 → 59 taken 141 times.
✓ Branch 55 → 56 taken 574 times.
✓ Branch 57 → 58 taken 467 times.
✓ Branch 57 → 59 taken 107 times.
✓ Branch 60 → 61 taken 574 times.
✓ Branch 60 → 62 taken 141 times.
✓ Branch 62 → 63 taken 467 times.
✓ Branch 62 → 67 taken 248 times.
✓ Branch 63 → 64 taken 467 times.
✗ Branch 121 → 122 not taken.
✗ Branch 121 → 123 not taken.
|
715 | if (sources.linePreview && !line.trimmed().isEmpty()) result.preview = sources.linePreview(spec->name, line); |
| 862 |
13/18✓ Branch 68 → 69 taken 715 times.
✗ Branch 68 → 76 not taken.
✓ Branch 70 → 71 taken 214 times.
✓ Branch 70 → 76 taken 501 times.
✓ Branch 71 → 72 taken 214 times.
✓ Branch 72 → 73 taken 214 times.
✓ Branch 74 → 75 taken 45 times.
✓ Branch 74 → 76 taken 169 times.
✓ Branch 77 → 78 taken 214 times.
✓ Branch 77 → 79 taken 501 times.
✓ Branch 79 → 80 taken 214 times.
✓ Branch 79 → 81 taken 501 times.
✓ Branch 81 → 82 taken 45 times.
✓ Branch 81 → 87 taken 670 times.
✗ Branch 126 → 127 not taken.
✗ Branch 126 → 128 not taken.
✗ Branch 130 → 131 not taken.
✗ Branch 130 → 132 not taken.
|
715 | if (result.hint.isEmpty() && spec->requiresArgument() && text.mid(space + 1).trimmed().isEmpty()) |
| 863 |
1/1✓ Branch 83 → 84 taken 45 times.
|
45 | result.hint = QString::fromUtf8(spec->syntax); |
| 864 | 715 | } | |
| 865 | } | ||
| 866 |
1/1✓ Branch 89 → 90 taken 1238 times.
|
1238 | setGhost(result, text, cursor); |
| 867 |
9/9✓ Branch 90 → 91 taken 1238 times.
✓ Branch 94 → 95 taken 1238 times.
✓ Branch 95 → 96 taken 1238 times.
✓ Branch 96 → 97 taken 1238 times.
✓ Branch 98 → 99 taken 1238 times.
✓ Branch 99 → 100 taken 1238 times.
✓ Branch 101 → 102 taken 1238 times.
✓ Branch 107 → 92 taken 1238 times.
✓ Branch 107 → 108 taken 1238 times.
|
2476 | qCDebug(lcCommandBar) << "completion" << "length" << text.size() << "candidates" << result.candidates.size() |
| 868 |
2/2✓ Branch 102 → 103 taken 1238 times.
✓ Branch 103 → 104 taken 1238 times.
|
1238 | << "ghost" << result.ghostForm; |
| 869 | 1238 | return result; | |
| 870 | 1238 | } | |
| 871 | |||
| 872 | } // namespace CommandCompletion | ||
| 873 |