diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml index e3c82979..62d89c21 100644 --- a/.github/workflows/deno.yml +++ b/.github/workflows/deno.yml @@ -25,6 +25,7 @@ jobs: - name: Check Type run: | + echo "export const mods = {};" > denops/ddc/_mods.js find denops -name "*.ts"| xargs deno test --unstable --no-run -A - name: Check with deno lint @@ -44,5 +45,6 @@ jobs: - name: Test run: | + echo "export const mods = {};" > denops/ddc/_mods.js grep -rl Deno.test denops| xargs deno test --unstable -A timeout-minutes: 5 diff --git a/.gitignore b/.gitignore index 44be1583..1aab5073 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -vim-themis/ +denops/ddc/_mods.js diff --git a/autoload/ddc.vim b/autoload/ddc.vim index 79fd8754..8acc3ea3 100644 --- a/autoload/ddc.vim +++ b/autoload/ddc.vim @@ -21,9 +21,20 @@ function ddc#enable(opts = {}) abort silent! call context_filetype#get_filetype() endif + " Create default mods file. + const mods = [s:root_dir, 'denops', 'ddc', '_mods.js']->join(s:sep) + if !(mods->filereadable()) + call writefile([ + \ 'export const mods = {};', + \ ], mods) + endif + let g:ddc#_started = reltime() let g:ddc#_context_filetype = context_filetype let g:ddc#_skip_next_complete = 0 + if !('g:ddc#_mods'->exists()) + const g:ddc#_mods = mods + endif " NOTE: ddc.vim must be registered manually. autocmd ddc User DenopsReady silent! call ddc#_register() @@ -99,8 +110,8 @@ function ddc#update_items(name, items) abort call ddc#_notify('updateItems', [a:name, a:items]) endfunction -function ddc#set_static_import_path(path) abort - call ddc#_notify('setStaticImportPath', [a:path]) +function ddc#set_static_import_path() abort + call ddc#_notify('setStaticImportPath', []) endfunction function ddc#on_event(event) abort diff --git a/denops/ddc/app.ts b/denops/ddc/app.ts index b987ed71..75ad1465 100644 --- a/denops/ddc/app.ts +++ b/denops/ddc/app.ts @@ -128,8 +128,8 @@ export function main(denops: Denops) { getCurrent(): Promise { return Promise.resolve(contextBuilder.getCurrent(denops)); }, - async setStaticImportPath(arg1: unknown): Promise { - await loader.initStaticImportPath(denops, arg1 as string); + async setStaticImportPath(): Promise { + await loader.initStaticImportPath(denops); return Promise.resolve(); }, async getPreviewer(arg1: unknown, arg2: unknown): Promise { diff --git a/denops/ddc/loader.ts b/denops/ddc/loader.ts index bc5c2e21..f0d8c0b6 100644 --- a/denops/ddc/loader.ts +++ b/denops/ddc/loader.ts @@ -10,8 +10,8 @@ import { SourceName, UiName, } from "./types.ts"; -import { basename, Denops, fn, Lock, op, parse, toFileUrl } from "./deps.ts"; -import { safeStat } from "./utils.ts"; +import { basename, Denops, fn, Lock, op, parse, toFileUrl, vars } from "./deps.ts"; +import { mods } from "./_mods.js"; export class Loader { private uis: Record> = {}; @@ -26,21 +26,45 @@ export class Loader { private registerLock = new Lock(0); private cachedPaths: Record = {}; private prevRuntimepath = ""; - private staticImportMod: Record = {}; - async initStaticImportPath(denops: Denops, path: string) { - if (Object.values(this.staticImportMod).length !== 0) { - return; + async initStaticImportPath(denops: Denops) { + // Generate _mods.ts + let mods: string[] = []; + const runtimepath = await op.runtimepath.getGlobal(denops); + for ( + const glob of [ + "denops/@ddu-columns/*.ts", + "denops/@ddu-filters/*.ts", + "denops/@ddu-kinds/*.ts", + "denops/@ddu-sources/*.ts", + "denops/@ddu-uis/*.ts", + ] + ) { + mods = mods.concat( + await fn.globpath( + denops, + runtimepath, + glob, + 1, + 1, + ), + ); } - path = await fn.expand(denops, path) as string; - if (!await safeStat(path)) { - return; + const staticLines = []; + for (const [index, path] of mods.entries()) { + staticLines.push(`import * as mod${index} from "file://${path}"`); } - - //const startTime = Date.now(); - this.staticImportMod = (await import(toFileUrl(path).href)).mods; - //console.log(`${Date.now() - startTime} ms`); + staticLines.push("export const mods = {"); + for (const [index, path] of mods.entries()) { + staticLines.push(` "${path}":`); + staticLines.push(` mod${index},`); + } + staticLines.push("};"); + await Deno.writeTextFile( + await vars.g.get(denops, "ddc#_mods"), + staticLines.join("\n"), + ); } async autoload( @@ -99,7 +123,7 @@ export class Loader { const name = parse(path).name; - const mod = this.staticImportMod[path] ?? + const mod = (mods as Record)[path] ?? await import(toFileUrl(path).href); let add; diff --git a/doc/ddc.txt b/doc/ddc.txt index 0bdb554b..309e230e 100644 --- a/doc/ddc.txt +++ b/doc/ddc.txt @@ -355,9 +355,9 @@ ddc#register({type}, {path}) *ddc#set_static_import_path()* ddc#set_static_import_path() - Set the path of staticImport file to optimize load ddc - extensions. - It is generated by "dpp.vim" |dpp-option-convertImportPaths|. + Make static import file to optimize load ddu extensions from + current 'runtimepath'. + NOTE: It should be called if you have updated plugins. *ddc#skip_next_complete()* ddc#skip_next_complete() @@ -1530,11 +1530,15 @@ https://github.com/Shougo/pum.vim *ddc-faq-21* Q: ddc.vim starting is slow. -A: It may be slow in Windows environment. You should use denops shared server +A: It may be slow in Windows environment. You can use denops shared server feature. https://github.com/vim-denops/denops.vim#shared-server +Or you can create static import file by |ddc#set_static_import_path()|. + +Or ignore deno cache directory "%LOCALAPPDATA%\deno" from anti virus scan. + *ddc-faq-22* Q: ddc.vim does not work in |command-line-window|. @@ -1629,6 +1633,9 @@ https://github.com/Shougo/ddc-ui-pum ============================================================================== COMPATIBILITY *ddc-compatibility* +2023.12.06 +* Change "ddc#set_static_import_path()" spec. + 2023.12.04 * Rename "util.ts" to "utils.ts".