Example #1
0
            async Task GetDescriptionAsync(RoslynCompletionSet completionSet, RoslynCompletion completion, CancellationToken cancellationToken)
            {
                var description = await completionSet.GetDescriptionAsync(completion, cancellationToken);

                if (description == null || description.TaggedParts.IsDefault || description.TaggedParts.Length == 0)
                {
                    InitializeDefaultDocumentation();
                }
                else
                {
                    Content = CreateContent(description);
                }
            }
Example #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();
                }
            }
        }
Example #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));
        }
Example #4
0
 public AsyncToolTipContent(CompletionToolTipProvider owner, RoslynCompletionSet completionSet, RoslynCompletion completion, ICompletionSession session, ITaggedTextElementProviderService taggedTextElementProviderService, bool colorize)
 {
     this.owner = owner;
     Session    = session;
     cancellationTokenSource = new CancellationTokenSource();
     this.taggedTextElementProviderService = taggedTextElementProviderService;
     this.colorize      = colorize;
     Session.Dismissed += Session_Dismissed;
     Unloaded          += AsyncToolTipContent_Unloaded;
     GetDescriptionAsync(completionSet, completion, cancellationTokenSource.Token)
     .ContinueWith(t => {
         var ex = t.Exception;
         Dispose();
     }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
 }
Example #5
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);
		}
Example #6
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()) {
				var textChange = change.TextChange;
				Debug.Assert(textChange.Span.End <= originalSnapshot.Length);
				if (textChange.Span.End > originalSnapshot.Length)
					return;
				var span = new SnapshotSpan(originalSnapshot, textChange.Span.ToSpan()).TranslateTo(currentSnapshot, SpanTrackingMode.EdgeInclusive);
				if (!ed.Replace(span.Span, textChange.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();
				}
			}
		}