Skip to content

Commit 4a9969e

Browse files
feat: add Tags property to Suggestion and update Npm suggestions provider to include package version
1 parent 89623ab commit 4a9969e

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

CmdPalWebSearchShortcut/WebSearchShortcut/Pages/SearchWebPage.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ private async Task<ListItem[]> FetchSuggestionItemsAsync(string searchText, Canc
189189
.GetSuggestionsAsync(searchText, cancellationToken)
190190
.ConfigureAwait(false);
191191

192+
#pragma warning disable CS8601 // Possible null reference assignment.
192193
return
193194
[
194195
.. suggestions.Select(suggestion => new ListItem(
@@ -202,8 +203,10 @@ private async Task<ListItem[]> FetchSuggestionItemsAsync(string searchText, Canc
202203
Subtitle = suggestion.Description ?? StringFormatter.Format(Resources.SearchQueryItem_SubtitleTemplate, new() { ["shortcut"] = _shortcut.Name, ["query"] = suggestion.Title }),
203204
Icon = Icons.Search,
204205
TextToSuggest = suggestion.Title,
206+
Tags = suggestion.Tags?.Select(tag => new Tag(tag)).ToArray(),
205207
MoreCommands = [_openHomepageContextItem]
206208
})
207209
];
210+
#pragma warning restore CS8601 // Possible null reference assignment.
208211
}
209212
}

CmdPalWebSearchShortcut/WebSearchShortcut/Suggestion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal interface ISuggestionsProvider
1313
Task<IReadOnlyList<Suggestion>> GetSuggestionsAsync(string query, CancellationToken cancellationToken = default);
1414
}
1515

16-
internal sealed record Suggestion(string Title, string? Description = null);
16+
internal sealed record Suggestion(string Title, string? Description = null, string[]? Tags = null);
1717

1818
internal static class SuggestionsRegistry
1919
{

CmdPalWebSearchShortcut/WebSearchShortcut/SuggestionsProviders/Npm.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ .. results
4040
var pkg = o.GetProperty("package");
4141
var title = pkg.GetProperty("name").GetString();
4242
var description = pkg.TryGetProperty("description", out var desc) ? desc.GetString() : "";
43-
return title is null ? null : new Suggestion(title, description ?? "");
43+
var version = pkg.TryGetProperty("version", out var ver) ? ver.GetString() : "";
44+
return title is null
45+
? null
46+
: new Suggestion(title, description ?? "", version is null ? null : [version]);
4447
})
4548
.Where(s => s is not null)
4649
.Select(s => s!)

0 commit comments

Comments
 (0)