提交 d18962b2 编写于 作者: G Gen Lu

Merge branch 'ignoreCOmpletionItemSpan' of...

Merge branch 'ignoreCOmpletionItemSpan' of https://github.com/CyrusNajmabadi/roslyn into TypeImportCompletion2
......@@ -130,6 +130,11 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
return CommitResultUnhandled;
}
if (!session.Properties.TryGetProperty(CompletionSource.CompletionListSpan, out TextSpan completionListSpan))
{
return CommitResultUnhandled;
}
var triggerDocument = triggerSnapshot.GetOpenDocumentInCurrentContextWithChanges();
if (triggerDocument == null)
{
......@@ -139,8 +144,8 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
// Commit with completion service assumes that null is provided is case of invoke. VS provides '\0' in the case.
char? commitChar = typeChar == '\0' ? null : (char?)typeChar;
var commitBehavior = Commit(
triggerDocument, completionService, session.TextView, subjectBuffer,
roslynItem, commitChar, triggerSnapshot, serviceRules, filterText, cancellationToken);
triggerDocument, completionService, session.TextView, subjectBuffer, roslynItem,
completionListSpan, commitChar, triggerSnapshot, serviceRules, filterText, cancellationToken);
_recentItemsManager.MakeMostRecentItem(roslynItem.DisplayText);
return new AsyncCompletionData.CommitResult(isHandled: true, commitBehavior);
......@@ -152,6 +157,7 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
ITextView view,
ITextBuffer subjectBuffer,
RoslynCompletionItem roslynItem,
TextSpan completionListSpan,
char? commitCharacter,
ITextSnapshot triggerSnapshot,
CompletionRules rules,
......@@ -174,7 +180,8 @@ internal CommitManager(ITextView textView, RecentItemsManager recentItemsManager
return AsyncCompletionData.CommitBehavior.None;
}
var change = completionService.GetChangeAsync(document, roslynItem, commitCharacter, cancellationToken).WaitAndGetResult(cancellationToken);
var change = completionService.GetChangeAsync(
document, roslynItem, completionListSpan, commitCharacter, cancellationToken).WaitAndGetResult(cancellationToken);
var textChange = change.TextChange;
var triggerSnapshotSpan = new SnapshotSpan(triggerSnapshot, textChange.Span.ToSpan());
var mappedSpan = triggerSnapshotSpan.TranslateTo(subjectBuffer.CurrentSnapshot, SpanTrackingMode.EdgeInclusive);
......
......@@ -30,6 +30,7 @@ internal class CompletionSource : ForegroundThreadAffinitizedObject, IAsyncCompl
{
internal const string RoslynItem = nameof(RoslynItem);
internal const string TriggerSnapshot = nameof(TriggerSnapshot);
internal const string CompletionListSpan = nameof(CompletionListSpan);
internal const string InsertionText = nameof(InsertionText);
internal const string HasSuggestionItemOptions = nameof(HasSuggestionItemOptions);
internal const string Description = nameof(Description);
......@@ -231,6 +232,10 @@ internal CompletionSource(ITextView textView, IThreadingContext threadingContext
// where data and session in further calls are able to provide other snapshots.
session.Properties.AddProperty(TriggerSnapshot, triggerLocation.Snapshot);
// Store around the span this completion list applies to. We'll use this later
// to pass this value in when we're committing a completion list item.
session.Properties.AddProperty(CompletionListSpan, completionList.Span);
// This is a code supporting original completion scenarios:
// Controller.Session_ComputeModel: if completionList.SuggestionModeItem != null, then suggestionMode = true
// If there are suggestionItemOptions, then later HandleNormalFiltering should set selection to SoftSelection.
......
......@@ -107,7 +107,7 @@ private CompletionProvider GetCompletionProvider(CompletionItem item)
Contract.ThrowIfNull(completionService, nameof(completionService));
completionChange = completionService.GetChangeAsync(
triggerDocument, item, commitChar, CancellationToken.None).WaitAndGetResult(CancellationToken.None);
triggerDocument, item, model.OriginalList.Span, commitChar, CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var textChange = completionChange.TextChange;
var triggerSnapshotSpan = new SnapshotSpan(triggerSnapshot, textChange.Span.ToSpan());
......
......@@ -57,6 +57,9 @@ public virtual Task<CompletionDescription> GetDescriptionAsync(Document document
return Task.FromResult(CompletionChange.Create(new TextChange(item.Span, item.DisplayText)));
}
internal virtual Task<CompletionChange> GetChangeAsync(Document document, CompletionItem item, TextSpan completionListSpan, char? commitKey, CancellationToken cancellationToken)
=> GetChangeAsync(document, item, commitKey, cancellationToken);
/// <summary>
/// True if the provider produces snippet items.
/// </summary>
......
......@@ -124,6 +124,21 @@ public virtual TextSpan GetDefaultCompletionListSpan(SourceText text, int caretP
return Task.FromResult(CompletionChange.Create(new TextChange(item.Span, item.DisplayText)));
}
/// <summary>
/// Preferred overload of <see cref="GetChangeAsync(Document, CompletionItem, char?,
/// CancellationToken)"/>.
///
/// This overload is passed the value of <see cref="CompletionContext.CompletionListSpan"/>
/// which should be used to determine what span should be updated in the original <paramref
/// name="document"/> passed in.
/// </summary>
internal virtual Task<CompletionChange> GetChangeAsync(
Document document, CompletionItem item, TextSpan completionListSpan,
char? commitCharacter = null, CancellationToken cancellationToken = default)
{
return GetChangeAsync(document, item, commitCharacter, cancellationToken);
}
/// <summary>
/// Given a list of completion items that match the current code typed by the user,
/// returns the item that is considered the best match, and whether or not that
......
......@@ -486,6 +486,16 @@ internal virtual bool SupportsTriggerOnDeletion(OptionSet options)
}
}
internal override async Task<CompletionChange> GetChangeAsync(
Document document, CompletionItem item, TextSpan completionListSpan,
char? commitKey, CancellationToken cancellationToken)
{
var provider = GetProvider(item);
return provider != null
? await provider.GetChangeAsync(document, item, completionListSpan, commitKey, cancellationToken).ConfigureAwait(false)
: CompletionChange.Create(new TextChange(completionListSpan, item.DisplayText));
}
bool IEqualityComparer<ImmutableHashSet<string>>.Equals(ImmutableHashSet<string> x, ImmutableHashSet<string> y)
{
if (x == y)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册