Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gather sources does not cancelled on refresh #132

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: unable to determine stack trace on signal
Implement a signal reason as Error object.
  • Loading branch information
Milly committed Dec 28, 2024
commit ce185b6d88fe18925fc2132fe8fdd898e94f7584
14 changes: 10 additions & 4 deletions denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ import type { BaseSource } from "./base/source.ts";
import type { Loader } from "./loader.ts";
import { convertUserString, printError, treePath2Filename } from "./utils.ts";
import type { AvailableSourceInfo, GatherStateAbortable } from "./state.ts";
import { GatherState } from "./state.ts";
import { isRefreshTarget } from "./state.ts";
import {
GatherState,
isRefreshTarget,
QuitAbortReason,
RefreshAbortReason,
} from "./state.ts";
import {
callColumns,
callFilters,
Expand Down Expand Up @@ -848,7 +852,8 @@ export class Ddu {
quit() {
// NOTE: quitted flag must be called after ui.quit().
this.#quitted = true;
this.#aborter.abort({ reason: "quit" });
const reason = new QuitAbortReason();
this.#aborter.abort(reason);
this.#context.done = true;
}

Expand All @@ -860,7 +865,8 @@ export class Ddu {
async cancelToRefresh(
refreshIndexes: number[] = [],
): Promise<void> {
this.#aborter.abort({ reason: "cancelToRefresh", refreshIndexes });
const reason = new RefreshAbortReason(refreshIndexes);
this.#aborter.abort(reason);

await Promise.all(
[...this.#gatherStates]
Expand Down
29 changes: 22 additions & 7 deletions denops/ddu/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,29 @@ export type AvailableSourceInfo<
sourceParams: Params;
};

type GatherStateAbortReason =
| {
reason: "quit";
export type BaseAbortReason = {
readonly type: string;
};

export class QuitAbortReason extends Error implements BaseAbortReason {
override name = "QuitAbortReason";
readonly type = "quit";
}

export class RefreshAbortReason extends Error implements BaseAbortReason {
override name = "RefreshAbortReason";
readonly type = "cancelToRefresh";
readonly refreshIndexes: readonly number[];

constructor(refreshIndexes: number[] = []) {
super();
this.refreshIndexes = refreshIndexes;
}
| {
reason: "cancelToRefresh";
refreshIndexes: number[];
};
}

export type GatherStateAbortReason =
| QuitAbortReason
| RefreshAbortReason;

export type GatherStateAbortable = {
abort(reason: GatherStateAbortReason): void;
Expand Down