diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/AsyncCompletionService.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/AsyncCompletionService.cs index 6b4b6197bf971c93300367e6227b2f5acef54986..6907db870fda91b9bb44a765c0241de9bb05bced 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/AsyncCompletionService.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/AsyncCompletionService.cs @@ -5,7 +5,6 @@ using System.Collections.Immutable; using System.ComponentModel.Composition; using System.Linq; -using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; @@ -36,14 +35,12 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn IEditorOperationsFactoryService editorOperationsFactoryService, ITextUndoHistoryRegistry undoHistoryRegistry, IInlineRenameService inlineRenameService, - IWaitIndicator waitIndicator, [ImportMany] IEnumerable> asyncListeners, [ImportMany] IEnumerable, OrderableMetadata>> completionPresenters, [ImportMany] IEnumerable> autoBraceCompletionChars) - : this(editorOperationsFactoryService, undoHistoryRegistry, inlineRenameService, waitIndicator, + : this(editorOperationsFactoryService, undoHistoryRegistry, inlineRenameService, ExtensionOrderer.Order(completionPresenters).Select(lazy => lazy.Value).FirstOrDefault(), - asyncListeners, - autoBraceCompletionChars) + asyncListeners, autoBraceCompletionChars) { } @@ -51,7 +48,6 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn IEditorOperationsFactoryService editorOperationsFactoryService, ITextUndoHistoryRegistry undoHistoryRegistry, IInlineRenameService inlineRenameService, - IWaitIndicator waitIndicator, IIntelliSensePresenter completionPresenter, IEnumerable> asyncListeners, IEnumerable> autoBraceCompletionChars) diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs index 315cedac8d0fa38eaf139ef366f7f4cbfc01aa85..69556705648a4e4073ed510675f93e029367d810 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_Backspace.cs @@ -77,7 +77,7 @@ private void ExecuteBackspaceOrDelete(ITextView textView, Action nextHandler, bo { var textBeforeDeletion = SubjectBuffer.AsTextContainer().CurrentText; var documentBeforeDeletion = textBeforeDeletion.GetDocumentWithFrozenPartialSemanticsAsync(CancellationToken.None) - .WaitAndGetResult(CancellationToken.None); + .WaitAndGetResult(CancellationToken.None); this.TextView.TextBuffer.PostChanged -= OnTextViewBufferPostChanged; this.TextView.Caret.PositionChanged -= OnCaretPositionChanged; diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_TypeChar.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_TypeChar.cs index 7c92ab9e645bb3a94d17dca91e4760df12d9c3e0..9b25358a4d8a9dd1df952321c7ecb73a58935758 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_TypeChar.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/Completion/Controller_TypeChar.cs @@ -96,26 +96,23 @@ void ICommandHandler.ExecuteCommand(TypeCharCommandArgs arg // that goes into the other side of the seam, the character may be a commit character. // If it's a commit character, just commit without trying to check caret position, // since the caret is no longer in our buffer. - if (isOnSeam && this.IsCommitCharacter(args.TypedChar)) + if (isOnSeam && this.CommitIfCommitCharacter(args.TypedChar, initialTextSnapshot, nextHandler)) { - this.CommitOnTypeChar(args.TypedChar, initialTextSnapshot, nextHandler); return; } - else if (_autoBraceCompletionChars.Contains(args.TypedChar) && + + if (_autoBraceCompletionChars.Contains(args.TypedChar) && this.SubjectBuffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.AutomaticPairCompletion) && - this.IsCommitCharacter(args.TypedChar)) + this.CommitIfCommitCharacter(args.TypedChar, initialTextSnapshot, nextHandler)) { // I don't think there is any better way than this. if typed char is one of auto brace completion char, // we don't do multiple buffer change check - this.CommitOnTypeChar(args.TypedChar, initialTextSnapshot, nextHandler); return; } - else - { - // If we were computing anything, we stop. We only want to process a typechar - // if it was a normal character. - this.StopModelComputation(); - } + + // If we were computing anything, we stop. We only want to process a typechar + // if it was a normal character. + this.StopModelComputation(); } return; @@ -214,15 +211,10 @@ void ICommandHandler.ExecuteCommand(TypeCharCommandArgs arg // buffer. // Now, commit if it was a commit character. - if (this.IsCommitCharacter(args.TypedChar)) - { - // Known to be a commit character for the currently selected item. So just - // commit the session. - this.CommitOnTypeChar(args.TypedChar, initialTextSnapshot, nextHandler); - } - else + if (!this.CommitIfCommitCharacter(args.TypedChar, initialTextSnapshot, nextHandler)) { - // Now dismiss the session. + // Wasn't a filter or commit character. Stop what we're doing as we have + // no idea what this is. this.StopModelComputation(); } @@ -298,12 +290,12 @@ private bool IsTextualTriggerCharacter(CompletionService completionService, char return completionService.ShouldTriggerCompletion(previousPosition.Snapshot.AsText(), caretPosition, trigger, _roles, options); } - private bool IsCommitCharacter(char ch) + private bool IsCommitCharacter(char ch, out Model model) { AssertIsForeground(); // TODO(cyrusn): Find a way to allow the user to cancel out of this. - var model = sessionOpt.WaitForModel(); + model = sessionOpt.WaitForModel(); if (model == null || model.IsSoftSelection) { return false; @@ -440,14 +432,18 @@ private string GetTextTypedSoFar(Model model, CompletionItem selectedItem) return filterText; } - private void CommitOnTypeChar( + private bool CommitIfCommitCharacter( char ch, ITextSnapshot initialTextSnapshot, Action nextHandler) { AssertIsForeground(); // Note: this function is called after the character has already been inserted into the // buffer. - var model = sessionOpt.WaitForModel(); + + if (!IsCommitCharacter(ch, out var model)) + { + return false; + } // We only call CommitOnTypeChar if ch was a commit character. And we only know if ch // was commit character if we had a selected item. @@ -456,6 +452,7 @@ private string GetTextTypedSoFar(Model model, CompletionItem selectedItem) this.Commit( model.SelectedItem, model, ch, initialTextSnapshot, nextHandler); + return true; } } } \ No newline at end of file