提交 26d50c89 编写于 作者: R Ravi Chande

Add additional null checks/contract assertions for the result of GetCompletionService

上级 38697471
......@@ -210,7 +210,9 @@ internal partial class Session
// matches the text typed so far.
// Ask the language to determine which of the *matched* items it wants to select.
// We have a Document so GetCompletionService should always succeed.
var service = this.Controller.GetCompletionService();
Contract.ThrowIfNull(service, nameof(service));
var matchingCompletionItems = filterResults.Where(r => r.MatchedFilterText)
.Select(t => t.PresentationItem.Item)
......
......@@ -151,6 +151,11 @@ internal override void OnModelUpdated(Model modelOpt)
AssertIsForeground();
Contract.ThrowIfTrue(sessionOpt != null);
if (completionService == null)
{
return false;
}
if (this.TextView.Selection.Mode == TextSelectionMode.Box)
{
// No completion with multiple selection
......
......@@ -65,8 +65,11 @@ private void ExecuteBackspaceOrDelete(ITextView textView, Action nextHandler, bo
var trigger = CompletionTrigger.CreateDeletionTrigger(deletedChar.GetValueOrDefault());
var completionService = this.GetCompletionService();
this.StartNewModelComputation(
completionService, trigger, filterItems: false, dismissIfEmptyAllowed: true);
if (completionService != null)
{
this.StartNewModelComputation(
completionService, trigger, filterItems: false, dismissIfEmptyAllowed: true);
}
return;
}
......
......@@ -92,6 +92,8 @@ private CompletionProvider GetCompletionProvider(CompletionItem item)
var triggerSnapshot = model.TriggerSnapshot;
var completionService = CompletionService.GetService(triggerDocument);
Contract.ThrowIfNull(completionService, nameof(completionService));
completionChange = completionService.GetChangeAsync(
triggerDocument, item.Item, commitChar, CancellationToken.None).WaitAndGetResult(CancellationToken.None);
var textChange = completionChange.TextChange;
......
......@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.Completion
{
......@@ -26,10 +27,7 @@ void ICommandHandler<TabKeyCommandArgs>.ExecuteCommand(TabKeyCommandArgs args, A
if (sessionOpt == null)
{
// The user may be trying to invoke snippets through question-tab
var completionService = GetCompletionService();
if (completionService != null &&
TryInvokeSnippetCompletion(args, completionService))
if (TryInvokeSnippetCompletion(args))
{
// We've taken care of the tab. Don't send it to the buffer.
return;
......@@ -57,7 +55,7 @@ void ICommandHandler<TabKeyCommandArgs>.ExecuteCommand(TabKeyCommandArgs args, A
}
}
private bool TryInvokeSnippetCompletion(TabKeyCommandArgs args, CompletionService completionService)
private bool TryInvokeSnippetCompletion(TabKeyCommandArgs args)
{
var subjectBuffer = args.SubjectBuffer;
var caretPoint = args.TextView.GetCaretPoint(subjectBuffer).Value.Position;
......@@ -99,7 +97,12 @@ private bool TryInvokeSnippetCompletion(TabKeyCommandArgs args, CompletionServic
return false;
}
var rules = GetCompletionService().GetRules();
// There's was a buffer-Document mapping. We should be able
// to get a CompletionService.
var completionService = GetCompletionService();
Contract.ThrowIfNull(completionService, nameof(completionService));
var rules = completionService.GetRules();
if (rules.SnippetsRule != SnippetsRule.IncludeAfterTypingIdentifierQuestionTab)
{
return false;
......
......@@ -317,6 +317,11 @@ private bool IsCommitCharacter(char ch)
}
var completionService = GetCompletionService();
if (completionService == null)
{
return false;
}
var textTypedSoFar = GetTextTypedSoFar(model, model.SelectedItem.Item);
return IsCommitCharacter(
completionService.GetRules(), model.SelectedItem.Item, ch, textTypedSoFar);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册