Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Switch to a more appropriate model for supporting prefix/suffix text in completoin items. #26764

Merged
merged 5 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -31,31 +31,32 @@ protected override Task BaseVerifyWorkerAsync(
string code, int position,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, bool checkForAbsence,
int? glyph, int? matchPriority, bool? hasSuggestionItem)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
{
return base.VerifyWorkerAsync(
code, position, expectedItemOrNull, expectedDescriptionOrNull,
sourceCodeKind, usePreviousCharAsTrigger, checkForAbsence,
glyph, matchPriority, hasSuggestionItem);
glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
}

protected override async Task VerifyWorkerAsync(
string code, int position,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger,
bool checkForAbsence, int? glyph, int? matchPriority, bool? hasSuggestionItem)
bool checkForAbsence, int? glyph, int? matchPriority,
bool? hasSuggestionItem, string displayTextSuffix)
{
await VerifyAtPositionAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyInFrontOfCommentAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtEndOfFileAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtPositionAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
await VerifyInFrontOfCommentAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
await VerifyAtEndOfFileAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);

// Items cannot be partially written if we're checking for their absence,
// or if we're verifying that the list will show up (without specifying an actual item)
if (!checkForAbsence && expectedItemOrNull != null)
{
await VerifyAtPosition_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyInFrontOfComment_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtEndOfFile_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtPosition_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
await VerifyInFrontOfComment_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
await VerifyAtEndOfFile_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
}
}

Expand All @@ -68,39 +69,39 @@ private Task VerifyInFrontOfCommentAsync(
string code, int position, string insertText, bool usePreviousCharAsTrigger,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph,
int? matchPriority, bool? hasSuggestionItem)
int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
{
code = code.Substring(0, position) + insertText + "/**/" + code.Substring(position);
position += insertText.Length;

return base.VerifyWorkerAsync(
code, position, expectedItemOrNull, expectedDescriptionOrNull,
sourceCodeKind, usePreviousCharAsTrigger, checkForAbsence, glyph,
matchPriority, hasSuggestionItem);
matchPriority, hasSuggestionItem, displayTextSuffix);
}

private Task VerifyInFrontOfCommentAsync(
string code, int position, bool usePreviousCharAsTrigger,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph,
int? matchPriority, bool? hasSuggestionItem)
int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
{
return VerifyInFrontOfCommentAsync(
code, position, string.Empty, usePreviousCharAsTrigger,
expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind,
checkForAbsence, glyph, matchPriority, hasSuggestionItem);
checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
}

protected Task VerifyInFrontOfComment_ItemPartiallyWrittenAsync(
string code, int position, bool usePreviousCharAsTrigger,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph,
int? matchPriority, bool? hasSuggestionItem)
int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
{
return VerifyInFrontOfCommentAsync(
code, position, ItemPartiallyWritten(expectedItemOrNull), usePreviousCharAsTrigger,
expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind,
checkForAbsence, glyph, matchPriority, hasSuggestionItem);
checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
}

protected string AddInsideMethod(string text)
Expand Down Expand Up @@ -142,7 +143,7 @@ protected async Task VerifySendEnterThroughToEnterAsync(string initialMarkup, st

var service = GetCompletionService(workspace);
var completionList = await GetCompletionListAsync(service, document, position, CompletionTrigger.Invoke);
var item = completionList.Items.First(i => i.DisplayText.StartsWith(textTypedSoFar));
var item = completionList.Items.First(i => (i.DisplayText + i.DisplayTextSuffix).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 @@ -84,7 +84,7 @@ public class TestAttribute : Attribute
public ConsoleColor Color { get; set; }
}";

await VerifyItemExistsAsync(markup, "Color =");
await VerifyItemExistsAsync(markup, "Color", displayTextSuffix: " =");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -106,7 +106,7 @@ public class TestAttribute : Attribute
public string Text { get; set; }
}";

await VerifyItemExistsAsync(markup, "Text =");
await VerifyItemExistsAsync(markup, "Text", displayTextSuffix: " =");
}

[WorkItem(544345, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544345")]
Expand All @@ -129,8 +129,8 @@ public class TestAttribute : Attribute
public string Text { get; set; }
}";

await VerifyItemExistsAsync(markup, "Text =");
await VerifyItemIsAbsentAsync(markup, "Color =");
await VerifyItemExistsAsync(markup, "Text", displayTextSuffix: " =");
await VerifyItemIsAbsentAsync(markup, "Color", displayTextSuffix: " =");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -149,7 +149,7 @@ class Goo
{ }
";

await VerifyItemExistsAsync(markup, "a:");
await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -168,7 +168,7 @@ class Goo
{ }
";

await VerifyItemExistsAsync(markup, "a:");
await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":");
}

[WorkItem(545426, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545426")]
Expand All @@ -191,7 +191,7 @@ class Goo
{
}";

await VerifyItemExistsAsync(markup, "Text =");
await VerifyItemExistsAsync(markup, "Text", displayTextSuffix: " =");
}

[WorkItem(1075278, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1075278")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ protected override async Task VerifyWorkerAsync(
string code, int position,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, bool checkForAbsence,
int? glyph, int? matchPriority, bool? hasSuggestionItem)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
{
await VerifyAtPositionAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtEndOfFileAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtPositionAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
await VerifyAtEndOfFileAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);

// Items cannot be partially written if we're checking for their absence,
// or if we're verifying that the list will show up (without specifying an actual item)
if (!checkForAbsence && expectedItemOrNull != null)
{
await VerifyAtPosition_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtEndOfFile_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem);
await VerifyAtPosition_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
await VerifyAtEndOfFile_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ protected override bool CompareItems(string actualItem, string expectedItem)
protected override Task VerifyWorkerAsync(
string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, bool checkForAbsence,
int? glyph, int? matchPriority, bool? hasSuggestionItem)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
{
return BaseVerifyWorkerAsync(
code, position, expectedItemOrNull, expectedDescriptionOrNull,
sourceCodeKind, usePreviousCharAsTrigger, checkForAbsence,
glyph, matchPriority, hasSuggestionItem);
glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void Bar()
}
}";

await VerifyItemExistsAsync(markup, "a:");
await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -94,7 +94,7 @@ public DogBed(int b) : base($$
}
";

await VerifyItemExistsAsync(markup, "a:");
await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -110,7 +110,7 @@ void Bar(int a)
}
";

await VerifyItemExistsAsync(markup, "a:");
await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -126,7 +126,7 @@ void Bar(int a, string b)
}
";

await VerifyItemExistsAsync(markup, "a:");
await VerifyItemExistsAsync(markup, "a", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand Down Expand Up @@ -159,7 +159,7 @@ static void Main(string[] args)
}
";

await VerifyItemExistsAsync(markup, "i:");
await VerifyItemExistsAsync(markup, "i", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -179,8 +179,8 @@ static void Caller()
}
";

await VerifyItemExistsAsync(markup, "declaring:");
await VerifyItemIsAbsentAsync(markup, "implementing:");
await VerifyItemExistsAsync(markup, "declaring", displayTextSuffix: ":");
await VerifyItemIsAbsentAsync(markup, "implementing", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand Down Expand Up @@ -237,8 +237,8 @@ void Goo(string str = ""hello"", bool boolean = false)
}
";

await VerifyItemExistsAsync(markup, "str:");
await VerifyItemIsAbsentAsync(markup, "character:");
await VerifyItemExistsAsync(markup, "str", displayTextSuffix: ":");
await VerifyItemIsAbsentAsync(markup, "character", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -260,8 +260,8 @@ void Goo(string str = ""hello"", bool boolean = false)
}
";

await VerifyItemExistsAsync(markup, "boolean:");
await VerifyItemExistsAsync(markup, "character:");
await VerifyItemExistsAsync(markup, "boolean", displayTextSuffix: ":");
await VerifyItemExistsAsync(markup, "character", displayTextSuffix: ":");
}

[WorkItem(544191, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544191")]
Expand Down Expand Up @@ -292,10 +292,10 @@ void Method(Bar obj, bool b = false, string str = """")
}
class Bar { }
";
await VerifyItemExistsAsync(markup, "str:");
await VerifyItemExistsAsync(markup, "num:");
await VerifyItemExistsAsync(markup, "b:");
await VerifyItemIsAbsentAsync(markup, "dbl:");
await VerifyItemExistsAsync(markup, "str", displayTextSuffix: ":");
await VerifyItemExistsAsync(markup, "num", displayTextSuffix: ":");
await VerifyItemExistsAsync(markup, "b", displayTextSuffix: ":");
await VerifyItemIsAbsentAsync(markup, "dbl", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -321,9 +321,9 @@ void Method(object obj, bool b = false, string str = """")
}
}
";
await VerifyItemExistsAsync(markup, "str:");
await VerifyItemExistsAsync(markup, "num:");
await VerifyItemExistsAsync(markup, "b:");
await VerifyItemExistsAsync(markup, "str", displayTextSuffix: ":");
await VerifyItemExistsAsync(markup, "num", displayTextSuffix: ":");
await VerifyItemExistsAsync(markup, "b", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand Down Expand Up @@ -352,10 +352,10 @@ void Method(object obj, bool b = false, string str = """")
}
}
";
await VerifyItemExistsAsync(markup, "num:");
await VerifyItemExistsAsync(markup, "b:");
await VerifyItemIsAbsentAsync(markup, "obj:");
await VerifyItemIsAbsentAsync(markup, "str:");
await VerifyItemExistsAsync(markup, "num", displayTextSuffix: ":");
await VerifyItemExistsAsync(markup, "b", displayTextSuffix: ":");
await VerifyItemIsAbsentAsync(markup, "obj", displayTextSuffix: ":");
await VerifyItemIsAbsentAsync(markup, "str", displayTextSuffix: ":");
}

[WorkItem(529369, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529369")]
Expand All @@ -371,7 +371,7 @@ void Goo(int @integer)
}
}
";
await VerifyItemExistsAsync(markup, "integer:");
await VerifyItemExistsAsync(markup, "integer", displayTextSuffix: ":");
}

[WorkItem(544209, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544209")]
Expand All @@ -393,7 +393,7 @@ void Goo(string obj = ""hello"")
{ }
}
";
await VerifyItemExistsAsync(markup, "obj:",
await VerifyItemExistsAsync(markup, "obj", displayTextSuffix: ":",
expectedDescriptionOrNull: $"({FeaturesResources.parameter}) Class1 obj = default(Class1)");
}

Expand All @@ -416,7 +416,7 @@ static void Main(string[] args)
handler($$
}
}";
await VerifyItemExistsAsync(markup, "message:");
await VerifyItemExistsAsync(markup, "message", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand All @@ -438,7 +438,7 @@ static void Main(string[] args)
handler.Invoke($$
}
}";
await VerifyItemExistsAsync(markup, "message:");
await VerifyItemExistsAsync(markup, "message", displayTextSuffix: ":");
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand Down
Loading