コード例 #1
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionCollection> completionSets)
        {
            var snapshot     = session.TextView.TextSnapshot;
            var triggerPoint = session.GetTriggerPoint(snapshot);

            if (triggerPoint == null)
            {
                return;
            }
            var info = CompletionInfo.Create(snapshot);

            if (info == null)
            {
                return;
            }

            // This helps a little to speed up the code
            ProfileOptimizationHelper.StartProfile("roslyn-completion-" + info.Value.CompletionService.Language);

            CompletionTrigger completionTrigger;

            session.Properties.TryGetProperty(typeof(CompletionTrigger), out completionTrigger);

            var completionList = info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, triggerPoint.Value.Position, completionTrigger).GetAwaiter().GetResult();

            if (completionList == null)
            {
                return;
            }
            Debug.Assert(completionList.DefaultSpan.End <= snapshot.Length);
            if (completionList.DefaultSpan.End > snapshot.Length)
            {
                return;
            }
            var trackingSpan  = snapshot.CreateTrackingSpan(completionList.DefaultSpan.Start, completionList.DefaultSpan.Length, SpanTrackingMode.EdgeInclusive, TrackingFidelityMode.Forward);
            var completionSet = RoslynCompletionCollection.Create(mruCompletionService, completionList, info.Value.CompletionService, session.TextView, trackingSpan);

            completionSets.Add(completionSet);
        }