Skip to content

Commit 86dda39

Browse files
authored
Merge pull request #217 from vim-denops/feat
πŸ‘ Chores
2 parents 4a598a6 + 0116b6a commit 86dda39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+168
-257
lines changed

β€Ždenops_std/argument/flags_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import { parseFlags } from "./flags.ts";
33

44
Deno.test("parseFlags", () => {

β€Ždenops_std/argument/mod.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,65 @@
11
/**
2-
* A module to handle Vim's command arguments.
2+
* A module to handle Vim's command arguments like the followings.
33
*
4+
* ```vim
5+
* :MyCommand ++enc=sjis ++ff=dos -f --foo=foo --bar=bar --bar=baz hello world
6+
* ```
7+
*
8+
* Developers should utilize `[<f-args>]` in Vim script to acquire the arguments
9+
* as a string array, adhering to the standard Vim command behavior.
10+
*
11+
* For example:
12+
*
13+
* ```vim
14+
* command! -nargs=* MyCommand call denops#request("myplugin", "test", [[<f-args>]])
15+
* ```
16+
*
17+
* Then, developers can use this module to parse, validate, or format the arguments.
18+
*
19+
* ```typescript
20+
* import type { Denops } from "../mod.ts";
21+
* import {
22+
* builtinOpts,
23+
* formatFlags,
24+
* formatOpts,
25+
* parse,
26+
* validateFlags,
27+
* validateOpts,
28+
* } from "./mod.ts";
29+
*
30+
* export async function main(denops: Denops): Promise<void> {
31+
* denops.dispatcher = {
32+
* test(args: unknown) {
33+
* // Parse string array to extract `opts`, `flags`.
34+
* const [opts, flags, residues] = parse(args as string[]);
35+
*
36+
* console.log(opts);
37+
* // { "enc": "sjis", "ff": "dos" }
38+
* console.log(flags);
39+
* // { "f": "", "foo": "foo", "bar": ["bar", "baz"] }
40+
* console.log(residues);
41+
* // ["hello", "world"]
42+
*
43+
* // Validate if `opts` has unknown options
44+
* validateOpts(opts, ["enc", "ff"]);
45+
*
46+
* // Or use `builtinOpts` to validate Vim's builtin `++opts`
47+
* validateOpts(opts, builtinOpts);
48+
*
49+
* // Validate if `flags` has unknown flags
50+
* validateFlags(flags, ["f", "foo", "bar"]);
51+
*
52+
* // Reformat `opts` to string
53+
* console.log(formatOpts(opts));
54+
* // "++enc=sjis ++ff=dos"
55+
*
56+
* // Reformat `flags` to string
57+
* console.log(formatFlags(flags));
58+
* // "-f --foo=foo --bar=bar --bar=baz"
59+
* },
60+
* };
61+
* }
62+
* ```
463
* @module
564
*/
665
import { Opts, parseOpts } from "./opts.ts";

β€Ždenops_std/argument/mod_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import { parse } from "./mod.ts";
33

44
Deno.test("parse", () => {

β€Ždenops_std/argument/opts_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import { parseOpts } from "./opts.ts";
33

44
Deno.test("parseOpts", () => {

β€Ždenops_std/autocmd/README.md

Lines changed: 0 additions & 169 deletions
This file was deleted.

β€Ždenops_std/autocmd/common_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
33
import { globals } from "../variable/mod.ts";
44
import { define, emit, emitAll, list, remove } from "./common.ts";

β€Ždenops_std/autocmd/group_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
33
import { globals } from "../variable/mod.ts";
44
import { group } from "./group.ts";

β€Ždenops_std/batch/batch_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import {
33
assertSpyCall,
44
assertSpyCalls,
55
spy,
6-
} from "https://deno.land/std@0.192.0/testing/mock.ts";
6+
} from "https://deno.land/std@0.205.0/testing/mock.ts";
77
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
88
import { batch, BatchHelper } from "./batch.ts";
99

β€Ždenops_std/batch/collect_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
assertEquals,
33
assertRejects,
4-
} from "https://deno.land/std@0.192.0/testing/asserts.ts";
4+
} from "https://deno.land/std@0.205.0/assert/mod.ts";
55
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
66
import type { Denops } from "https://deno.land/x/denops_core@v5.0.0/mod.ts";
77
import { collect } from "./collect.ts";

β€Ždenops_std/buffer/buffer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Denops } from "https://deno.land/x/denops_core@v5.0.0/mod.ts";
2+
import { maybe } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts#^";
23
import * as autocmd from "../autocmd/mod.ts";
34
import * as batch from "../batch/mod.ts";
45
import * as fn from "../function/mod.ts";
@@ -7,7 +8,7 @@ import { execute } from "../helper/mod.ts";
78
import {
89
FileFormat,
910
findFileFormat,
10-
maybeFileFormat,
11+
isFileFormat,
1112
splitText,
1213
} from "./fileformat.ts";
1314
import { tryDecode } from "./fileencoding.ts";
@@ -284,7 +285,7 @@ export async function decode(
284285
} else {
285286
[enc, text] = tryDecode(data, fileencodings);
286287
}
287-
const ff = maybeFileFormat(options.fileformat) ??
288+
const ff = maybe(options.fileformat, isFileFormat) ??
288289
findFileFormat(text, fileformats) ?? fileformat;
289290
return {
290291
content: splitText(text, ff),

β€Ždenops_std/buffer/buffer_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
assertEquals,
33
assertRejects,
4-
} from "https://deno.land/std@0.192.0/testing/asserts.ts";
4+
} from "https://deno.land/std@0.205.0/assert/mod.ts";
55
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
66
import { default as Encoding } from "https://cdn.skypack.dev/encoding-japanese@2.0.0/";
77
import * as fn from "../function/mod.ts";

β€Ždenops_std/buffer/decoration_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import { test } from "https://deno.land/x/denops_test@v1.4.0/mod.ts";
33
import * as fn from "../function/mod.ts";
44
import * as vimFn from "../function/vim/mod.ts";

β€Ždenops_std/buffer/fileencoding_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
1+
import { assertEquals } from "https://deno.land/std@0.205.0/assert/mod.ts";
22
import { default as Encoding } from "https://cdn.skypack.dev/encoding-japanese@2.0.0/";
33
import { tryDecode } from "./fileencoding.ts";
44

0 commit comments

Comments
Β (0)