| 1 | #nullable enable |
| 2 | using System.Collections.ObjectModel; |
| 3 | using CascadeIDE.Features.Workspace.Application; |
| 4 | using CascadeIDE.Models; |
| 5 | |
| 6 | namespace CascadeIDE.Features.Chat; |
| 7 | |
| 8 | /// <summary>Кэш путей из дерева решения; фильтр по префиксу (ADR 0125) через <see cref="WorkspaceFileIndex"/>.</summary> |
| 9 | public sealed class WorkspaceFileSlashCompletionProvider : IWorkspaceFileSlashCompletionProvider |
| 10 | { |
| 11 | private readonly WorkspaceFileIndex _index = new(); |
| 12 | private readonly Func<string?> _getSolutionPath; |
| 13 | private readonly Func<ObservableCollection<SolutionItem>> _getSolutionRoots; |
| 14 | private readonly Func<string> _getWorkspaceRoot; |
| 15 | |
| 16 | public WorkspaceFileSlashCompletionProvider( |
| 17 | Func<string?> getSolutionPath, |
| 18 | Func<ObservableCollection<SolutionItem>> getSolutionRoots, |
| 19 | Func<string> getWorkspaceRoot) |
| 20 | { |
| 21 | _getSolutionPath = getSolutionPath; |
| 22 | _getSolutionRoots = getSolutionRoots; |
| 23 | _getWorkspaceRoot = getWorkspaceRoot; |
| 24 | } |
| 25 | |
| 26 | public IReadOnlyList<WorkspaceFileSlashMatch> GetMatches(string pathPrefix, int limit) |
| 27 | { |
| 28 | if (limit <= 0) |
| 29 | return []; |
| 30 | |
| 31 | var roots = _getSolutionRoots(); |
| 32 | if (roots.Count == 0) |
| 33 | return []; |
| 34 | |
| 35 | _index.Invalidate(roots, _getSolutionPath(), _getWorkspaceRoot()); |
| 36 | return _index.Search(pathPrefix, limit) |
| 37 | .Select(m => new WorkspaceFileSlashMatch(m.InsertPath, m.Help)) |
| 38 | .ToList(); |
| 39 | } |
| 40 | } |
| 41 | |