Skip to content

Commit 797e8fd

Browse files
authored
Add filenameChars (#18)
* Add filenameChars * Fix CI
1 parent 45b849a commit 797e8fd

File tree

6 files changed

+172
-109
lines changed

6 files changed

+172
-109
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ jobs:
3636
include:
3737
- os: ubuntu-latest
3838
deno: v1.x
39-
- os: ubuntu-latest
40-
deno: v1.14
41-
- os: ubuntu-latest
42-
deno: v1.14
4339
- os: ubuntu-latest
4440
deno: canary
4541
- os: windows-latest

autoload/ddc_file/internal.vim

Lines changed: 115 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
function! s:line_to_file_full(line, is_posix) abort
2-
return matchlist(
3-
\ a:line,
4-
\ a:is_posix
5-
\ ? '\c\%(^\$\%(env:\)\?\)\?[[:fname:]/]*$'
6-
\ : '\c\%(^\$\%(env:\)\?\)\?[[:fname:]\\]*$'
7-
\ )[0]
2+
let separator = a:is_posix ? '/' : '\'
3+
let pattern = printf('\c\%(^\$\%(env:\)\?\)\?[[:fname:]\%s]*$', separator)
4+
return matchlist(a:line, pattern)[0]
85
endfunction
96

10-
function! s:full_to_base_prefix(full, is_posix) abort
11-
return get(matchlist(
12-
\ a:full,
13-
\ a:is_posix
14-
\ ? '\%(.*\/\|^\)\(.*[^[:keyword:]/]\)[[:keyword:]]*$'
15-
\ : '\%(.*\\\|^\)\(.*[^[:keyword:]\\]\)[[:keyword:]]*$'
16-
\ ), 1, '')
7+
function! s:full_to_base_prefix(full, chars, is_posix) abort
8+
let separator = a:is_posix ? '/' : '\'
9+
let pattern = printf('\%(.*\%s\|^\)\(.*[^%s%s]\)[%s]*$',
10+
\ separator, a:chars, separator, a:chars)
11+
return get(matchlist(a:full, pattern), 1, '')
1712
endfunction
1813

1914
" @param {string} input_line
15+
" @param {string} chars
2016
" @param {boolean} is_posix
2117
" @return {[
2218
" string,
2319
" string,
2420
" string,
2521
" ]}
26-
function! ddc_file#internal#info(input_line, is_posix) abort
22+
function! ddc_file#internal#info(input_line, chars, is_posix) abort
2723
let input_file_full = s:line_to_file_full(a:input_line, a:is_posix)
28-
let input_file_base_prefix = s:full_to_base_prefix(input_file_full, a:is_posix)
24+
let input_file_base_prefix = s:full_to_base_prefix(
25+
\ input_file_full, a:chars, a:is_posix)
2926
let buf_path = expand('%:p')
3027
return [
31-
\ input_file_full,
32-
\ input_file_base_prefix,
33-
\ buf_path,
34-
\ ]
28+
\ input_file_full,
29+
\ input_file_base_prefix,
30+
\ buf_path,
31+
\ ]
3532
endfunction
3633

3734
function! ddc_file#internal#_test() abort
@@ -94,55 +91,105 @@ function! ddc_file#internal#_test() abort
9491
" NOTE: '/' is included as well as '\'.
9592
let &isk = '@,48-57,_,128-167,224-235'
9693
let &isf = '@,48-57,/,\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,='
97-
call assert_equal('', s:line_to_file_full('', v:false))
98-
call assert_equal('.', s:line_to_file_full('.', v:false))
99-
call assert_equal('.', s:line_to_file_full('. .', v:false))
100-
call assert_equal('abc', s:line_to_file_full('abc', v:false))
101-
call assert_equal('bb', s:line_to_file_full('aa bb', v:false))
102-
call assert_equal('bb', s:line_to_file_full('aa bb', v:false))
103-
call assert_equal('bb\aa', s:line_to_file_full('aa ff bb\aa', v:false))
104-
call assert_equal('.bb\aa', s:line_to_file_full('aa ff .bb\aa', v:false))
105-
call assert_equal('.\bb\aa', s:line_to_file_full('aa ff .\bb\aa', v:false))
106-
call assert_equal('..\bb\aa', s:line_to_file_full('aa ff ..\bb\aa', v:false))
107-
call assert_equal('/a', s:line_to_file_full('/a', v:false))
108-
call assert_equal('/.\a', s:line_to_file_full('/.\a', v:false))
109-
call assert_equal('$Foo/bar', s:line_to_file_full('$Foo/bar', v:false))
110-
call assert_equal('/bar', s:line_to_file_full('$Foo /bar', v:false))
111-
call assert_equal('Foo/bar', s:line_to_file_full('$ Foo/bar', v:false))
112-
call assert_equal('$env:Foo/bar', s:line_to_file_full('$env:Foo/bar', v:false))
113-
call assert_equal('/root/$env:Foo/bar', s:line_to_file_full('/root/$env:Foo/bar', v:false))
114-
call assert_equal('$Env:Foo/bar', s:line_to_file_full('$Env:Foo/bar', v:false))
115-
call assert_equal('/bar', s:line_to_file_full('$env:Foo /bar', v:false))
116-
call assert_equal('Foo/bar', s:line_to_file_full('$env: Foo/bar', v:false))
117-
call assert_equal('', s:full_to_base_prefix('', v:false))
118-
call assert_equal('', s:full_to_base_prefix('a', v:false))
119-
call assert_equal('', s:full_to_base_prefix('abc', v:false))
120-
call assert_equal('', s:full_to_base_prefix('\abc', v:false))
121-
call assert_equal('.', s:full_to_base_prefix('.', v:false))
122-
call assert_equal('.', s:full_to_base_prefix('.a', v:false))
123-
call assert_equal('.', s:full_to_base_prefix('.abc', v:false))
124-
call assert_equal('', s:full_to_base_prefix('.\abc', v:false))
125-
call assert_equal('./', s:full_to_base_prefix('./', v:false))
126-
call assert_equal('', s:full_to_base_prefix('\\', v:false))
127-
call assert_equal('.', s:full_to_base_prefix('\.', v:false))
128-
call assert_equal('.', s:full_to_base_prefix('.\.', v:false))
129-
call assert_equal('.', s:full_to_base_prefix('.\.a', v:false))
130-
call assert_equal('.a.', s:full_to_base_prefix('.\.a.', v:false))
131-
call assert_equal('.a.', s:full_to_base_prefix('.\.a.b', v:false))
132-
call assert_equal('.a.b.', s:full_to_base_prefix('.\.a.b.', v:false))
133-
call assert_equal('', s:full_to_base_prefix('.\a', v:false))
134-
call assert_equal('a.', s:full_to_base_prefix('.\a.', v:false))
135-
call assert_equal('a.', s:full_to_base_prefix('.\a.b', v:false))
136-
call assert_equal('a.b.', s:full_to_base_prefix('.\a.b.', v:false))
137-
call assert_equal('.', s:full_to_base_prefix('.', v:false))
138-
call assert_equal('.', s:full_to_base_prefix('.a', v:false))
139-
call assert_equal('.a.', s:full_to_base_prefix('.a.', v:false))
140-
call assert_equal('.a.', s:full_to_base_prefix('.a.b', v:false))
141-
call assert_equal('.a.b.', s:full_to_base_prefix('.a.b.', v:false))
142-
call assert_equal('', s:full_to_base_prefix('a', v:false))
143-
call assert_equal('a.', s:full_to_base_prefix('a.', v:false))
144-
call assert_equal('a.', s:full_to_base_prefix('a.b', v:false))
145-
call assert_equal('a.b.', s:full_to_base_prefix('a.b.', v:false))
94+
let chars = '[:keyword:]'
95+
call assert_equal('',
96+
\ s:line_to_file_full('', chars, v:false))
97+
call assert_equal('.',
98+
\ s:line_to_file_full('.', chars, v:false))
99+
call assert_equal('.',
100+
\ s:line_to_file_full('. .', chars, v:false))
101+
call assert_equal('abc',
102+
\ s:line_to_file_full('abc', chars, v:false))
103+
call assert_equal('bb',
104+
\ s:line_to_file_full('aa bb', chars, v:false))
105+
call assert_equal('bb',
106+
\ s:line_to_file_full('aa bb', chars, v:false))
107+
call assert_equal('bb\aa',
108+
\ s:line_to_file_full('aa ff bb\aa', chars, v:false))
109+
call assert_equal('.bb\aa',
110+
\ s:line_to_file_full('aa ff .bb\aa', chars, v:false))
111+
call assert_equal('.\bb\aa',
112+
\ s:line_to_file_full('aa ff .\bb\aa', chars, v:false))
113+
call assert_equal('..\bb\aa',
114+
\ s:line_to_file_full('aa ff ..\bb\aa', chars, v:false))
115+
call assert_equal('/a',
116+
\ s:line_to_file_full('/a', chars, v:false))
117+
call assert_equal('/.\a',
118+
\ s:line_to_file_full('/.\a', chars, v:false))
119+
call assert_equal('$Foo/bar',
120+
\s:line_to_file_full('$Foo/bar', chars, v:false))
121+
call assert_equal('/bar',
122+
\s:line_to_file_full('$Foo /bar', chars, v:false))
123+
call assert_equal('Foo/bar',
124+
\s:line_to_file_full('$ Foo/bar', chars, v:false))
125+
call assert_equal('$env:Foo/bar',
126+
\s:line_to_file_full('$env:Foo/bar', chars, v:false))
127+
call assert_equal('/root/$env:Foo/bar',
128+
\ s:line_to_file_full('/root/$env:Foo/bar', chars, v:false))
129+
call assert_equal('$Env:Foo/bar',
130+
\s:line_to_file_full('$Env:Foo/bar', chars, v:false))
131+
call assert_equal('/bar',
132+
\s:line_to_file_full('$env:Foo /bar', chars, v:false))
133+
call assert_equal('Foo/bar',
134+
\s:line_to_file_full('$env: Foo/bar', chars, v:false))
135+
call assert_equal('',
136+
\s:full_to_base_prefix('', chars, v:false))
137+
call assert_equal('',
138+
\s:full_to_base_prefix('a', chars, v:false))
139+
call assert_equal('',
140+
\s:full_to_base_prefix('abc', chars, v:false))
141+
call assert_equal('',
142+
\s:full_to_base_prefix('\abc', chars, v:false))
143+
call assert_equal('.',
144+
\s:full_to_base_prefix('.', chars, v:false))
145+
call assert_equal('.',
146+
\s:full_to_base_prefix('.a', chars, v:false))
147+
call assert_equal('.',
148+
\s:full_to_base_prefix('.abc', chars, v:false))
149+
call assert_equal('',
150+
\s:full_to_base_prefix('.\abc', chars, v:false))
151+
call assert_equal('./',
152+
\s:full_to_base_prefix('./', chars, v:false))
153+
call assert_equal('',
154+
\s:full_to_base_prefix('\\', chars, v:false))
155+
call assert_equal('.',
156+
\s:full_to_base_prefix('\.', chars, v:false))
157+
call assert_equal('.',
158+
\s:full_to_base_prefix('.\.', chars, v:false))
159+
call assert_equal('.',
160+
\s:full_to_base_prefix('.\.a', chars, v:false))
161+
call assert_equal('.a.',
162+
\s:full_to_base_prefix('.\.a.', chars, v:false))
163+
call assert_equal('.a.',
164+
\s:full_to_base_prefix('.\.a.b', chars, v:false))
165+
call assert_equal('.a.b.',
166+
\s:full_to_base_prefix('.\.a.b.', chars, v:false))
167+
call assert_equal('',
168+
\s:full_to_base_prefix('.\a', chars, v:false))
169+
call assert_equal('a.',
170+
\s:full_to_base_prefix('.\a.', chars, v:false))
171+
call assert_equal('a.',
172+
\s:full_to_base_prefix('.\a.b', chars, v:false))
173+
call assert_equal('a.b.',
174+
\s:full_to_base_prefix('.\a.b.', chars, v:false))
175+
call assert_equal('.',
176+
\s:full_to_base_prefix('.', chars, v:false))
177+
call assert_equal('.',
178+
\s:full_to_base_prefix('.a', chars, v:false))
179+
call assert_equal('.a.',
180+
\s:full_to_base_prefix('.a.', chars, v:false))
181+
call assert_equal('.a.',
182+
\s:full_to_base_prefix('.a.b', chars, v:false))
183+
call assert_equal('.a.b.',
184+
\s:full_to_base_prefix('.a.b.', chars, v:false))
185+
call assert_equal('',
186+
\ s:full_to_base_prefix('a', chars, v:false))
187+
call assert_equal('a.',
188+
\ s:full_to_base_prefix('a.', chars, v:false))
189+
call assert_equal('a.',
190+
\ s:full_to_base_prefix('a.b', chars, v:false))
191+
call assert_equal('a.b.',
192+
\ s:full_to_base_prefix('a.b.', chars, v:false))
146193
finally
147194
for e in v:errors
148195
echom e

denops/@ddc-file/deps.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
export type {
22
Context,
33
Item,
4-
} from "https://deno.land/x/ddc_vim@v3.0.0/types.ts";
5-
export { BaseSource } from "https://deno.land/x/ddc_vim@v3.0.0/types.ts";
6-
export type { Denops } from "https://deno.land/x/ddc_vim@v3.0.0/deps.ts";
7-
export { fn, vars } from "https://deno.land/x/ddc_vim@v3.0.0/deps.ts";
4+
} from "https://deno.land/x/ddc_vim@v3.1.0/types.ts";
5+
export { BaseSource } from "https://deno.land/x/ddc_vim@v3.1.0/types.ts";
6+
export type { Denops } from "https://deno.land/x/ddc_vim@v3.1.0/deps.ts";
7+
export { fn, vars } from "https://deno.land/x/ddc_vim@v3.1.0/deps.ts";
88
export type {
99
GatherArguments,
10-
} from "https://deno.land/x/ddc_vim@v3.0.0/base/source.ts";
11-
export * as path from "https://deno.land/std@0.160.0/path/mod.ts";
12-
export * as io from "https://deno.land/std@0.160.0/io/mod.ts";
13-
export * as fs from "https://deno.land/std@0.160.0/fs/mod.ts";
14-
export * as asserts from "https://deno.land/std@0.160.0/testing/asserts.ts";
10+
} from "https://deno.land/x/ddc_vim@v3.1.0/base/source.ts";
11+
export * as path from "https://deno.land/std@0.162.0/path/mod.ts";
12+
export * as io from "https://deno.land/std@0.162.0/io/mod.ts";
13+
export * as fs from "https://deno.land/std@0.162.0/fs/mod.ts";
14+
export * as asserts from "https://deno.land/std@0.162.0/testing/asserts.ts";
1515
export {
1616
asyncIteratorFrom as fromA,
1717
iteratorFrom as from,

denops/@ddc-file/internal_autoload_fn.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const createCaller = (name: string): any => {
1212
export type Info = (
1313
denops: Denops,
1414
inputLine: string,
15+
filenameChars: string,
1516
isPosix: boolean,
1617
) => Promise<[
1718
string,

denops/@ddc-sources/file.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Params = {
2828
disableMenu: boolean;
2929
beforeResolve: string;
3030
afterResolve: string;
31+
filenameChars: string;
3132

3233
// display customize
3334
displayFile: string;
@@ -85,6 +86,7 @@ export class Source extends BaseSource<Params> {
8586
const [inputFileFull, inputFileBasePrefix, bufPath] = await internal.info(
8687
args.denops,
8788
args.context.input,
89+
args.sourceParams.filenameChars,
8890
mode === "posix",
8991
);
9092

@@ -309,6 +311,7 @@ export class Source extends BaseSource<Params> {
309311
disableMenu: false,
310312
beforeResolve: "",
311313
afterResolve: "",
314+
filenameChars: "[:keyword:]",
312315

313316
// display customize
314317
displayFile: "file",

0 commit comments

Comments
 (0)