提交 42b7fd04 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14557 from CyrusNajmabadi/numberCompletion

Don't dismiss intellisense if the user types a number after a dot.
// 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 System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
......@@ -131,13 +132,27 @@ internal partial class Session
var filterResults = new List<FilterResult>();
var filterText = model.GetCurrentTextInSnapshot(model.OriginalList.Span, textSnapshot, textSpanToText);
var filterText = model.GetCurrentTextInSnapshot(
model.OriginalList.Span, textSnapshot, textSpanToText);
// If the user was typing a number, then immediately dismiss completion.
// Check if the user is typing a number. If so, only proceed if it's a number
// directly after a <dot>. That's because it is actually reasonable for completion
// to be brought up after a <dot> and for the user to want to filter completion
// items based on a number that exists in the name of the item. However, when
// we are not after a dot (i.e. we're being brought up after <space> is typed)
// then we don't want to filter things. Consider the user writing:
//
// dim i =<space>
//
// We'll bring up the completion list here (as VB has completion on <space>).
// If the user then types '3', we don't want to match against Int32.
var filterTextStartsWithANumber = filterText.Length > 0 && char.IsNumber(filterText[0]);
if (filterTextStartsWithANumber)
{
return null;
if (!IsAfterDot(model, textSnapshot, textSpanToText))
{
return null;
}
}
foreach (var currentItem in model.TotalItems)
......@@ -196,6 +211,17 @@ internal partial class Session
helper, recentItems, filterText, filterResults);
}
private Boolean IsAfterDot(Model model, ITextSnapshot textSnapshot, Dictionary<TextSpan, string> textSpanToText)
{
var span = model.OriginalList.Span;
// Move the span back one character if possible.
span = TextSpan.FromBounds(Math.Max(0, span.Start - 1), span.End);
var text = model.GetCurrentTextInSnapshot(span, textSnapshot, textSpanToText);
return text.Length > 0 && text[0] == '.';
}
private Model HandleNormalFiltering(
Model model,
Document document,
......@@ -424,13 +450,6 @@ public FilterResult(PresentationItem presentationItem, string filterText, bool m
}
}
if (filterText.Length > 0 && IsAllDigits(filterText))
{
// The user is just typing a number. We never want this to match against
// anything we would put in a completion list.
return false;
}
return helper.MatchesFilterText(item, filterText, CultureInfo.CurrentCulture);
}
......
......@@ -2244,5 +2244,26 @@ class Program
Await state.AssertSelectedCompletionItem("DateTime")
End Using
End Function
<WorkItem(14465, "https://github.com/dotnet/roslyn/issues/14465")>
<WpfFact, Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TypingNumberShouldNotDismiss1() As Task
Using state = TestState.CreateCSharpTestState(
<Document><![CDATA[
class C
{
void Moo1()
{
new C()$$
}
}
]]></Document>)
state.SendTypeChars(".")
Await state.AssertCompletionSession()
state.SendTypeChars("1")
Await state.AssertSelectedCompletionItem("Moo1")
End Using
End Function
End Class
End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册