Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
        public void Commit(RoslynCompletion completion)
        {
            if (completion == null)
            {
                throw new ArgumentNullException(nameof(completion));
            }

            mruCompletionService.AddText(completion.DisplayText);

            var info = CompletionInfo.Create(ApplicableTo.TextBuffer.CurrentSnapshot);

            Debug.Assert(info != null);
            if (info == null)
            {
                return;
            }

            var change          = completionService.GetChangeAsync(info.Value.Document, completion.CompletionItem, commitCharacter: null).GetAwaiter().GetResult();
            var buffer          = ApplicableTo.TextBuffer;
            var currentSnapshot = buffer.CurrentSnapshot;

            using (var ed = buffer.CreateEdit()) {
                foreach (var c in change.TextChanges)
                {
                    Debug.Assert(c.Span.End <= originalSnapshot.Length);
                    if (c.Span.End > originalSnapshot.Length)
                    {
                        return;
                    }
                    var span = new SnapshotSpan(originalSnapshot, c.Span.ToSpan()).TranslateTo(currentSnapshot, SpanTrackingMode.EdgeInclusive);
                    if (!ed.Replace(span.Span, c.NewText))
                    {
                        return;
                    }
                }
                ed.Apply();
            }
            if (change.NewPosition != null)
            {
                var snapshot = buffer.CurrentSnapshot;
                Debug.Assert(change.NewPosition.Value <= snapshot.Length);
                if (change.NewPosition.Value <= snapshot.Length)
                {
                    textView.Caret.MoveTo(new SnapshotPoint(snapshot, change.NewPosition.Value));
                    textView.Caret.EnsureVisible();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the description or null if none
        /// </summary>
        /// <param name="completion">Completion</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns></returns>
        public Task <CompletionDescription> GetDescriptionAsync(RoslynCompletion completion, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (completion == null)
            {
                throw new ArgumentNullException(nameof(completion));
            }

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

            if (info == null)
            {
                return(Task.FromResult <CompletionDescription>(null));
            }

            return(completionService.GetDescriptionAsync(info.Value.Document, completion.CompletionItem, cancellationToken));
        }
Exemplo n.º 4
0
        public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> 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 = RoslynCompletionSet.Create(imageMonikerService, mruCompletionService, completionList, info.Value.CompletionService, session.TextView, DefaultCompletionSetMoniker, dnSpy_Roslyn_Shared_Resources.CompletionSet_All, trackingSpan);

            completionSets.Add(completionSet);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 CompletionService TryGetRoslynCompletionService() => CompletionInfo.Create(textView.TextSnapshot)?.CompletionService;