Skip to content

Commit

Permalink
DEV2-2856 - refetch suggestions on idle (#1121)
Browse files Browse the repository at this point in the history
* DEV2-2856 - refetch suggestions on idle

* tests
  • Loading branch information
dimacodota authored May 29, 2023
1 parent 389adb2 commit 2ed5aaa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/debounceCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function debounceCompletions(
vscode.InlineCompletionList<TabnineInlineCompletionItem> | undefined
> {
const { time, value: current } = await timed(() =>
getInlineCompletionItems(document, position)
getInlineCompletionItems(document, position, token)
);

const debounceTime = calculateDebounceMs(time);
Expand All @@ -30,7 +30,7 @@ export default async function debounceCompletions(
}

// re fetch the most updated suggestions
return getInlineCompletionItems(document, position);
return getInlineCompletionItems(document, position, token);
}

async function debounceOrCancelOnRequest(
Expand Down
6 changes: 5 additions & 1 deletion src/getInlineCompletionItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import { isMultiline } from "./utils/utils";

export default async function getInlineCompletionItems(
document: vscode.TextDocument,
position: vscode.Position
position: vscode.Position,
cancellationToken: vscode.CancellationToken
): Promise<vscode.InlineCompletionList<TabnineInlineCompletionItem>> {
const response = await runCompletion({
document,
position,
retry: {
cancellationToken,
},
});

const completions = response?.results.map(
Expand Down
10 changes: 5 additions & 5 deletions src/test/suite/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe("Should do completion", () => {

verify(
stdinMock.write(new SimpleAutocompleteRequestMatcher(), "utf8")
).once();
).atLeast(1);
});
it("should skip completion request on text deletion", async () => {
await openADocWith("test deletion");
Expand Down Expand Up @@ -246,7 +246,7 @@ describe("Should do completion", () => {

verify(
stdinMock.write(new SimpleAutocompleteRequestMatcher(), "utf8")
).once();
).atLeast(1);
});
it("should do completion on new line in python", async () => {
await openADocWith("def binary_search(arr, target):", "python");
Expand All @@ -256,7 +256,7 @@ describe("Should do completion", () => {

verify(
stdinMock.write(new SimpleAutocompleteRequestMatcher(), "utf8")
).once();
).atLeast(1);
});
it("should not change the replace range end in case of multiline suffix", async () => {
const editor = await openADocWith("consol");
Expand Down Expand Up @@ -329,7 +329,7 @@ describe("Should do completion", () => {

verify(
stdinMock.write(new SimpleAutocompleteRequestMatcher(), "utf8")
).once();
).atLeast(1);
});
});
it("should should query tabnine if the change is auto closed brackets", async () => {
Expand Down Expand Up @@ -478,7 +478,7 @@ describe("Should do completion", () => {
new SimpleAutocompleteRequestMatcher(SECOND_PREFIX),
"utf8"
)
).twice();
).atLeast(2);
});
it("should report suggestion about to shown after debounce", async () => {
mockGetDebounceConfig(SHORT_DEBOUNCE_VALUE);
Expand Down

0 comments on commit 2ed5aaa

Please sign in to comment.