Skip to content

Commit

Permalink
Show auto-import in detail for completion
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTup committed Apr 8, 2019
1 parent ac0d95c commit 317b4cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/providers/dart_completion_item_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi
item.insertArgumentPlaceholders,
item.replacementOffset,
item.replacementLength,
item.autoImportUri,
item.suggestion,
res,
);
Expand All @@ -129,10 +130,12 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi
insertArgumentPlaceholders: boolean,
replacementOffset: number,
replacementLength: number,
displayUri: string,
suggestion: as.AvailableSuggestion,
resolvedResult: as.CompletionGetSuggestionDetailsResponse | undefined,
) {
const completionItem = this.makeCompletion(document, nextCharacter, enableCommitCharacters, insertArgumentPlaceholders, {
autoImportUri: displayUri,
completionText: (resolvedResult && resolvedResult.completion) || suggestion.label,
displayText: undefined,
docSummary: suggestion.docSummary,
Expand Down Expand Up @@ -195,12 +198,14 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi
insertArgumentPlaceholders,
resp.replacementOffset,
resp.replacementLength,
includedSuggestionSet.displayUri || suggestionSet.uri,
suggestion,
undefined,
);

// Attach additional info that resolve will need.
const delayedCompletionItem: DelayedCompletionItem = {
autoImportUri: includedSuggestionSet.displayUri || suggestionSet.uri,
document,
enableCommitCharacters,
filePath,
Expand Down Expand Up @@ -252,6 +257,7 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi

private makeCompletion(
document: TextDocument, nextCharacter: string, enableCommitCharacters: boolean, insertArgumentPlaceholders: boolean, suggestion: {
autoImportUri?: string,
completionText: string,
displayText: string | undefined,
docSummary: string | undefined,
Expand Down Expand Up @@ -359,7 +365,9 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi
completion.label = label;
completion.filterText = label.split("(")[0]; // Don't ever include anything after a ( in filtering.
completion.kind = kind;
completion.detail = (suggestion.isDeprecated ? "(deprecated) " : "") + detail;
completion.detail = (suggestion.autoImportUri ? `Auto import from '${suggestion.autoImportUri}'\n\n` : "")
+ (suggestion.isDeprecated ? "(deprecated) " : "")
+ detail;
completion.documentation = new MarkdownString(cleanDartdoc(suggestion.docSummary));
completion.insertText = completionText;
completion.keepWhitespace = true;
Expand Down Expand Up @@ -480,6 +488,7 @@ export class DartCompletionItemProvider implements CompletionItemProvider, IAmDi
}

interface DelayedCompletionItem extends CompletionItem {
autoImportUri: string;
document: TextDocument;
nextCharacter: string;
enableCommitCharacters: boolean;
Expand Down
3 changes: 2 additions & 1 deletion test/dart_only/providers/completion_item_provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ main() {
`);
const completions = await getCompletionsAt("ProcessInf^");

ensureCompletion(completions, vs.CompletionItemKind.Class, "ProcessInfo", "ProcessInfo");
const completion = ensureCompletion(completions, vs.CompletionItemKind.Class, "ProcessInfo", "ProcessInfo");
assert.equal(completion.detail.startsWith("Auto import from 'dart:io'\n\n"), true);
});

it("insert imports automatically when completing unimported symbols", async () => {
Expand Down

0 comments on commit 317b4cd

Please sign in to comment.