提交 193c8215 编写于 作者: C CyrusNajmabadi

Reduce locations where we wait on getting a Model.

上级 e054d2c3
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Linq; using System.Linq;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions; using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Options; using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
...@@ -36,14 +35,12 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn ...@@ -36,14 +35,12 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn
IEditorOperationsFactoryService editorOperationsFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService,
ITextUndoHistoryRegistry undoHistoryRegistry, ITextUndoHistoryRegistry undoHistoryRegistry,
IInlineRenameService inlineRenameService, IInlineRenameService inlineRenameService,
IWaitIndicator waitIndicator,
[ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners, [ImportMany] IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners,
[ImportMany] IEnumerable<Lazy<IIntelliSensePresenter<ICompletionPresenterSession, ICompletionSession>, OrderableMetadata>> completionPresenters, [ImportMany] IEnumerable<Lazy<IIntelliSensePresenter<ICompletionPresenterSession, ICompletionSession>, OrderableMetadata>> completionPresenters,
[ImportMany] IEnumerable<Lazy<IBraceCompletionSessionProvider, BraceCompletionMetadata>> autoBraceCompletionChars) [ImportMany] IEnumerable<Lazy<IBraceCompletionSessionProvider, BraceCompletionMetadata>> autoBraceCompletionChars)
: this(editorOperationsFactoryService, undoHistoryRegistry, inlineRenameService, waitIndicator, : this(editorOperationsFactoryService, undoHistoryRegistry, inlineRenameService,
ExtensionOrderer.Order(completionPresenters).Select(lazy => lazy.Value).FirstOrDefault(), ExtensionOrderer.Order(completionPresenters).Select(lazy => lazy.Value).FirstOrDefault(),
asyncListeners, asyncListeners, autoBraceCompletionChars)
autoBraceCompletionChars)
{ {
} }
...@@ -51,7 +48,6 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn ...@@ -51,7 +48,6 @@ internal class AsyncCompletionService : ForegroundThreadAffinitizedObject, IAsyn
IEditorOperationsFactoryService editorOperationsFactoryService, IEditorOperationsFactoryService editorOperationsFactoryService,
ITextUndoHistoryRegistry undoHistoryRegistry, ITextUndoHistoryRegistry undoHistoryRegistry,
IInlineRenameService inlineRenameService, IInlineRenameService inlineRenameService,
IWaitIndicator waitIndicator,
IIntelliSensePresenter<ICompletionPresenterSession, ICompletionSession> completionPresenter, IIntelliSensePresenter<ICompletionPresenterSession, ICompletionSession> completionPresenter,
IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners, IEnumerable<Lazy<IAsynchronousOperationListener, FeatureMetadata>> asyncListeners,
IEnumerable<Lazy<IBraceCompletionSessionProvider, BraceCompletionMetadata>> autoBraceCompletionChars) IEnumerable<Lazy<IBraceCompletionSessionProvider, BraceCompletionMetadata>> autoBraceCompletionChars)
......
...@@ -96,27 +96,24 @@ void ICommandHandler<TypeCharCommandArgs>.ExecuteCommand(TypeCharCommandArgs arg ...@@ -96,27 +96,24 @@ void ICommandHandler<TypeCharCommandArgs>.ExecuteCommand(TypeCharCommandArgs arg
// that goes into the other side of the seam, the character may be a commit character. // 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, // If it's a commit character, just commit without trying to check caret position,
// since the caret is no longer in our buffer. // 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; return;
} }
else if (_autoBraceCompletionChars.Contains(args.TypedChar) &&
if (_autoBraceCompletionChars.Contains(args.TypedChar) &&
this.SubjectBuffer.GetFeatureOnOffOption(InternalFeatureOnOffOptions.AutomaticPairCompletion) && 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, // 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 // we don't do multiple buffer change check
this.CommitOnTypeChar(args.TypedChar, initialTextSnapshot, nextHandler);
return; return;
} }
else
{
// If we were computing anything, we stop. We only want to process a typechar // If we were computing anything, we stop. We only want to process a typechar
// if it was a normal character. // if it was a normal character.
this.StopModelComputation(); this.StopModelComputation();
} }
}
return; return;
} }
...@@ -214,15 +211,10 @@ void ICommandHandler<TypeCharCommandArgs>.ExecuteCommand(TypeCharCommandArgs arg ...@@ -214,15 +211,10 @@ void ICommandHandler<TypeCharCommandArgs>.ExecuteCommand(TypeCharCommandArgs arg
// buffer. // buffer.
// Now, commit if it was a commit character. // Now, commit if it was a commit character.
if (this.IsCommitCharacter(args.TypedChar)) if (!this.CommitIfCommitCharacter(args.TypedChar, initialTextSnapshot, nextHandler))
{
// Known to be a commit character for the currently selected item. So just
// commit the session.
this.CommitOnTypeChar(args.TypedChar, initialTextSnapshot, nextHandler);
}
else
{ {
// 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(); this.StopModelComputation();
} }
...@@ -298,12 +290,12 @@ private bool IsTextualTriggerCharacter(CompletionService completionService, char ...@@ -298,12 +290,12 @@ private bool IsTextualTriggerCharacter(CompletionService completionService, char
return completionService.ShouldTriggerCompletion(previousPosition.Snapshot.AsText(), caretPosition, trigger, _roles, options); return completionService.ShouldTriggerCompletion(previousPosition.Snapshot.AsText(), caretPosition, trigger, _roles, options);
} }
private bool IsCommitCharacter(char ch) private bool IsCommitCharacter(char ch, out Model model)
{ {
AssertIsForeground(); AssertIsForeground();
// TODO(cyrusn): Find a way to allow the user to cancel out of this. // 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) if (model == null || model.IsSoftSelection)
{ {
return false; return false;
...@@ -440,14 +432,18 @@ private string GetTextTypedSoFar(Model model, CompletionItem selectedItem) ...@@ -440,14 +432,18 @@ private string GetTextTypedSoFar(Model model, CompletionItem selectedItem)
return filterText; return filterText;
} }
private void CommitOnTypeChar( private bool CommitIfCommitCharacter(
char ch, ITextSnapshot initialTextSnapshot, Action nextHandler) char ch, ITextSnapshot initialTextSnapshot, Action nextHandler)
{ {
AssertIsForeground(); AssertIsForeground();
// Note: this function is called after the character has already been inserted into the // Note: this function is called after the character has already been inserted into the
// buffer. // 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 // 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. // was commit character if we had a selected item.
...@@ -456,6 +452,7 @@ private string GetTextTypedSoFar(Model model, CompletionItem selectedItem) ...@@ -456,6 +452,7 @@ private string GetTextTypedSoFar(Model model, CompletionItem selectedItem)
this.Commit( this.Commit(
model.SelectedItem, model, ch, model.SelectedItem, model, ch,
initialTextSnapshot, nextHandler); initialTextSnapshot, nextHandler);
return true;
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册