Skip to content

Commit 4e31100

Browse files
committed
💥 Rename path attribute to expr in Bufname
Developers often use `path` module of `deno_std` with this module thus it's better not to use that name.
1 parent 89e8d10 commit 4e31100

File tree

3 files changed

+50
-46
lines changed

3 files changed

+50
-46
lines changed

denops_std/bufname/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import { format } from "https://deno.land/x/denops_std/bufname/mod.ts";
1818

1919
export async function main(denops: Denops): Promise<void> {
2020
assertEquals(
21-
format({ scheme: "denops", path: "/Users/johntitor/.vimrc" }),
21+
format({ scheme: "denops", expr: "/Users/johntitor/.vimrc" }),
2222
"denops:///Users/johntitor/.vimrc",
2323
);
2424

2525
assertEquals(
2626
format({
2727
scheme: "denops",
28-
path: "/Users/johntitor/.vimrc",
28+
expr: "/Users/johntitor/.vimrc",
2929
params: {
3030
foo: "foo",
3131
bar: ["bar", "bar"],
@@ -38,7 +38,7 @@ export async function main(denops: Denops): Promise<void> {
3838
assertEquals(
3939
format({
4040
scheme: "denops",
41-
path: "/Users/johntitor/.vimrc",
41+
expr: "/Users/johntitor/.vimrc",
4242
params: {
4343
foo: "foo",
4444
bar: ["bar", "bar"],
@@ -66,14 +66,14 @@ import { parse } from "https://deno.land/x/denops_std/bufname/mod.ts";
6666
export async function main(denops: Denops): Promise<void> {
6767
assertEquals(parse("denops:///Users/johntitor/.vimrc"), {
6868
scheme: "denops",
69-
path: "/Users/johntitor/.vimrc",
69+
expr: "/Users/johntitor/.vimrc",
7070
});
7171

7272
assertEquals(
7373
parse("denops:///Users/johntitor/.vimrc;foo=foo&bar=bar&bar=bar"),
7474
{
7575
scheme: "denops",
76-
path: "/Users/johntitor/.vimrc",
76+
expr: "/Users/johntitor/.vimrc",
7777
params: {
7878
foo: "foo",
7979
bar: ["bar", "bar"],
@@ -85,7 +85,7 @@ export async function main(denops: Denops): Promise<void> {
8585
parse("denops:///Users/johntitor/.vimrc;foo=foo&bar=bar&bar=bar#README.md"),
8686
{
8787
scheme: "denops",
88-
path: "/Users/johntitor/.vimrc",
88+
expr: "/Users/johntitor/.vimrc",
8989
params: {
9090
foo: "foo",
9191
bar: ["bar", "bar"],

denops_std/bufname/bufname.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export type BufnameParams = Record<string, string | string[] | undefined>;
55
export type Bufname = {
66
// Scheme part of a buffer name. Note that Vim supports only alphabets in scheme part.
77
scheme: string;
8-
// Path part of a buffer name. Note that '<>|?*' are not supported in Vim on Windows.
9-
path: string;
8+
// Expression part of a buffer name. Note that '<>|?*' are not supported in Vim on Windows.
9+
expr: string;
1010
// Params part of a buffer name. While '?' is not supported, the params part are splitted by ';' instead.
1111
params?: BufnameParams;
1212
// Fragment part of a buffer name. This is mainly used to regulate the suffix of the buffer name.
@@ -23,19 +23,21 @@ const schemeUnusablePattern = /[^a-zA-Z]/;
2323
// https://github.com/vim/vim/blob/36698e34aacee4186e6f5f87f431626752fcb337/src/misc1.c#L2567-L2580
2424
const schemePattern = /^(\S+):\/\//;
2525

26-
// The path part might contains query and/or fragment
27-
const pathPattern = /^(.*?)(?:;(.*?))?(?:#(.*))?$/;
26+
// The expr part might contains query and/or fragment
27+
const exprPattern = /^(.*?)(?:;(.*?))?(?:#(.*))?$/;
2828

2929
/**
3030
* Format Bufname instance to construct Vim's buffer name.
3131
*/
32-
export function format({ scheme, path, params, fragment }: Bufname): string {
32+
export function format(
33+
{ scheme, expr, params, fragment }: Bufname,
34+
): string {
3335
if (schemeUnusablePattern.test(scheme)) {
3436
throw new Error(
3537
`Scheme '${scheme}' contains unusable characters. Only alphabets are allowed.`,
3638
);
3739
}
38-
const encodedPath = encode(path).replaceAll(";", "%3B").replaceAll(
40+
const encodedPath = encode(expr).replaceAll(";", "%3B").replaceAll(
3941
"#",
4042
"%23",
4143
);
@@ -49,16 +51,18 @@ export function format({ scheme, path, params, fragment }: Bufname): string {
4951
/**
5052
* Parse Vim's buffer name to construct Bufname instance.
5153
*/
52-
export function parse(expr: string): Bufname {
53-
if (bufnameUnusablePattern.test(expr)) {
54+
export function parse(bufname: string): Bufname {
55+
if (bufnameUnusablePattern.test(bufname)) {
5456
throw new Error(
55-
`Expression '${expr}' contains unusable characters. Vim (on Windows) does not support '<>|?*' in a buffer name.`,
57+
`A buffer name '${bufname}' contains unusable characters. Vim (on Windows) does not support '<>|?*' in a buffer name.`,
5658
);
5759
}
5860
// Check if the bufname is remote
59-
const m1 = expr.match(schemePattern);
61+
const m1 = bufname.match(schemePattern);
6062
if (!m1) {
61-
throw new Error(`Expression '${expr}' does not start from '{scheme}://'.`);
63+
throw new Error(
64+
`A buffer name '${bufname}' does not start from '{scheme}://'.`,
65+
);
6266
}
6367
const scheme = m1[1];
6468
// Vim (less than 8.2.3153) only supports alphabets in scheme part
@@ -67,19 +71,19 @@ export function parse(expr: string): Bufname {
6771
`Scheme '${scheme}' contains unusable characters. Only alphabets are allowed.`,
6872
);
6973
}
70-
const remain = decode(expr.substring(`${scheme}://`.length), [
74+
const remain = decode(bufname.substring(`${scheme}://`.length), [
7175
"%3B", // ;
7276
"%23", // #
7377
]);
74-
const m2 = remain.match(pathPattern)!;
75-
const path = decode(m2[1]);
78+
const m2 = remain.match(exprPattern)!;
79+
const expr = decode(m2[1]);
7680
const params = m2[2]
7781
? fromURLSearchParams(new URLSearchParams(decode(m2[2])))
7882
: undefined;
7983
const fragment = m2[3] ? decode(m2[3]) : undefined;
8084
return {
8185
scheme,
82-
path,
86+
expr,
8387
...(params ? { params } : {}),
8488
...(fragment ? { fragment } : {}),
8589
};

denops_std/bufname/bufname_test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Deno.test("format throws exception when 'scheme' contains unusable characters",
66
() =>
77
format({
88
scheme: "denops0number",
9-
path: "/absolute/path/to/worktree",
9+
expr: "/absolute/path/to/worktree",
1010
}),
1111
undefined,
1212
"contains unusable characters",
@@ -15,7 +15,7 @@ Deno.test("format throws exception when 'scheme' contains unusable characters",
1515
() =>
1616
format({
1717
scheme: "denops+plus",
18-
path: "/absolute/path/to/worktree",
18+
expr: "/absolute/path/to/worktree",
1919
}),
2020
undefined,
2121
"contains unusable characters",
@@ -24,7 +24,7 @@ Deno.test("format throws exception when 'scheme' contains unusable characters",
2424
() =>
2525
format({
2626
scheme: "denops-minus",
27-
path: "/absolute/path/to/worktree",
27+
expr: "/absolute/path/to/worktree",
2828
}),
2929
undefined,
3030
"contains unusable characters",
@@ -33,7 +33,7 @@ Deno.test("format throws exception when 'scheme' contains unusable characters",
3333
() =>
3434
format({
3535
scheme: "denops.dot",
36-
path: "/absolute/path/to/worktree",
36+
expr: "/absolute/path/to/worktree",
3737
}),
3838
undefined,
3939
"contains unusable characters",
@@ -42,7 +42,7 @@ Deno.test("format throws exception when 'scheme' contains unusable characters",
4242
() =>
4343
format({
4444
scheme: "denops_underscore",
45-
path: "/absolute/path/to/worktree",
45+
expr: "/absolute/path/to/worktree",
4646
}),
4747
undefined,
4848
"contains unusable characters",
@@ -51,16 +51,16 @@ Deno.test("format throws exception when 'scheme' contains unusable characters",
5151
Deno.test("format returns buffer name string from Bufname instance", () => {
5252
const src = {
5353
scheme: "denops",
54-
path: "/absolute/path/to/worktree",
54+
expr: "/absolute/path/to/worktree",
5555
};
5656
const dst = format(src);
5757
const exp = "denops:///absolute/path/to/worktree";
5858
assertEquals(dst, exp);
5959
});
60-
Deno.test("format encodes unusable characters in 'path'", () => {
60+
Deno.test("format encodes unusable characters in 'expr'", () => {
6161
const src = {
6262
scheme: "denops",
63-
path: "/<>|?*",
63+
expr: "/<>|?*",
6464
};
6565
const dst = format(src);
6666
const exp = "denops:///%3C%3E%7C%3F%2A";
@@ -69,7 +69,7 @@ Deno.test("format encodes unusable characters in 'path'", () => {
6969
Deno.test("format returns buffer name string from Bufname instance (with URLSearchParams)", () => {
7070
const src = {
7171
scheme: "denops",
72-
path: "/absolute/path/to/worktree",
72+
expr: "/absolute/path/to/worktree",
7373
params: {
7474
foo: "foo",
7575
bar: ["bar", "bar"],
@@ -83,7 +83,7 @@ Deno.test("format returns buffer name string from Bufname instance (with URLSear
8383
Deno.test("format encodes unusable characters in 'params'", () => {
8484
const src = {
8585
scheme: "denops",
86-
path: "/absolute/path/to/worktree",
86+
expr: "/absolute/path/to/worktree",
8787
params: {
8888
foo: "<>|?*",
8989
},
@@ -95,7 +95,7 @@ Deno.test("format encodes unusable characters in 'params'", () => {
9595
Deno.test("format returns buffer name string from Bufname instance (with fragment)", () => {
9696
const src = {
9797
scheme: "denops",
98-
path: "/absolute/path/to/worktree",
98+
expr: "/absolute/path/to/worktree",
9999
fragment: "Hello World.md",
100100
};
101101
const dst = format(src);
@@ -105,7 +105,7 @@ Deno.test("format returns buffer name string from Bufname instance (with fragmen
105105
Deno.test("format encodes unusable characters in 'fragment'", () => {
106106
const src = {
107107
scheme: "denops",
108-
path: "/absolute/path/to/worktree",
108+
expr: "/absolute/path/to/worktree",
109109
fragment: "<>|?*",
110110
};
111111
const dst = format(src);
@@ -115,7 +115,7 @@ Deno.test("format encodes unusable characters in 'fragment'", () => {
115115
Deno.test("format returns buffer name string from Bufname instance (with URLSearchParams and fragment)", () => {
116116
const src = {
117117
scheme: "denops",
118-
path: "/absolute/path/to/worktree",
118+
expr: "/absolute/path/to/worktree",
119119
params: {
120120
foo: "foo",
121121
bar: ["bar", "bar"],
@@ -128,10 +128,10 @@ Deno.test("format returns buffer name string from Bufname instance (with URLSear
128128
"denops:///absolute/path/to/worktree;foo=foo&bar=bar&bar=bar#Hello World.md";
129129
assertEquals(dst, exp);
130130
});
131-
Deno.test("format encodes ';' and '#' in 'path'", () => {
131+
Deno.test("format encodes ';' and '#' in 'expr'", () => {
132132
const src = {
133133
scheme: "denops",
134-
path: "/hello;world#hello",
134+
expr: "/hello;world#hello",
135135
};
136136
const dst = format(src);
137137
const exp = "denops:///hello%3Bworld%23hello";
@@ -180,16 +180,16 @@ Deno.test("parse returns Bufname instance from buffer name", () => {
180180
const dst = parse(src);
181181
const exp = {
182182
scheme: "denops",
183-
path: "/absolute/path/to/worktree",
183+
expr: "/absolute/path/to/worktree",
184184
};
185185
assertEquals(dst, exp);
186186
});
187-
Deno.test("parse decodes percent-encoded characters in 'path'", () => {
187+
Deno.test("parse decodes percent-encoded characters in 'expr'", () => {
188188
const src = "denops:///%3C%3E%7C%3F%2A";
189189
const dst = parse(src);
190190
const exp = {
191191
scheme: "denops",
192-
path: "/<>|?*",
192+
expr: "/<>|?*",
193193
};
194194
assertEquals(dst, exp);
195195
});
@@ -198,7 +198,7 @@ Deno.test("parse returns Bufname instance from buffer name (with params)", () =>
198198
const dst = parse(src);
199199
const exp = {
200200
scheme: "denops",
201-
path: "/absolute/path/to/worktree",
201+
expr: "/absolute/path/to/worktree",
202202
params: {
203203
foo: "foo",
204204
bar: ["bar", "bar"],
@@ -211,7 +211,7 @@ Deno.test("parse decodes percent-encoded characters in 'params'", () => {
211211
const dst = parse(src);
212212
const exp = {
213213
scheme: "denops",
214-
path: "/absolute/path/to/worktree",
214+
expr: "/absolute/path/to/worktree",
215215
params: {
216216
foo: "<>|?*",
217217
},
@@ -223,7 +223,7 @@ Deno.test("parse returns Bufname instance from buffer name (with fragment)", ()
223223
const dst = parse(src);
224224
const exp = {
225225
scheme: "denops",
226-
path: "/absolute/path/to/worktree",
226+
expr: "/absolute/path/to/worktree",
227227
fragment: "Hello World.md",
228228
};
229229
assertEquals(dst, exp);
@@ -233,7 +233,7 @@ Deno.test("parse decodes percent-encoded characters in 'fragment'", () => {
233233
const dst = parse(src);
234234
const exp = {
235235
scheme: "denops",
236-
path: "/absolute/path/to/worktree",
236+
expr: "/absolute/path/to/worktree",
237237
fragment: "<>|?*",
238238
};
239239
assertEquals(dst, exp);
@@ -244,7 +244,7 @@ Deno.test("parse returns Bufname instance from buffer name (with params and frag
244244
const dst = parse(src);
245245
const exp = {
246246
scheme: "denops",
247-
path: "/absolute/path/to/worktree",
247+
expr: "/absolute/path/to/worktree",
248248
params: {
249249
foo: "foo",
250250
bar: ["bar", "bar"],
@@ -253,12 +253,12 @@ Deno.test("parse returns Bufname instance from buffer name (with params and frag
253253
};
254254
assertEquals(dst, exp);
255255
});
256-
Deno.test("parse decode percent-encoded characters (';' and '#') in 'path'", () => {
256+
Deno.test("parse decode percent-encoded characters (';' and '#') in 'expr'", () => {
257257
const src = "denops:///hello%3Bworld%23hello";
258258
const dst = parse(src);
259259
const exp = {
260260
scheme: "denops",
261-
path: "/hello;world#hello",
261+
expr: "/hello;world#hello",
262262
};
263263
assertEquals(dst, exp);
264264
});

0 commit comments

Comments
 (0)