Example #1
0
        public async Task <string> GetLatestVersion(string libraryName, bool includePreReleases, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(libraryName))
            {
                return(null);
            }

            if (!await EnsureCatalogAsync(cancellationToken).ConfigureAwait(false))
            {
                return(null);
            }

            CdnjsLibraryGroup group = _libraryGroups.FirstOrDefault(l => l.DisplayName == libraryName);

            if (group == null)
            {
                return(null);
            }

            string first = includePreReleases
                ? (await GetLibraryVersionsAsync(group.DisplayName, cancellationToken).ConfigureAwait(false)).First()
                : group.Version;

            if (!string.IsNullOrEmpty(first))
            {
                return(first);
            }

            return(null);
        }
Example #2
0
        public async Task <string> GetLatestVersion(string libraryName, bool includePreReleases, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(libraryName))
            {
                return(null);
            }

            if (!await EnsureCatalogAsync(cancellationToken).ConfigureAwait(false))
            {
                return(null);
            }

            CdnjsLibraryGroup group = _libraryGroups.FirstOrDefault(l => l.DisplayName == libraryName);

            if (group == null)
            {
                return(null);
            }

            var    versions = (await GetLibraryVersionsAsync(group.DisplayName, cancellationToken).ConfigureAwait(false)).ToList();
            string first    = versions[0];

            if (!includePreReleases)
            {
                first = versions.First(id => id.Any(c => !char.IsLetter(c)));
            }

            if (!string.IsNullOrEmpty(first))
            {
                return(first);
            }

            return(null);
        }
Example #3
0
        public async Task <string> GetLatestVersion(string libraryId, bool includePreReleases, CancellationToken cancellationToken)
        {
            string[] args = libraryId.Split('@');

            if (args.Length < 2)
            {
                return(null);
            }

            if (!await EnsureCatalogAsync(cancellationToken).ConfigureAwait(false))
            {
                return(null);
            }

            string name = args[0];

            CdnjsLibraryGroup group = _libraryGroups.FirstOrDefault(l => l.DisplayName == name);

            if (group == null)
            {
                return(null);
            }

            var    ids   = (await GetLibraryIdsAsync(group.DisplayName, cancellationToken).ConfigureAwait(false)).ToList();
            string first = ids[0];

            if (!includePreReleases)
            {
                first = ids.First(id => id.Substring(name.Length).Any(c => !char.IsLetter(c)));
            }

            if (!string.IsNullOrEmpty(first) && ids.IndexOf(first) < ids.IndexOf(libraryId))
            {
                return(first);
            }

            return(null);
        }
        public async Task <string> GetLatestVersion(string libraryId, bool includePreReleases, CancellationToken cancellationToken)
        {
            (string name, string version) = LibraryIdToNameAndVersionConverter.Instance.GetLibraryNameAndVersion(libraryId, _provider.Id);

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(version))
            {
                return(null);
            }

            if (!await EnsureCatalogAsync(cancellationToken).ConfigureAwait(false))
            {
                return(null);
            }

            CdnjsLibraryGroup group = _libraryGroups.FirstOrDefault(l => l.DisplayName == name);

            if (group == null)
            {
                return(null);
            }

            var    ids   = (await GetLibraryIdsAsync(group.DisplayName, cancellationToken).ConfigureAwait(false)).ToList();
            string first = ids[0];

            if (!includePreReleases)
            {
                first = ids.First(id => id.Substring(name.Length).Any(c => !char.IsLetter(c)));
            }

            if (!string.IsNullOrEmpty(first))
            {
                return(LibraryIdToNameAndVersionConverter.Instance.GetLibraryNameAndVersion(first, _provider.Id).Version);
            }

            return(null);
        }
Example #5
0
        public async Task <CompletionSet> GetLibraryCompletionSetAsync(string value, int caretPosition)
        {
            if (!await EnsureCatalogAsync(CancellationToken.None).ConfigureAwait(false))
            {
                return(default(CompletionSet));
            }

            var completionSet = 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).ConfigureAwait(false);

                foreach (CdnjsLibraryGroup group in result)
                {
                    var completion = new CompletionItem
                    {
                        DisplayText   = group.DisplayName,
                        InsertionText = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(group.DisplayName, group.Version, _provider.Id),
                        Description   = group.Description,
                    };

                    completions.Add(completion);
                }

                completionSet.CompletionType = CompletionSortOrder.AsSpecified;
            }

            // Version
            else
            {
                CdnjsLibraryGroup group = _libraryGroups.FirstOrDefault(g => g.DisplayName == name);

                if (group != null)
                {
                    completionSet.Start  = at + 1;
                    completionSet.Length = value.Length - completionSet.Start;

                    IEnumerable <Asset> assets = await GetAssetsAsync(name, CancellationToken.None).ConfigureAwait(false);

                    foreach (string version in assets.Select(a => a.Version))
                    {
                        var completion = new CompletionItem
                        {
                            DisplayText   = version,
                            InsertionText = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(name, version, _provider.Id),
                        };

                        completions.Add(completion);
                    }
                }

                completionSet.CompletionType = CompletionSortOrder.Version;
            }

            completionSet.Completions = completions;

            return(completionSet);
        }
Example #6
0
        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).ConfigureAwait(false);

                foreach (CdnjsLibraryGroup group in result)
                {
                    var completion = new CompletionItem
                    {
                        DisplayText   = AliasedName(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)
                {
                    span.Start  = at + 1;
                    span.Length = value.Length - span.Start;

                    IEnumerable <Asset> assets = await GetAssetsAsync(name, CancellationToken.None).ConfigureAwait(false);

                    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);
        }