Skip to content
Merged
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
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ jobs:
include:
- os: ubuntu-latest
deno: v1.x
- os: ubuntu-latest
deno: v1.14
- os: ubuntu-latest
deno: v1.14
- os: ubuntu-latest
deno: canary
- os: windows-latest
Expand Down
183 changes: 115 additions & 68 deletions autoload/ddc_file/internal.vim
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
function! s:line_to_file_full(line, is_posix) abort
return matchlist(
\ a:line,
\ a:is_posix
\ ? '\c\%(^\$\%(env:\)\?\)\?[[:fname:]/]*$'
\ : '\c\%(^\$\%(env:\)\?\)\?[[:fname:]\\]*$'
\ )[0]
let separator = a:is_posix ? '/' : '\'
let pattern = printf('\c\%(^\$\%(env:\)\?\)\?[[:fname:]\%s]*$', separator)
return matchlist(a:line, pattern)[0]
endfunction

function! s:full_to_base_prefix(full, is_posix) abort
return get(matchlist(
\ a:full,
\ a:is_posix
\ ? '\%(.*\/\|^\)\(.*[^[:keyword:]/]\)[[:keyword:]]*$'
\ : '\%(.*\\\|^\)\(.*[^[:keyword:]\\]\)[[:keyword:]]*$'
\ ), 1, '')
function! s:full_to_base_prefix(full, chars, is_posix) abort
let separator = a:is_posix ? '/' : '\'
let pattern = printf('\%(.*\%s\|^\)\(.*[^%s%s]\)[%s]*$',
\ separator, a:chars, separator, a:chars)
return get(matchlist(a:full, pattern), 1, '')
endfunction

" @param {string} input_line
" @param {string} chars
" @param {boolean} is_posix
" @return {[
" string,
" string,
" string,
" ]}
function! ddc_file#internal#info(input_line, is_posix) abort
function! ddc_file#internal#info(input_line, chars, is_posix) abort
let input_file_full = s:line_to_file_full(a:input_line, a:is_posix)
let input_file_base_prefix = s:full_to_base_prefix(input_file_full, a:is_posix)
let input_file_base_prefix = s:full_to_base_prefix(
\ input_file_full, a:chars, a:is_posix)
let buf_path = expand('%:p')
return [
\ input_file_full,
\ input_file_base_prefix,
\ buf_path,
\ ]
\ input_file_full,
\ input_file_base_prefix,
\ buf_path,
\ ]
endfunction

function! ddc_file#internal#_test() abort
Expand Down Expand Up @@ -94,55 +91,105 @@ function! ddc_file#internal#_test() abort
" NOTE: '/' is included as well as '\'.
let &isk = '@,48-57,_,128-167,224-235'
let &isf = '@,48-57,/,\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,='
call assert_equal('', s:line_to_file_full('', v:false))
call assert_equal('.', s:line_to_file_full('.', v:false))
call assert_equal('.', s:line_to_file_full('. .', v:false))
call assert_equal('abc', s:line_to_file_full('abc', v:false))
call assert_equal('bb', s:line_to_file_full('aa bb', v:false))
call assert_equal('bb', s:line_to_file_full('aa bb', v:false))
call assert_equal('bb\aa', s:line_to_file_full('aa ff bb\aa', v:false))
call assert_equal('.bb\aa', s:line_to_file_full('aa ff .bb\aa', v:false))
call assert_equal('.\bb\aa', s:line_to_file_full('aa ff .\bb\aa', v:false))
call assert_equal('..\bb\aa', s:line_to_file_full('aa ff ..\bb\aa', v:false))
call assert_equal('/a', s:line_to_file_full('/a', v:false))
call assert_equal('/.\a', s:line_to_file_full('/.\a', v:false))
call assert_equal('$Foo/bar', s:line_to_file_full('$Foo/bar', v:false))
call assert_equal('/bar', s:line_to_file_full('$Foo /bar', v:false))
call assert_equal('Foo/bar', s:line_to_file_full('$ Foo/bar', v:false))
call assert_equal('$env:Foo/bar', s:line_to_file_full('$env:Foo/bar', v:false))
call assert_equal('/root/$env:Foo/bar', s:line_to_file_full('/root/$env:Foo/bar', v:false))
call assert_equal('$Env:Foo/bar', s:line_to_file_full('$Env:Foo/bar', v:false))
call assert_equal('/bar', s:line_to_file_full('$env:Foo /bar', v:false))
call assert_equal('Foo/bar', s:line_to_file_full('$env: Foo/bar', v:false))
call assert_equal('', s:full_to_base_prefix('', v:false))
call assert_equal('', s:full_to_base_prefix('a', v:false))
call assert_equal('', s:full_to_base_prefix('abc', v:false))
call assert_equal('', s:full_to_base_prefix('\abc', v:false))
call assert_equal('.', s:full_to_base_prefix('.', v:false))
call assert_equal('.', s:full_to_base_prefix('.a', v:false))
call assert_equal('.', s:full_to_base_prefix('.abc', v:false))
call assert_equal('', s:full_to_base_prefix('.\abc', v:false))
call assert_equal('./', s:full_to_base_prefix('./', v:false))
call assert_equal('', s:full_to_base_prefix('\\', v:false))
call assert_equal('.', s:full_to_base_prefix('\.', v:false))
call assert_equal('.', s:full_to_base_prefix('.\.', v:false))
call assert_equal('.', s:full_to_base_prefix('.\.a', v:false))
call assert_equal('.a.', s:full_to_base_prefix('.\.a.', v:false))
call assert_equal('.a.', s:full_to_base_prefix('.\.a.b', v:false))
call assert_equal('.a.b.', s:full_to_base_prefix('.\.a.b.', v:false))
call assert_equal('', s:full_to_base_prefix('.\a', v:false))
call assert_equal('a.', s:full_to_base_prefix('.\a.', v:false))
call assert_equal('a.', s:full_to_base_prefix('.\a.b', v:false))
call assert_equal('a.b.', s:full_to_base_prefix('.\a.b.', v:false))
call assert_equal('.', s:full_to_base_prefix('.', v:false))
call assert_equal('.', s:full_to_base_prefix('.a', v:false))
call assert_equal('.a.', s:full_to_base_prefix('.a.', v:false))
call assert_equal('.a.', s:full_to_base_prefix('.a.b', v:false))
call assert_equal('.a.b.', s:full_to_base_prefix('.a.b.', v:false))
call assert_equal('', s:full_to_base_prefix('a', v:false))
call assert_equal('a.', s:full_to_base_prefix('a.', v:false))
call assert_equal('a.', s:full_to_base_prefix('a.b', v:false))
call assert_equal('a.b.', s:full_to_base_prefix('a.b.', v:false))
let chars = '[:keyword:]'
call assert_equal('',
\ s:line_to_file_full('', chars, v:false))
call assert_equal('.',
\ s:line_to_file_full('.', chars, v:false))
call assert_equal('.',
\ s:line_to_file_full('. .', chars, v:false))
call assert_equal('abc',
\ s:line_to_file_full('abc', chars, v:false))
call assert_equal('bb',
\ s:line_to_file_full('aa bb', chars, v:false))
call assert_equal('bb',
\ s:line_to_file_full('aa bb', chars, v:false))
call assert_equal('bb\aa',
\ s:line_to_file_full('aa ff bb\aa', chars, v:false))
call assert_equal('.bb\aa',
\ s:line_to_file_full('aa ff .bb\aa', chars, v:false))
call assert_equal('.\bb\aa',
\ s:line_to_file_full('aa ff .\bb\aa', chars, v:false))
call assert_equal('..\bb\aa',
\ s:line_to_file_full('aa ff ..\bb\aa', chars, v:false))
call assert_equal('/a',
\ s:line_to_file_full('/a', chars, v:false))
call assert_equal('/.\a',
\ s:line_to_file_full('/.\a', chars, v:false))
call assert_equal('$Foo/bar',
\s:line_to_file_full('$Foo/bar', chars, v:false))
call assert_equal('/bar',
\s:line_to_file_full('$Foo /bar', chars, v:false))
call assert_equal('Foo/bar',
\s:line_to_file_full('$ Foo/bar', chars, v:false))
call assert_equal('$env:Foo/bar',
\s:line_to_file_full('$env:Foo/bar', chars, v:false))
call assert_equal('/root/$env:Foo/bar',
\ s:line_to_file_full('/root/$env:Foo/bar', chars, v:false))
call assert_equal('$Env:Foo/bar',
\s:line_to_file_full('$Env:Foo/bar', chars, v:false))
call assert_equal('/bar',
\s:line_to_file_full('$env:Foo /bar', chars, v:false))
call assert_equal('Foo/bar',
\s:line_to_file_full('$env: Foo/bar', chars, v:false))
call assert_equal('',
\s:full_to_base_prefix('', chars, v:false))
call assert_equal('',
\s:full_to_base_prefix('a', chars, v:false))
call assert_equal('',
\s:full_to_base_prefix('abc', chars, v:false))
call assert_equal('',
\s:full_to_base_prefix('\abc', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('.', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('.a', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('.abc', chars, v:false))
call assert_equal('',
\s:full_to_base_prefix('.\abc', chars, v:false))
call assert_equal('./',
\s:full_to_base_prefix('./', chars, v:false))
call assert_equal('',
\s:full_to_base_prefix('\\', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('\.', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('.\.', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('.\.a', chars, v:false))
call assert_equal('.a.',
\s:full_to_base_prefix('.\.a.', chars, v:false))
call assert_equal('.a.',
\s:full_to_base_prefix('.\.a.b', chars, v:false))
call assert_equal('.a.b.',
\s:full_to_base_prefix('.\.a.b.', chars, v:false))
call assert_equal('',
\s:full_to_base_prefix('.\a', chars, v:false))
call assert_equal('a.',
\s:full_to_base_prefix('.\a.', chars, v:false))
call assert_equal('a.',
\s:full_to_base_prefix('.\a.b', chars, v:false))
call assert_equal('a.b.',
\s:full_to_base_prefix('.\a.b.', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('.', chars, v:false))
call assert_equal('.',
\s:full_to_base_prefix('.a', chars, v:false))
call assert_equal('.a.',
\s:full_to_base_prefix('.a.', chars, v:false))
call assert_equal('.a.',
\s:full_to_base_prefix('.a.b', chars, v:false))
call assert_equal('.a.b.',
\s:full_to_base_prefix('.a.b.', chars, v:false))
call assert_equal('',
\ s:full_to_base_prefix('a', chars, v:false))
call assert_equal('a.',
\ s:full_to_base_prefix('a.', chars, v:false))
call assert_equal('a.',
\ s:full_to_base_prefix('a.b', chars, v:false))
call assert_equal('a.b.',
\ s:full_to_base_prefix('a.b.', chars, v:false))
finally
for e in v:errors
echom e
Expand Down
18 changes: 9 additions & 9 deletions denops/@ddc-file/deps.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export type {
Context,
Item,
} from "https://deno.land/x/ddc_vim@v3.0.0/types.ts";
export { BaseSource } from "https://deno.land/x/ddc_vim@v3.0.0/types.ts";
export type { Denops } from "https://deno.land/x/ddc_vim@v3.0.0/deps.ts";
export { fn, vars } from "https://deno.land/x/ddc_vim@v3.0.0/deps.ts";
} from "https://deno.land/x/ddc_vim@v3.1.0/types.ts";
export { BaseSource } from "https://deno.land/x/ddc_vim@v3.1.0/types.ts";
export type { Denops } from "https://deno.land/x/ddc_vim@v3.1.0/deps.ts";
export { fn, vars } from "https://deno.land/x/ddc_vim@v3.1.0/deps.ts";
export type {
GatherArguments,
} from "https://deno.land/x/ddc_vim@v3.0.0/base/source.ts";
export * as path from "https://deno.land/std@0.160.0/path/mod.ts";
export * as io from "https://deno.land/std@0.160.0/io/mod.ts";
export * as fs from "https://deno.land/std@0.160.0/fs/mod.ts";
export * as asserts from "https://deno.land/std@0.160.0/testing/asserts.ts";
} from "https://deno.land/x/ddc_vim@v3.1.0/base/source.ts";
export * as path from "https://deno.land/std@0.162.0/path/mod.ts";
export * as io from "https://deno.land/std@0.162.0/io/mod.ts";
export * as fs from "https://deno.land/std@0.162.0/fs/mod.ts";
export * as asserts from "https://deno.land/std@0.162.0/testing/asserts.ts";
export {
asyncIteratorFrom as fromA,
iteratorFrom as from,
Expand Down
1 change: 1 addition & 0 deletions denops/@ddc-file/internal_autoload_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const createCaller = (name: string): any => {
export type Info = (
denops: Denops,
inputLine: string,
filenameChars: string,
isPosix: boolean,
) => Promise<[
string,
Expand Down
3 changes: 3 additions & 0 deletions denops/@ddc-sources/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Params = {
disableMenu: boolean;
beforeResolve: string;
afterResolve: string;
filenameChars: string;

// display customize
displayFile: string;
Expand Down Expand Up @@ -85,6 +86,7 @@ export class Source extends BaseSource<Params> {
const [inputFileFull, inputFileBasePrefix, bufPath] = await internal.info(
args.denops,
args.context.input,
args.sourceParams.filenameChars,
mode === "posix",
);

Expand Down Expand Up @@ -309,6 +311,7 @@ export class Source extends BaseSource<Params> {
disableMenu: false,
beforeResolve: "",
afterResolve: "",
filenameChars: "[:keyword:]",

// display customize
displayFile: "file",
Expand Down
Loading