Skip to content

Commit

Permalink
Merge pull request #34808 from genlu/TypeImportCompletion2
Browse files Browse the repository at this point in the history
Implement import completion for types
  • Loading branch information
genlu committed Apr 17, 2019
2 parents 0d0406b + 5013e2f commit 0160f43
Show file tree
Hide file tree
Showing 84 changed files with 2,186 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,32 @@ protected override TestWorkspace CreateWorkspace(string fileContents)
string code, int position,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, bool checkForAbsence,
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string inlineDescription = null)
{
return base.VerifyWorkerAsync(
code, position, expectedItemOrNull, expectedDescriptionOrNull,
sourceCodeKind, usePreviousCharAsTrigger, checkForAbsence,
glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
}

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, string displayTextSuffix)
bool? hasSuggestionItem, string displayTextSuffix, string inlineDescription = null)
{
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);
await VerifyAtPositionAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
await VerifyInFrontOfCommentAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
await VerifyAtEndOfFileAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);

// 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, 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);
await VerifyAtPosition_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
await VerifyInFrontOfComment_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
await VerifyAtEndOfFile_ItemPartiallyWrittenAsync(code, position, usePreviousCharAsTrigger, expectedItemOrNull, expectedDescriptionOrNull, sourceCodeKind, checkForAbsence, glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
}
}

Expand All @@ -69,39 +69,39 @@ protected override string ItemPartiallyWritten(string expectedItemOrNull)
string code, int position, string insertText, bool usePreviousCharAsTrigger,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool checkForAbsence, int? glyph,
int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string inlineDescription)
{
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, displayTextSuffix);
matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
}

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

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

protected string AddInsideMethod(string text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal override CompletionProvider CreateCompletionProvider()
string code, int position,
string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, bool checkForAbsence,
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string inlineDescription = null)
{
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);
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, string displayTextSuffix)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string inlineDescription = null)
{
return BaseVerifyWorkerAsync(
code, position, expectedItemOrNull, expectedDescriptionOrNull,
sourceCodeKind, usePreviousCharAsTrigger, checkForAbsence,
glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2744,7 +2744,7 @@ public override void M(in int x)
var completionList = await GetCompletionListAsync(service, document, testDocument.CursorPosition.Value, CompletionTrigger.Invoke);
var completionItem = completionList.Items.Where(c => c.DisplayText == "M(in int x)").Single();

var commit = await service.GetChangeAsync(document, completionItem, commitKey: null, CancellationToken.None);
var commit = await service.GetChangeAsync(document, completionItem, completionList.Span, commitKey: null, CancellationToken.None);

var text = await document.GetTextAsync();
var newText = text.WithChanges(commit.TextChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,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, string displayTextSuffix)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string inlineDescription = null)
{
return BaseVerifyWorkerAsync(
code, position, expectedItemOrNull, expectedDescriptionOrNull,
sourceCodeKind, usePreviousCharAsTrigger, checkForAbsence,
glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ internal override CompletionProvider CreateCompletionProvider()
protected override Task VerifyWorkerAsync(
string code, int position, string expectedItemOrNull, string expectedDescriptionOrNull,
SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger, bool checkForAbsence,
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix)
int? glyph, int? matchPriority, bool? hasSuggestionItem, string displayTextSuffix, string inlineDescription)
{
return base.VerifyWorkerAsync(code, position,
expectedItemOrNull, expectedDescriptionOrNull,
SourceCodeKind.Regular, usePreviousCharAsTrigger, checkForAbsence,
glyph, matchPriority, hasSuggestionItem, displayTextSuffix);
glyph, matchPriority, hasSuggestionItem, displayTextSuffix, inlineDescription);
}

[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
Expand Down Expand Up @@ -345,17 +345,17 @@ string Property

var document = workspace.CurrentSolution.GetDocument(testDocument.Id);
var service = CompletionService.GetService(document);
var completions = await service.GetCompletionsAndSetItemDocumentAsync(document, position);
var completions = await service.GetCompletionsAsync(document, position);

var item = completions.Items.First(i => i.DisplayText == "Beep");
var edit = testDocument.GetTextBuffer().CreateEdit();
edit.Delete(Span.FromBounds(position - 10, position));
edit.Apply();

document = workspace.CurrentSolution.GetDocument(testDocument.Id);
var currentDocument = workspace.CurrentSolution.GetDocument(testDocument.Id);

Assert.NotEqual(document, item.Document);
var description = service.GetDescriptionAsync(item.Document, item);
Assert.NotEqual(currentDocument, document);
var description = service.GetDescriptionAsync(document, item);
}
}
}
Expand Down

0 comments on commit 0160f43

Please sign in to comment.