public async Task <string> GetLatestVersion(string libraryId, bool includePreReleases, CancellationToken cancellationToken) { string[] args = libraryId.Split('@'); if (args.Length < 2) { return(null); } string name = args[0]; if (!await EnsureCatalogAsync(cancellationToken).ConfigureAwait(false)) { return(null); } CdnjsLibraryGroup group = _libraryGroups.FirstOrDefault(l => l.DisplayName == name); if (group == null) { return(null); } group.DisplayInfosTask = ct => GetDisplayInfosAsync(group.DisplayName, ct); var ids = (await group.GetLibraryIdsAsync(cancellationToken).ConfigureAwait(false)).ToList(); string first = ids.First(); if (!includePreReleases) { first = ids.First(id => id.IndexOf('-', name.Length) == -1); } if (!string.IsNullOrEmpty(first) && ids.IndexOf(first) < ids.IndexOf(libraryId)) { return(first); } ; return(null); }
public async Task <CompletionSet> GetLibraryCompletionSetAsync(string value, int caretPosition) { if (!await EnsureCatalogAsync(CancellationToken.None).ConfigureAwait(false)) { return(default(CompletionSet)); } var span = new CompletionSet { Start = 0, Length = value.Length }; int at = value.IndexOf('@'); string name = at > -1 ? value.Substring(0, at) : value; var completions = new List <CompletionItem>(); // Name if (at == -1 || caretPosition <= at) { IReadOnlyList <ILibraryGroup> result = await SearchAsync(name, int.MaxValue, CancellationToken.None); foreach (CdnjsLibraryGroup group in result) { var completion = new CompletionItem { DisplayText = group.DisplayName, InsertionText = group.DisplayName + "@" + group.Version, Description = group.Description }; completions.Add(completion); } } // Version else { CdnjsLibraryGroup group = _libraryGroups.FirstOrDefault(g => g.DisplayName == name); if (group != null) { IEnumerable <Asset> assets = await GetAssetsAsync(name, CancellationToken.None); foreach (string version in assets.Select(a => a.Version)) { var completion = new CompletionItem { DisplayText = version, InsertionText = $"{name}@{version}" }; completions.Add(completion); } } } span.Completions = completions; return(span); }