Esempio n. 1
0
		public void AugmentCompletionSession(ICompletionSession session, IList<CompletionCollection> completionCollections) {
			var snapshot = session.TextView.TextSnapshot;
			var triggerPoint = session.GetTriggerPoint(snapshot);
			if (triggerPoint == null)
				return;
			var info = CompletionInfo.Create(snapshot);
			if (info == null)
				return;

			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 completionCollection = RoslynCompletionCollection.Create(completionList, info.Value.CompletionService, session.TextView, trackingSpan);
			completionCollections.Add(completionCollection);
		}
        bool TryStartSession(char c, bool isDelete)
        {
            if (HasSession)
            {
                return(false);
            }

            var info = CompletionInfo.Create(textView.TextSnapshot);

            if (info == null)
            {
                return(false);
            }
            int pos = textView.Caret.Position.BufferPosition.Position;
            var completionTrigger = isDelete ? CompletionTrigger.CreateDeletionTrigger(c) : CompletionTrigger.CreateInsertionTrigger(c);

            if (!info.Value.CompletionService.ShouldTriggerCompletion(info.Value.SourceText, pos, completionTrigger))
            {
                return(false);
            }

            StartSession(info, completionTrigger);
            return(HasSession);
        }
 CompletionService TryGetRoslynCompletionService() => CompletionInfo.Create(textView.TextSnapshot)?.CompletionService;