Skip to content

Commit

Permalink
Merge pull request #127 from Shougo/loader_objs
Browse files Browse the repository at this point in the history
Improve loader implementation
  • Loading branch information
Shougo authored Dec 3, 2024
2 parents 8103503 + 84a9a7c commit 9832fde
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 159 deletions.
2 changes: 1 addition & 1 deletion autoload/ddu.vim
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function ddu#get_context(name) abort
return ddu#denops#_request('getContext', [a:name])
endfunction
function ddu#register(type, path) abort
call ddu#denops#_notify('register', [a:type, a:path])
call ddu#denops#_notify('registerPath', [a:type, a:path])
endfunction
function ddu#load(type, names) abort
call ddu#denops#_notify('loadExtensions', [a:type, a:names])
Expand Down
49 changes: 31 additions & 18 deletions denops/ddu/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import {
uiSearchItem,
} from "./ext.ts";
import { isDenoCacheIssueError } from "./utils.ts";
import { defaultUiOptions } from "./base/ui.ts";
import { defaultSourceOptions } from "./base/source.ts";
import { defaultFilterOptions } from "./base/filter.ts";
import { defaultColumnOptions } from "./base/column.ts";
import { defaultKindOptions } from "./base/kind.ts";
import { type BaseUi, defaultUiOptions } from "./base/ui.ts";
import { type BaseSource, defaultSourceOptions } from "./base/source.ts";
import { type BaseFilter, defaultFilterOptions } from "./base/filter.ts";
import { type BaseKind, defaultKindOptions } from "./base/kind.ts";
import { type BaseColumn, defaultColumnOptions } from "./base/column.ts";
import { defaultActionOptions } from "./base/action.ts";

import type { Denops, Entrypoint } from "jsr:@denops/std@~7.3.0";
import type { Denops, Entrypoint } from "jsr:@denops/std@~7.4.0";

import { toFileUrl } from "jsr:@std/path@~1.0.2/to-file-url";
import { Lock } from "jsr:@core/asyncutil@~1.2.0/lock";
Expand Down Expand Up @@ -104,42 +104,55 @@ export const main: Entrypoint = (denops: Denops) => {
};

denops.dispatcher = {
alias(arg1: unknown, arg2: unknown, arg3: unknown): Promise<void> {
alias(arg1: unknown, arg2: unknown, arg3: unknown) {
setAlias(
ensure(arg1, is.String) as DduAliasType,
ensure(arg2, is.String) as string,
ensure(arg3, is.String) as string,
);
return Promise.resolve();
},
async register(arg1: unknown, arg2: unknown): Promise<void> {
async registerPath(arg1: unknown, arg2: unknown) {
await loader.registerPath(
ensure(arg1, is.String) as DduExtType,
ensure(arg2, is.String) as string,
);
return Promise.resolve();
},
setGlobal(arg1: unknown): Promise<void> {
registerExtension(
arg1: unknown,
arg2: unknown,
arg3: unknown,
) {
const type = ensure(arg1, is.String);
const name = ensure(arg2, is.String);
if (type === "ui") {
loader.registerExtension(type, name, arg3 as BaseUi<BaseParams>);
} else if (type === "source") {
loader.registerExtension(type, name, arg3 as BaseSource<BaseParams>);
} else if (type === "filter") {
loader.registerExtension(type, name, arg3 as BaseFilter<BaseParams>);
} else if (type === "kind") {
loader.registerExtension(type, name, arg3 as BaseKind<BaseParams>);
} else if (type === "column") {
loader.registerExtension(type, name, arg3 as BaseColumn<BaseParams>);
}
},
setGlobal(arg1: unknown) {
const options = ensure(arg1, is.Record) as Partial<DduOptions>;
contextBuilder.setGlobal(options);
return Promise.resolve();
},
setLocal(arg1: unknown, arg2: unknown): Promise<void> {
setLocal(arg1: unknown, arg2: unknown) {
const options = ensure(arg1, is.Record) as Partial<DduOptions>;
const name = ensure(arg2, is.String) as string;
contextBuilder.setLocal(name, options);
return Promise.resolve();
},
patchGlobal(arg1: unknown): Promise<void> {
patchGlobal(arg1: unknown) {
const options = ensure(arg1, is.Record) as Partial<DduOptions>;
contextBuilder.patchGlobal(options);
return Promise.resolve();
},
patchLocal(arg1: unknown, arg2: unknown): Promise<void> {
patchLocal(arg1: unknown, arg2: unknown) {
const options = ensure(arg1, is.Record) as Partial<DduOptions>;
const name = ensure(arg2, is.String) as string;
contextBuilder.patchLocal(name, options);
return Promise.resolve();
},
getGlobal(): Promise<Partial<DduOptions>> {
return Promise.resolve(contextBuilder.getGlobal());
Expand Down
2 changes: 1 addition & 1 deletion denops/ddu/base/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ItemHighlight,
} from "../types.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import type { Denops } from "jsr:@denops/std@~7.4.0";

export type OnInitArguments<Params extends BaseParams> = {
denops: Denops;
Expand Down
2 changes: 1 addition & 1 deletion denops/ddu/base/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ContextBuilder } from "../context.ts";
import type { DduAliasType } from "../types.ts";
import type { Denops } from "jsr:@denops/std@~7.3.0";
import type { Denops } from "jsr:@denops/std@~7.4.0";

export type ConfigArguments = {
denops: Denops;
Expand Down
2 changes: 1 addition & 1 deletion denops/ddu/base/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
SourceOptions,
} from "../types.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import type { Denops } from "jsr:@denops/std@~7.4.0";

export type OnInitArguments<Params extends BaseParams> = {
denops: Denops;
Expand Down
2 changes: 1 addition & 1 deletion denops/ddu/base/kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
Previewer,
} from "../types.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import type { Denops } from "jsr:@denops/std@~7.4.0";

export type GetPreviewerArguments = {
denops: Denops;
Expand Down
2 changes: 1 addition & 1 deletion denops/ddu/base/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
SourceOptions,
} from "../types.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import type { Denops } from "jsr:@denops/std@~7.4.0";

export type OnInitArguments<Params extends BaseParams> = {
denops: Denops;
Expand Down
2 changes: 1 addition & 1 deletion denops/ddu/base/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
UiOptions,
} from "../types.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import type { Denops } from "jsr:@denops/std@~7.4.0";

export type UiActions<Params extends BaseParams> = Record<
string,
Expand Down
4 changes: 2 additions & 2 deletions denops/ddu/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {
import { defaultSourceOptions } from "./base/source.ts";
import { printError } from "./utils.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import * as fn from "jsr:@denops/std@~7.3.0/function";
import type { Denops } from "jsr:@denops/std@~7.4.0";
import * as fn from "jsr:@denops/std@~7.4.0/function";

import { assertEquals } from "jsr:@std/assert@~1.0.2/equals";

Expand Down
7 changes: 2 additions & 5 deletions denops/ddu/ddu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import {
uiSearchItem,
} from "./ext.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import * as fn from "jsr:@denops/std@~7.3.0/function";
import type { Denops } from "jsr:@denops/std@~7.4.0";
import * as fn from "jsr:@denops/std@~7.4.0/function";

import { assertEquals } from "jsr:@std/assert@~1.0.2/equals";
import { equal } from "jsr:@std/assert@~1.0.2/equal";
Expand Down Expand Up @@ -1145,7 +1145,6 @@ export class Ddu {

const sourceIndex = parent.__sourceIndex;
const source = this.#loader.getSource(
this.#options.name,
parent.__sourceName,
);
if (source == null) {
Expand Down Expand Up @@ -1389,7 +1388,6 @@ export class Ddu {
}
const sourceIndex = item.__sourceIndex;
const source = this.#loader.getSource(
this.#options.name,
item.__sourceName,
);
if (source == null) {
Expand Down Expand Up @@ -1652,7 +1650,6 @@ export class Ddu {
return this.#options.sources.map((userSource) =>
sourceArgs(
this.#loader.getSource(
this.#options.name,
convertUserString(userSource).name,
),
this.#options,
Expand Down
28 changes: 13 additions & 15 deletions denops/ddu/ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import type { BaseUi } from "./base/ui.ts";
import type { Loader } from "./loader.ts";
import { convertUserString, printError } from "./utils.ts";

import type { Denops } from "jsr:@denops/std@~7.3.0";
import * as fn from "jsr:@denops/std@~7.3.0/function";
import type { Denops } from "jsr:@denops/std@~7.4.0";
import * as fn from "jsr:@denops/std@~7.4.0/function";

import type { Lock } from "jsr:@core/asyncutil@~1.2.0/lock";
import { is } from "jsr:@core/unknownutil@~4.3.0/is";
Expand Down Expand Up @@ -82,10 +82,9 @@ export async function getItemActions(
const sources = [
...new Set(
items.length > 0
? items.map((item) => loader.getSource(options.name, item.__sourceName))
? items.map((item) => loader.getSource(item.__sourceName))
: options.sources.map((userSource) =>
loader.getSource(
options.name,
convertUserString(userSource).name,
)
),
Expand Down Expand Up @@ -305,7 +304,7 @@ export async function getUi(
]
> {
const userUi = convertUserString(options.ui);
if (!loader.getUi(options.name, userUi.name)) {
if (!loader.getUi(userUi.name)) {
const startTime = Date.now();

const exists = await loader.autoload(denops, "ui", userUi.name);
Expand All @@ -322,7 +321,7 @@ export async function getUi(
}
}

const ui = loader.getUi(options.name, userUi.name);
const ui = loader.getUi(userUi.name);
if (!ui) {
return [
undefined,
Expand Down Expand Up @@ -350,7 +349,7 @@ export async function getSource(
BaseParams,
]
> {
if (!loader.getSource(options.name, name)) {
if (!loader.getSource(name)) {
const startTime = Date.now();

const exists = await loader.autoload(denops, "source", name);
Expand All @@ -364,7 +363,7 @@ export async function getSource(
}
}

const source = loader.getSource(options.name, name);
const source = loader.getSource(name);
if (!source) {
return [
undefined,
Expand Down Expand Up @@ -396,7 +395,7 @@ export async function getFilter(
> {
userFilter = convertUserString(userFilter);

if (!loader.getFilter(options.name, userFilter.name)) {
if (!loader.getFilter(userFilter.name)) {
const startTime = Date.now();

const exists = await loader.autoload(denops, "filter", userFilter.name);
Expand All @@ -413,7 +412,7 @@ export async function getFilter(
}
}

const filter = loader.getFilter(options.name, userFilter.name);
const filter = loader.getFilter(userFilter.name);
if (!filter) {
return [
undefined,
Expand All @@ -440,7 +439,7 @@ async function getKind(
): Promise<
BaseKind<BaseParams> | undefined
> {
if (!loader.getKind(options.name, name)) {
if (!loader.getKind(name)) {
const startTime = Date.now();

const exists = await loader.autoload(denops, "kind", name);
Expand All @@ -454,7 +453,7 @@ async function getKind(
}
}

const kind = loader.getKind(options.name, name);
const kind = loader.getKind(name);
if (!kind) {
return undefined;
}
Expand All @@ -476,7 +475,7 @@ export async function getColumn(
> {
userColumn = convertUserString(userColumn);

if (!loader.getColumn(options.name, userColumn.name)) {
if (!loader.getColumn(userColumn.name)) {
const startTime = Date.now();

const exists = await loader.autoload(denops, "column", userColumn.name);
Expand All @@ -493,7 +492,7 @@ export async function getColumn(
}
}

const column = loader.getColumn(options.name, userColumn.name);
const column = loader.getColumn(userColumn.name);
if (!column) {
return [
undefined,
Expand Down Expand Up @@ -681,7 +680,6 @@ export async function getPreviewer(
previewContext: PreviewContext,
): Promise<Previewer | undefined> {
const source = loader.getSource(
options.name,
item.__sourceName,
);
if (!source) {
Expand Down
Loading

0 comments on commit 9832fde

Please sign in to comment.