getPromptSuggestions method

List<PromptSuggestion> getPromptSuggestions({
  1. PromptCategory? category,
  2. String? search,
  3. String? projectType,
  4. bool? hasGit,
  5. int limit = 10,
})

Get prompt suggestions based on context.

Implementation

List<PromptSuggestion> getPromptSuggestions({
  PromptCategory? category,
  String? search,
  String? projectType,
  bool? hasGit,
  int limit = 10,
}) {
  var suggestions = List<PromptSuggestion>.from(_promptSuggestions);

  if (category != null) {
    suggestions = suggestions.where((s) => s.category == category).toList();
  }

  if (search != null && search.isNotEmpty) {
    final query = search.toLowerCase();
    suggestions = suggestions.where((s) {
      return s.title.toLowerCase().contains(query) ||
          s.text.toLowerCase().contains(query) ||
          s.tags.any((t) => t.toLowerCase().contains(query));
    }).toList();
  }

  // Filter by required context.
  if (hasGit == false) {
    suggestions = suggestions
        .where((s) => s.requiredContext != 'git')
        .toList();
  }

  // Sort by usage count (most used first), then by name.
  suggestions.sort((a, b) {
    final usageCmp = b.usageCount.compareTo(a.usageCount);
    if (usageCmp != 0) return usageCmp;
    return a.title.compareTo(b.title);
  });

  return suggestions.take(limit).toList();
}