Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Tweak completion filtering behavior. #2 #16894

Merged
merged 14 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected async Task VerifySendEnterThroughToEnterAsync(string initialMarkup, st
sendThroughEnterOption);

var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, position, CompletionTrigger.Default);
var completionList = await GetCompletionListAsync(service, document, position, CompletionTrigger.Invoke);
var item = completionList.Items.First(i => i.DisplayText.StartsWith(textTypedSoFar));

Assert.Equal(expected, Controller.SendEnterThroughToEditor(service.GetRules(), item, textTypedSoFar));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class C
var document = workspace.CurrentSolution.GetDocument(hostDocument.Id);
var service = CreateCompletionService(workspace,
ImmutableArray.Create<CompletionProvider>(provider));
var completionList = await GetCompletionListAsync(service, document, hostDocument.CursorPosition.Value, CompletionTrigger.Default);
var completionList = await GetCompletionListAsync(service, document, hostDocument.CursorPosition.Value, CompletionTrigger.Invoke);

Assert.True(called);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ public override void set_Bar(int bay, int value)
var solution = testWorkspace.CurrentSolution;
var documentId = testWorkspace.Documents.Single(d => d.Name == "CSharpDocument").Id;
var document = solution.GetDocument(documentId);
var triggerInfo = CompletionTrigger.Default;
var triggerInfo = CompletionTrigger.Invoke;

var service = GetCompletionService(testWorkspace);
var completionList = await GetCompletionListAsync(service, document, position, triggerInfo);
Expand Down Expand Up @@ -2382,7 +2382,7 @@ public override bool Equals(object obj)
var solution = testWorkspace.CurrentSolution;
var documentId = testWorkspace.Documents.Single(d => d.Name == "CSharpDocument2").Id;
var document = solution.GetDocument(documentId);
var triggerInfo = CompletionTrigger.Default;
var triggerInfo = CompletionTrigger.Invoke;

var service = GetCompletionService(testWorkspace);
var completionList = await GetCompletionListAsync(service, document, position, triggerInfo);
Expand Down Expand Up @@ -2438,7 +2438,7 @@ public override bool Equals(object obj)
var solution = testWorkspace.CurrentSolution;
var documentId = testWorkspace.Documents.Single(d => d.Name == "CSharpDocument").Id;
var document = solution.GetDocument(documentId);
var triggerInfo = CompletionTrigger.Default;
var triggerInfo = CompletionTrigger.Invoke;

var service = GetCompletionService(testWorkspace);
var completionList = await GetCompletionListAsync(service, document, cursorPosition, triggerInfo);
Expand Down Expand Up @@ -2543,7 +2543,7 @@ static void Main(string[] args)
var document = workspace.CurrentSolution.GetDocument(testDocument.Id);

var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, testDocument.CursorPosition.Value, CompletionTrigger.Default);
var completionList = await GetCompletionListAsync(service, document, testDocument.CursorPosition.Value, CompletionTrigger.Invoke);

var oldTree = await document.GetSyntaxTreeAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ private async Task CheckResultsAsync(Document document, int position, bool isBui
{
var triggerInfos = new List<CompletionTrigger>();
triggerInfos.Add(CompletionTrigger.CreateInsertionTrigger('a'));
triggerInfos.Add(CompletionTrigger.Default);
triggerInfos.Add(CompletionTrigger.Invoke);
triggerInfos.Add(CompletionTrigger.CreateDeletionTrigger('z'));

var service = GetCompletionService(document.Project.Solution.Workspace);
Expand Down
2 changes: 2 additions & 0 deletions src/EditorFeatures/Core/EditorFeatures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
<Compile Include="FindUsages\IFindUsagesService.cs" />
<Compile Include="FindUsages\SimpleFindUsagesContext.cs" />
<Compile Include="Implementation\InlineRename\Dashboard\DashboardAutomationPeer.cs" />
<Compile Include="Implementation\Intellisense\Completion\CompletionFilterReason.cs" />
<Compile Include="Implementation\Intellisense\Completion\FilterResult.cs" />
<Compile Include="Implementation\Structure\BlockTagState.cs" />
<Compile Include="Tags\ExportImageMonikerServiceAttribute.cs" />
<Compile Include="Implementation\NavigateTo\AbstractNavigateToItemDisplay.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Completion
{
internal enum CompletionFilterReason
{
Insertion,
Deletion,
CaretPositionChanged,
Other,

#if false
// If necessary, we could add additional filter reasons. For example, for the below items.
// However, we have no need for them currently. That somewhat makes sense. We only want
// to really customize our filtering behavior depending on if a user was typing/deleting
// in the buffer.
Snippets,
ItemFiltersChanged,
Invoke,
InvokeAndCommitIfUnique
#endif
}

internal static class CompletionTriggerExtensions
{
public static CompletionFilterReason GetFilterReason(this CompletionTrigger trigger)
=> trigger.Kind.GetFilterReason();
}

internal static class CompletionTriggerKindExtensions
{
public static CompletionFilterReason GetFilterReason(this CompletionTriggerKind kind)
{
switch (kind)
{
case CompletionTriggerKind.Insertion:
return CompletionFilterReason.Insertion;
case CompletionTriggerKind.Deletion:
return CompletionFilterReason.Deletion;
case CompletionTriggerKind.Snippets:
case CompletionTriggerKind.Invoke:
case CompletionTriggerKind.InvokeAndCommitIfUnique:
return CompletionFilterReason.Other;
default:
throw ExceptionUtilities.UnexpectedValue(kind);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ private void OnPresenterSessionCompletionItemFilterStateChanged(

// Update the filter state for the model. Note: if we end up filtering everything
// out we do *not* want to dismiss the completion list.
this.FilterModel(CompletionFilterReason.ItemFiltersChanged,
dismissIfEmptyAllowed: false,
recheckCaretPosition: false,
filterState: e.FilterState);
this.FilterModel(CompletionFilterReason.Other, filterState: e.FilterState);
}
}
}
Expand Down
Loading