Skip to content

Commit 2b94bbd

Browse files
authored
Add new options beforeResolve and afterResolve (#15)
* update deps * Add new options beforeResolve and afterResolve
1 parent 1280c7d commit 2b94bbd

File tree

3 files changed

+93
-12
lines changed

3 files changed

+93
-12
lines changed

denops/@ddc-file/deps.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
export type {
22
Candidate,
33
Context,
4-
} from "https://deno.land/x/ddc_vim@v0.17.0/types.ts";
5-
export { BaseSource } from "https://deno.land/x/ddc_vim@v0.17.0/types.ts";
6-
export type { Denops } from "https://deno.land/x/ddc_vim@v0.17.0/deps.ts";
7-
export { fn, vars } from "https://deno.land/x/ddc_vim@v0.17.0/deps.ts";
4+
} from "https://deno.land/x/ddc_vim@v1.3.0/types.ts";
5+
export { BaseSource } from "https://deno.land/x/ddc_vim@v1.3.0/types.ts";
6+
export type { Denops } from "https://deno.land/x/ddc_vim@v1.3.0/deps.ts";
7+
export { fn, vars } from "https://deno.land/x/ddc_vim@v1.3.0/deps.ts";
88
export type {
99
GatherCandidatesArguments,
10-
} from "https://deno.land/x/ddc_vim@v0.17.0/base/source.ts";
11-
export * as path from "https://deno.land/std@0.111.0/path/mod.ts";
12-
export * as io from "https://deno.land/std@0.111.0/io/mod.ts";
13-
export * as fs from "https://deno.land/std@0.111.0/fs/mod.ts";
14-
export * as asserts from "https://deno.land/std@0.111.0/testing/asserts.ts";
10+
} from "https://deno.land/x/ddc_vim@v1.3.0/base/source.ts";
11+
export * as path from "https://deno.land/std@0.125.0/path/mod.ts";
12+
export * as io from "https://deno.land/std@0.125.0/io/mod.ts";
13+
export * as fs from "https://deno.land/std@0.125.0/fs/mod.ts";
14+
export * as asserts from "https://deno.land/std@0.125.0/testing/asserts.ts";
1515
export {
1616
asyncIteratorFrom as fromA,
1717
iteratorFrom as from,
1818
wrapAsyncIterator as wrapA,
1919
wrapIterator as wrap,
20-
} from "https://deno.land/x/iterator_helpers@v0.1.1/mod.ts";
21-
import homeDir from "https://deno.land/x/dir@v1.1.0/home_dir/mod.ts";
20+
} from "https://deno.land/x/iterator_helpers@v0.1.2/mod.ts";
21+
import homeDir from "https://deno.land/x/dir@v1.2.0/home_dir/mod.ts";
2222
export { homeDir };

denops/@ddc-sources/file.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Params = {
2626
trailingSlashAbbr: boolean;
2727
followSymlinks: boolean;
2828
disableMenu: boolean;
29+
beforeResolve: string;
30+
afterResolve: string;
2931

3032
// display customize
3133
displayFile: string;
@@ -231,7 +233,9 @@ export class Source extends BaseSource<Params> {
231233
.filter(({ asRoot }) => !isInputAbs || asRoot)
232234
.map((point) => ({
233235
...point,
234-
dir: path.normalize(path.join(point.dir, inputDirName)),
236+
dir: path.normalize(
237+
path.join(point.dir, p.beforeResolve, inputDirName, p.afterResolve),
238+
),
235239
}))
236240
.map(async (point) => ({
237241
point,
@@ -304,6 +308,8 @@ export class Source extends BaseSource<Params> {
304308
trailingSlashAbbr: true,
305309
followSymlinks: false,
306310
disableMenu: false,
311+
beforeResolve: "",
312+
afterResolve: "",
307313

308314
// display customize
309315
displayFile: "file",

doc/ddc-file.txt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ INTRODUCTION |ddc-file-introduction|
1111
DISPLAY RULES |ddc-file-display-rules|
1212
INSTALL |ddc-file-install|
1313
EXAMPLES |ddc-file-examples|
14+
BASIC EXAMPLES |ddc-file-example-basic|
15+
NODE MODULES EXAMPLES |ddc-file-example-node|
1416
PARAMS |ddc-file-params|
1517
FREQUENTLY ASKED QUESTIONS (FAQ) |ddc-file-faq|
1618

@@ -49,6 +51,11 @@ https://github.com/vim-denops/denops.vim
4951

5052
==============================================================================
5153
EXAMPLES *ddc-file-examples*
54+
55+
I welcome PRs for your useful ideas.
56+
57+
------------------------------------------------------------------------------
58+
BASIC EXAMPLE *ddc-file-example-basic*
5259
>
5360
call ddc#custom#patch_global('sources', ['file'])
5461
call ddc#custom#patch_global('sourceOptions', {
@@ -71,6 +78,60 @@ EXAMPLES *ddc-file-examples*
7178
\ }})
7279
<
7380

81+
------------------------------------------------------------------------------
82+
NODE MODULES EXAMPLE *ddc-file-example-node*
83+
84+
Find any files under node_modules/ folder from JS-family filetype buffers. You
85+
can see the completion when typing like `import ... from "<cursor>` in JS
86+
files. This collects files from up to 3 node_modules/ folders for example
87+
useful in monorepos.
88+
This config does not conflict with |ddc-file-example-basic|.
89+
>
90+
call ddc#custom#alias('source', 'node-modules', 'file')
91+
call ddc#custom#patch_global({
92+
\ 'sourceOptions': {
93+
\ 'node-modules': {
94+
\ 'mark': 'NODE',
95+
\ 'isVolatile': v:true,
96+
\ 'minAutoCompleteLength': 10000,
97+
\ 'forceCompletionPattern':
98+
\ '(?:'
99+
\ . '\bimport|'
100+
\ . '\bfrom|'
101+
\ . '\brequire\s*\(|'
102+
\ . '\bresolve\s*\(|'
103+
\ . '\bimport\s*\('
104+
\ . ')'
105+
\ . '\s*(?:''|"|`)[^''"`]*',
106+
\ },
107+
\ },
108+
\ 'sourceParams': {
109+
\ 'node-modules': {
110+
\ 'cwdMaxCandidates': 0,
111+
\ 'bufMaxCandidates': 0,
112+
\ 'followSymlinks': v:true,
113+
\ 'projMarkers': ['node_modules'],
114+
\ 'projFromCwdMaxCandidates': [],
115+
\ 'projFromBufMaxCandidates': [],
116+
\ 'beforeResolve': 'node_modules',
117+
\ 'displayBuf': '',
118+
\ },
119+
\ }})
120+
call ddc#custom#patch_filetype(
121+
\ [
122+
\ 'javascript',
123+
\ 'typescript',
124+
\ 'javascriptreact',
125+
\ 'typescriptreact',
126+
\ 'tsx',
127+
\ ], {
128+
\ 'sourceParams': {
129+
\ 'node-modules': {
130+
\ 'projFromBufMaxCandidates': [1000, 1000, 1000],
131+
\ },
132+
\ }})
133+
<
134+
74135
==============================================================================
75136
PARAMS *ddc-file-params*
76137

@@ -186,6 +247,20 @@ disableMenu (boolean)
186247

187248
Default: false
188249

250+
*ddc-file-params-beforeResolve*
251+
*ddc-file-params-afterResolve*
252+
beforeResolve (string) Default: ""
253+
afterResolve (string) Default: ""
254+
Your input will be transformed as join(find-root,
255+
beforeResolve, input, afterResolve). Empty strings are
256+
skipped. Path "find-root" denotes cwd/buf or found
257+
project-root by other settings. See |ddc-file-example-node|
258+
for example. You can specify absolute path to complete for
259+
specific folder, like with configuring
260+
`beforeResolve: '/usr/bin'` .
261+
262+
Default: ""
263+
189264
*ddc-file-params-displayFile*
190265
*ddc-file-params-displayDir*
191266
*ddc-file-params-displaySym*

0 commit comments

Comments
 (0)