Exemplo n.º 1
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets)
        {
            _currentSession = session;
            ITextSnapshot  snapshot = _textBuffer.CurrentSnapshot;
            ITrackingPoint point    = session.GetTriggerPoint(_textBuffer);
            int            pos      = point.GetPosition(snapshot);

            if (_classifier.GetClassificationSpans(new SnapshotSpan(snapshot, new Span(pos, 1))).Any(x => (x.ClassificationType.Classification?.IndexOf("comment", StringComparison.OrdinalIgnoreCase) ?? -1) > -1))
            {
                return;
            }

            _pos = pos;
            if (!IsInRangeForPackageCompletion(snapshot, pos, out Span span, out string name, out string version, out string completionType))
            {
                _nameSearchJob?.Cancel();
                _versionSearchJob?.Cancel();
                _nameSearchJob    = null;
                _versionSearchJob = null;
                return;
            }

            if (_isSelfTrigger)
            {
                _isSelfTrigger = false;
                if (_currentCompletionSet != null)
                {
                    completionSets.Add(_currentCompletionSet);
                }

                return;
            }

            string text = snapshot.GetText();
            int    targetFrameworkElementStartIndex  = text.IndexOf("<TargetFramework>", StringComparison.OrdinalIgnoreCase);
            int    targetFrameworksElementStartIndex = text.IndexOf("<TargetFrameworks>", StringComparison.OrdinalIgnoreCase);
            string tfm = "netcoreapp1.0";

            if (targetFrameworksElementStartIndex > -1)
            {
                int    closeTfms = text.IndexOf("</TargetFrameworks>", targetFrameworksElementStartIndex);
                int    realStart = targetFrameworksElementStartIndex + "<TargetFrameworks>".Length;
                string allTfms   = text.Substring(realStart, closeTfms - realStart);
                tfm = allTfms.Split(';')[0];
            }
            else if (targetFrameworkElementStartIndex > -1)
            {
                int closeTfm  = text.IndexOf("</TargetFramework>", targetFrameworkElementStartIndex);
                int realStart = targetFrameworkElementStartIndex + "<TargetFramework>".Length;
                tfm = text.Substring(realStart, closeTfm - realStart);
            }

            bool showLoading = false;

            switch (completionType)
            {
            case "Name":
                if (_nameSearchJob != null)
                {
                    _nameSearchJob.Cancel();
                    _nameSearchJob.Updated -= UpdateCompletions;
                }
                _versionSearchJob?.Cancel();
                _versionSearchJob       = null;
                _nameSearchJob          = _searchManager.SearchPackageNames(name, tfm);
                _nameSearchJob.Updated += UpdateCompletions;
                showLoading             = _nameSearchJob.RemainingFeeds.Count > 0;
                break;

            case "Version":
                if (_versionSearchJob != null)
                {
                    _versionSearchJob.Cancel();
                    _versionSearchJob.Updated -= UpdateCompletions;
                }
                _nameSearchJob?.Cancel();
                _nameSearchJob             = null;
                _versionSearchJob          = _searchManager.SearchPackageVersions(name, tfm);
                _versionSearchJob.Updated += UpdateCompletions;
                showLoading = _versionSearchJob.RemainingFeeds.Count > 0;
                break;
            }

            _currentCompletionSet = _currentSession.CompletionSets.FirstOrDefault(x => x is PackageCompletionSet) as PackageCompletionSet;

            bool newCompletionSet = _currentCompletionSet == null;

            if (newCompletionSet)
            {
                _currentCompletionSet = new PackageCompletionSet("PackageCompletion", "Package Completion", _textBuffer.CurrentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive));
            }

            if (_nameSearchJob != null)
            {
                ProduceNameCompletionSet();
            }
            else if (_versionSearchJob != null)
            {
                ProduceVersionCompletionSet();
            }

            //If we're not part of an existing session & the results have already been
            //  finalized and those results assert that no packages match, show that
            //  there is no such package/version
            if (!session.CompletionSets.Any(x => x is PackageCompletionSet))
            {
                if (((_nameSearchJob != null && _nameSearchJob.RemainingFeeds.Count == 0) ||
                     (_versionSearchJob != null && _versionSearchJob.RemainingFeeds.Count == 0)) &&
                    _currentCompletionSet.Completions.Count == 0)
                {
                    _currentCompletionSet.AccessibleCompletions.Add(new Microsoft.VisualStudio.Language.Intellisense.Completion("(No Results)"));
                }

                completionSets.Add(_currentCompletionSet);
            }
        }
Exemplo n.º 2
0
 protected override IPackageFeedSearchJob <Tuple <string, FeedKind> > CreateSearch(string partialWord)
 {
     return(searchManager.SearchPackageVersions(packageId.ToLower(), tfm));
 }