Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

DDC filters for _An O(NP) Sequence Comparison Algorithm_ by Sun Wu, Udi Manber and Gene Myers.

- `matcher_onp` -- filtering candidates by the edit-distance
- `sorter_onp` -- sorting candidates by the edit-distance
- `converter_onp`-- visualizing difference between input string and candidates
- `matcher_onp` -- filtering items by the edit-distance
- `sorter_onp` -- sorting items by the edit-distance
- `converter_onp`-- visualizing difference between input string and items

## Configuration

- `matcher_onp.maximumDistance` -- threshold of the edit-distance.
The filter drops the candidates of which distance is greater than this parameter.
The filter drops the items of which distance is greater than this parameter.
- `converter_onp.hlGroupAddition` -- name of the highlight group to highlight additions of diff string.
- `converter_onp.hlGroupDeletion` -- name of the highlight group to highlight deletions of diff string.
- `converter_onp.type` -- place to show diff string.
Expand Down
14 changes: 7 additions & 7 deletions denops/@ddc-filters/converter_onp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// This work is licensed under the MIT License. https://git.io/mit-license

import onp from "https://esm.sh/onp@2";
import { Candidate } from "https://lib.deno.dev/x/ddc_vim@v0/types.ts";
import { Item } from "https://lib.deno.dev/x/ddc_vim@v3/types.ts";
import {
BaseFilter,
FilterArguments,
OnInitArguments,
} from "https://lib.deno.dev/x/ddc_vim@v0/base/filter.ts";
} from "https://lib.deno.dev/x/ddc_vim@v3/base/filter.ts";

type Params = {
type: "abbr" | "kind" | "menu";
Expand All @@ -22,11 +22,11 @@ export class Filter extends BaseFilter<Params> {
await args.denops.cmd(`highlight OnpAddition ctermfg=Green guifg=Green`);
await args.denops.cmd(`highlight link OnpKeep Pmenu`);
}
override filter(args: FilterArguments<Params>): Promise<Candidate[]> {
return Promise.resolve(args.candidates.map((candidate) => {
const diff = onp.diffText(args.completeStr, candidate.word);
override filter(args: FilterArguments<Params>): Promise<Item[]> {
return Promise.resolve(args.items.map((item) => {
const diff = onp.diffText(args.completeStr, item.word);
let preview = "";
const highlights: typeof candidate.highlights = [];
const highlights: typeof item.highlights = [];
for (const result of diff.results) {
switch (result.state) {
case 1:
Expand Down Expand Up @@ -59,7 +59,7 @@ export class Filter extends BaseFilter<Params> {
}
preview += result.right;
}
return { ...candidate, [args.filterParams.type]: preview, highlights };
return { ...item, [args.filterParams.type]: preview, highlights };
}));
}
override params(): Params {
Expand Down
10 changes: 5 additions & 5 deletions denops/@ddc-filters/matcher_onp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// This work is licensed under the MIT License. https://git.io/mit-license

import onp from "https://esm.sh/onp@2";
import { Candidate } from "https://lib.deno.dev/x/ddc_vim@v0/types.ts";
import { Item } from "https://lib.deno.dev/x/ddc_vim@v3/types.ts";
import {
BaseFilter,
FilterArguments,
} from "https://lib.deno.dev/x/ddc_vim@v0/base/filter.ts";
} from "https://lib.deno.dev/x/ddc_vim@v3/base/filter.ts";

type Params = {
maximumDistance: number
};

export class Filter extends BaseFilter<Params> {
override filter(args: FilterArguments<Params>): Promise<Candidate[]> {
return Promise.resolve(args.candidates.filter((candidate) => {
const diff = onp.diffText(args.completeStr, candidate.word);
override filter(args: FilterArguments<Params>): Promise<Item[]> {
return Promise.resolve(args.items.filter((item) => {
const diff = onp.diffText(args.completeStr, item.word);
return diff.distance < args.filterParams.maximumDistance;
}));
}
Expand Down
16 changes: 8 additions & 8 deletions denops/@ddc-filters/sorter_onp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
// This work is licensed under the MIT License. https://git.io/mit-license

import onp from "https://esm.sh/onp@2";
import { Candidate } from "https://lib.deno.dev/x/ddc_vim@v0/types.ts";
import { Item } from "https://lib.deno.dev/x/ddc_vim@v3/types.ts";
import {
BaseFilter,
FilterArguments,
} from "https://lib.deno.dev/x/ddc_vim@v0/base/filter.ts";
} from "https://lib.deno.dev/x/ddc_vim@v3/base/filter.ts";

type Params = Record<string, never>;

export class Filter extends BaseFilter<Params> {
override filter(args: FilterArguments<Params>): Promise<Candidate[]> {
const matches = new Map<Candidate, number>(
args.candidates.map((candidate) => [
candidate,
onp.diffText(args.completeStr, candidate.word).distance
override filter(args: FilterArguments<Params>): Promise<Item[]> {
const matches = new Map<Item, number>(
args.items.map((item) => [
item,
onp.diffText(args.completeStr, item.word).distance
])
)
return Promise.resolve(args.candidates.sort((a, b) => {
return Promise.resolve(args.items.sort((a, b) => {
return (matches.get(a) ?? 0) - (matches.get(b) ?? 0)
}));
}
Expand Down
8 changes: 4 additions & 4 deletions doc/ddc-onp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ DDC ONP *ddc-onp-ddc_on

DDC filters for An O(NP) Sequence Comparison Algorithm by Sun Wu, Udi Manber and Gene Myers.

* `matcher_onp` -- filtering candidates by the edit-distance
* `sorter_onp` -- sorting candidates by the edit-distance
* `converter_onp`-- visualizing difference between input string and candidates
* `matcher_onp` -- filtering items by the edit-distance
* `sorter_onp` -- sorting items by the edit-distance
* `converter_onp`-- visualizing difference between input string and items

--------------------------------------------------------------------------------
CONFIGURATION *ddc-onp-configuration*

* `matcher_onp.maximumDistance` -- threshold of the edit-distance.
The filter drops the candidates of which distance is greater than this parameter.
The filter drops the items of which distance is greater than this parameter.
* `converter_onp.hlGroupAddition` -- name of the highlight group to highlight additions of diff string.
* `converter_onp.hlGroupDeletion` -- name of the highlight group to highlight deletions of diff string.
* `converter_onp.type` -- place to show diff string.
Expand Down