Skip to content

Commit

Permalink
Return incomplete completions
Browse files Browse the repository at this point in the history
We need to return non-empty completion list for update the results
microsoft/vscode#13735
  • Loading branch information
puh committed Dec 17, 2021
1 parent 4543d66 commit 81077a8
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/providers/autoCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,42 @@ export class NameCompletor implements CompletionItemProvider {
_token: CancellationToken,
_context: CompletionContext
): Promise<CompletionItem[] | CompletionList | undefined> {
if (!fetchedDepsMap) return;
console.log(`${_context.triggerKind}`);
let data = document.lineAt(position).text;
const section = findSection(document, position.line);
if (section != "dependencies" && section != "dev-dependencies") {
return
}
const match = data.match(RE_NAME);
if (match) {
let prefix = match[2];
let start = match[1].length;
let end = match[1].length + match[2].length;
let end = match[1].length + prefix.length;
let range = new Range(new Position(position.line, start), new Position(position.line, end));
if (!range.contains(position)) {
return;
return
}

if (prefix.length < 2) {
const item = new CompletionItem(prefix, CompletionItemKind.Module);
item.range = range;
return new CompletionList([
item
], true)
}

const config = workspace.getConfiguration("", document.uri);
const useLocalIndex = config.get<boolean>("crates.useLocalCargoIndex");
const localIndexHash = config.get<string>("crates.localCargoIndexHash");
const localGitBranch = config.get<string>("crates.localCargoIndexBranch");
let data = await findCratesByPrefix(match[2], useLocalIndex, localIndexHash, localGitBranch);
return data.map((item: string) => {
let i = new CompletionItem(item, CompletionItemKind.Text)
let data = await findCratesByPrefix(prefix, useLocalIndex, localIndexHash, localGitBranch);

const completionItems = data.map((item: string) => {
let i = new CompletionItem(item, CompletionItemKind.Module)
i.range = range;
return i;
});
return completionItems
}
}
}
Expand Down

0 comments on commit 81077a8

Please sign in to comment.