Skip to content

Commit

Permalink
Auto import dependencies when accepting a global suggestion
Browse files Browse the repository at this point in the history
Fixes #2635
  • Loading branch information
mjbvz committed Oct 20, 2017
1 parent 5943b17 commit a8fdcc4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions extensions/typescript/src/features/completionItemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import TypingsStatus from '../utils/typingsStatus';
import * as PConst from '../protocol.const';
import { CompletionEntry, CompletionsRequestArgs, CompletionDetailsRequestArgs, CompletionEntryDetails } from '../protocol';
import * as Previewer from './previewer';
import { tsTextSpanToVsRange, vsPositionToTsFileLocation } from '../utils/convert';
import { tsTextSpanToVsRange, vsPositionToTsFileLocation, tsLocationToVsPosition } from '../utils/convert';

import * as nls from 'vscode-nls';
let localize = nls.loadMessageBundle();
Expand Down Expand Up @@ -46,6 +46,10 @@ class MyCompletionItem extends CompletionItem {
}
}
}

if (entry.hasAction) {

}
}

private static convertKind(kind: string): CompletionItemKind {
Expand Down Expand Up @@ -277,9 +281,25 @@ export default class TypeScriptCompletionItemProvider implements CompletionItemP
}
const detail = details[0];
item.detail = Previewer.plain(detail.displayParts);

item.documentation = Previewer.markdownDocumentation(detail.documentation, detail.tags);

if (detail.codeActions && detail.codeActions.length) {
const additionalEdits: TextEdit[] = [];
for (const action of detail.codeActions) {
for (const change of action.changes) {
if (change.fileName !== filepath) {
continue;
}
for (const edit of change.textChanges) {
additionalEdits.push(new TextEdit(
new Range(tsLocationToVsPosition(edit.start), tsLocationToVsPosition(edit.end)),
edit.newText));
}
}
}
item.additionalTextEdits = additionalEdits;
}

if (detail && this.config.useCodeSnippetsOnMethodSuggest && (item.kind === CompletionItemKind.Function || item.kind === CompletionItemKind.Method)) {
return this.isValidFunctionCompletionContext(filepath, item.position).then(shouldCompleteFunction => {
if (shouldCompleteFunction) {
Expand Down

0 comments on commit a8fdcc4

Please sign in to comment.