diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3e5d72..40a01af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/autoload/ddc_file/internal.vim b/autoload/ddc_file/internal.vim index c6d97fa..cd00bde 100644 --- a/autoload/ddc_file/internal.vim +++ b/autoload/ddc_file/internal.vim @@ -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 @@ -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 diff --git a/denops/@ddc-file/deps.ts b/denops/@ddc-file/deps.ts index 31768d4..2940381 100644 --- a/denops/@ddc-file/deps.ts +++ b/denops/@ddc-file/deps.ts @@ -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, diff --git a/denops/@ddc-file/internal_autoload_fn.ts b/denops/@ddc-file/internal_autoload_fn.ts index 5b5531a..87218b1 100644 --- a/denops/@ddc-file/internal_autoload_fn.ts +++ b/denops/@ddc-file/internal_autoload_fn.ts @@ -12,6 +12,7 @@ const createCaller = (name: string): any => { export type Info = ( denops: Denops, inputLine: string, + filenameChars: string, isPosix: boolean, ) => Promise<[ string, diff --git a/denops/@ddc-sources/file.ts b/denops/@ddc-sources/file.ts index c022ed9..29d6760 100644 --- a/denops/@ddc-sources/file.ts +++ b/denops/@ddc-sources/file.ts @@ -28,6 +28,7 @@ type Params = { disableMenu: boolean; beforeResolve: string; afterResolve: string; + filenameChars: string; // display customize displayFile: string; @@ -85,6 +86,7 @@ export class Source extends BaseSource { const [inputFileFull, inputFileBasePrefix, bufPath] = await internal.info( args.denops, args.context.input, + args.sourceParams.filenameChars, mode === "posix", ); @@ -309,6 +311,7 @@ export class Source extends BaseSource { disableMenu: false, beforeResolve: "", afterResolve: "", + filenameChars: "[:keyword:]", // display customize displayFile: "file", diff --git a/doc/ddc-file.txt b/doc/ddc-file.txt index aa4acb0..c9a70fc 100644 --- a/doc/ddc-file.txt +++ b/doc/ddc-file.txt @@ -36,10 +36,10 @@ that completion got from. ^--- (d) project-root search recursion level (1 is omitted) < -It can be disabled by |ddc-file-params-disableMenu| and customized by +It can be disabled by |ddc-file-param-disableMenu| and customized by following. -- |ddc-file-params-displayCwd| -- |ddc-file-params-displayBuf| +- |ddc-file-param-displayCwd| +- |ddc-file-param-displayBuf| ============================================================================== INSTALL *ddc-file-install* @@ -185,7 +185,8 @@ projFromCwdMaxItems (number[]) |- .git/ |- src/ <-- cwd |- my-document.txt - If [10] is set, sub-project/ is only found with up to 10 files. + If [10] is set, sub-project/ is only found with up to 10 + files. If [10, 5] is set, sub-project/ is found with up to 10 files and my-project/ is also found with up to 5 files. @@ -194,11 +195,11 @@ projFromCwdMaxItems (number[]) *ddc-file-param-projFromBufMaxItems* projFromBufMaxItems (number[]) Project-root from buffer relative version of - |ddc-file-params-projFromCwdMaxItems|. + |ddc-file-param-projFromCwdMaxItems|. Default: [1000] - *ddc-file-params-cwdAsRoot* + *ddc-file-param-cwdAsRoot* cwdAsRoot (boolean) Set to true to complete from cwd even if the input is absolute path. e.g. the input is '/REA', and there is @@ -206,33 +207,33 @@ cwdAsRoot (boolean) Default: false - *ddc-file-params-bufAsRoot* + *ddc-file-param-bufAsRoot* bufAsRoot (boolean) - Buffer relative version of |ddc-file-params-cwdAsRoot|. + Buffer relative version of |ddc-file-param-cwdAsRoot|. Default: false - *ddc-file-params-projAsRoot* + *ddc-file-param-projAsRoot* projAsRoot (boolean) - Project-root relative version of |ddc-file-params-cwdAsRoot|. + Project-root relative version of |ddc-file-param-cwdAsRoot|. Default: true - *ddc-file-params-trailingSlash* + *ddc-file-param-trailingSlash* trailingSlash (boolean) Whether to include trailing slash when completing directory name. Default: false - *ddc-file-params-trailingSlashAbbr* + *ddc-file-param-trailingSlashAbbr* trailingSlashAbbr (boolean) Whether to display trailing slash when completing directory name. Note that this won't be actually inserted. Default: true - *ddc-file-params-followSymlinks* + *ddc-file-param-followSymlinks* followSymlinks (boolean) Whether to follow symlinks to determine whether the filename completing is file or directory. Note that, if you are trying @@ -241,14 +242,14 @@ followSymlinks (boolean) Default: false - *ddc-file-params-disableMenu* + *ddc-file-param-disableMenu* disableMenu (boolean) Disable to show menu like `buf^`. |ddc-file-display-rules| Default: false - *ddc-file-params-beforeResolve* - *ddc-file-params-afterResolve* + *ddc-file-param-beforeResolve* + *ddc-file-param-afterResolve* beforeResolve (string) Default: "" afterResolve (string) Default: "" Your input will be transformed as join(find-root, @@ -261,23 +262,30 @@ afterResolve (string) Default: "" Default: "" - *ddc-file-params-displayFile* - *ddc-file-params-displayDir* - *ddc-file-params-displaySym* - *ddc-file-params-displaySymDir* - *ddc-file-params-displaySymFile* + *ddc-file-param-filenameChars* +filenameChars (string) + The characters as filename pattern. + The pattern is |/collection| pattern. + + Default: "[:keyword:]" + + *ddc-file-param-displayFile* + *ddc-file-param-displayDir* + *ddc-file-param-displaySym* + *ddc-file-param-displaySymDir* + *ddc-file-param-displaySymFile* displayFile (string) Default: "file" displayDir (string) Default: "dir" displaySym (string) Default: "sym" displaySymFile (string) Default: "sym=file" displaySymDir (string) Default: "sym=dir" Texts to show as kind of completed item. To disable, set empty - strings. + strings. `displaySymFile` and `displaySymDir` are only used when - |ddc-file-params-followSymlinks| is set to `true`. + |ddc-file-param-followSymlinks| is set to `true`. - *ddc-file-params-displayCwd* - *ddc-file-params-displayBuf* + *ddc-file-param-displayCwd* + *ddc-file-param-displayBuf* displayCwd (string) Default: "cwd" displayBuf (string) Default: "buf" Texts to show as menu of completed item. @@ -288,13 +296,21 @@ FREQUENTLY ASKED QUESTIONS (FAQ) *ddc-file-faq* Q: How to complete paths including spaces or punctuations? -A. ddc-file respects value of |'isfname'| for backward searching, but as -described in |'isfname'|, it's not recommended to treat paths including such +A. ddc-file respects value of 'isfname' for backward searching, but as +described in 'isfname', it's not recommended to treat paths including such special characters. If you still want, I cannot stop you, please try this. > - :set isfname+=32,40-41 + :set isfname+=32,40-41 < Please take care that leading spaces are also treated as part of path. +Q: I want to include "." as filename pattern. + +A. You can change the pattern by |ddc-file-param-filenameChars|. +> + call ddc#custom#patch_global('sourceParams', { + \ 'file': {'filenameChars': '[:keyword:].'}, + \ }) + ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl