From 06688443f6ee322699c89051483bd670fcdbd610 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 5 Sep 2023 20:39:23 +0900 Subject: [PATCH] Split denops functions --- README.md | 8 ++-- autoload/dpp.vim | 82 --------------------------------------- autoload/dpp/denops.vim | 86 +++++++++++++++++++++++++++++++++++++++++ denops/dpp/app.ts | 4 +- denops/dpp/context.ts | 6 +-- doc/dpp.txt | 64 ++++++++++++++++++++++++++++-- 6 files changed, 157 insertions(+), 93 deletions(-) create mode 100644 autoload/dpp/denops.vim diff --git a/README.md b/README.md index 90da601..94da318 100644 --- a/README.md +++ b/README.md @@ -87,12 +87,14 @@ execute 'set runtimepath+=' .. s:dpp_src if dpp#load_state(s:dpp_base) " NOTE: dpp#make_state() requires denops.vim execute 'set runtimepath+=' .. s:denops_src - call dpp#make_state(s:dpp_base, '{your script path}') + autocmd dpp User DenopsReady + \ call dpp#make_state(s:dpp_base, '{your script path}') endif " Attempt to determine the type of a file based on its name and -" possibly its " contents. Use this to allow intelligent auto-indenting -" for each filetype, and for plugins that are filetype specific. +" possibly its " contents. Use this to allow intelligent +" auto-indenting " for each filetype, and for plugins that are +" filetype specific. filetype indent plugin on " Enable syntax highlighting diff --git a/autoload/dpp.vim b/autoload/dpp.vim index 3d6fe5d..b7416a3 100644 --- a/autoload/dpp.vim +++ b/autoload/dpp.vim @@ -1,88 +1,6 @@ function dpp#load_state(path) abort endfunction -function dpp#_request(method, args) abort - if s:init() - return {} - endif - - if !dpp#_denops_running() - " Lazy call request - execute printf('autocmd User DenopsPluginPost:dpp call ' - \ .. 's:notify("%s", %s)', a:method, a:args->string()) - return {} - endif - - if denops#plugin#wait('dpp') - return {} - endif - return denops#request('dpp', a:method, a:args) -endfunction -function dpp#_notify(method, args) abort - if s:init() - return {} - endif - - if !dpp#_denops_running() - " Lazy call notify - execute printf('autocmd User DenopsPluginPost:dpp call ' - \ .. 's:notify("%s", %s)', a:method, a:args->string()) - return {} - endif - - return s:notify(a:method, a:args) -endfunction - -const s:root_dir = ''->expand()->fnamemodify(':h:h') -const s:sep = has('win32') ? '\' : '/' -function dpp#_register() abort - call denops#plugin#register('dpp', - \ [s:root_dir, 'denops', 'dpp', 'app.ts']->join(s:sep), - \ #{ mode: 'skip' }) - - autocmd dpp User DenopsClosed call s:stopped() -endfunction - -function dpp#_denops_running() abort - return 'g:loaded_denops'->exists() - \ && denops#server#status() ==# 'running' - \ && denops#plugin#is_loaded('dpp') -endfunction - -function dpp#_lazy_redraw(name, args = {}) abort - call timer_start(0, { -> dpp#redraw(a:name, a:args) }) -endfunction - -function s:init() abort - if 's:initialized'->exists() - return - endif - - if !has('patch-9.0.1276') && !has('nvim-0.10') - call dpp#util#_error('dpp.vim requires Vim 9.0.1276+ or NeoVim 0.10+.') - return 1 - endif - - augroup dpp - autocmd! - autocmd User DenopsPluginPost:dpp let s:initialized = v:true - augroup END - - let g:dpp#_started = reltime() - - " NOTE: dpp.vim must be registered manually. - - " NOTE: denops load may be started - autocmd dpp User DenopsReady silent! call dpp#_register() - if 'g:loaded_denops'->exists() && denops#server#status() ==# 'running' - silent! call dpp#_register() - endif -endfunction - -function s:stopped() abort - unlet! s:initialized -endfunction - function dpp#begin(path, options = {}) abort if !has('patch-9.0.1276') && !has('nvim-0.10') call dpp#util#_error('dpp.vim requires Vim 9.0.1276+ or NeoVim 0.10+.') diff --git a/autoload/dpp/denops.vim b/autoload/dpp/denops.vim new file mode 100644 index 0000000..32b0bff --- /dev/null +++ b/autoload/dpp/denops.vim @@ -0,0 +1,86 @@ +function dpp#denops#_request(method, args) abort + if s:init() + return {} + endif + + if !dpp#_denops_running() + " Lazy call request + execute printf('autocmd User DenopsPluginPost:dpp call ' + \ .. 's:notify("%s", %s)', a:method, a:args->string()) + return {} + endif + + if denops#plugin#wait('dpp') + return {} + endif + return denops#request('dpp', a:method, a:args) +endfunction +function dpp#denops#_notify(method, args) abort + if s:init() + return {} + endif + + if !dpp#_denops_running() + " Lazy call notify + execute printf('autocmd User DenopsPluginPost:dpp call ' + \ .. 's:notify("%s", %s)', a:method, a:args->string()) + return {} + endif + + return s:notify(a:method, a:args) +endfunction + +function s:notify(method, args) abort + if denops#plugin#is_loaded('dpp') + call denops#notify('dpp', a:method, a:args) + else + call denops#plugin#wait_async('dpp', + \ { -> denops#notify('dpp', a:method, a:args) }) + endif +endfunction + +const s:root_dir = ''->expand()->fnamemodify(':h:h') +const s:sep = has('win32') ? '\' : '/' +function dpp#_register() abort + call denops#plugin#register('dpp', + \ [s:root_dir, 'denops', 'dpp', 'app.ts']->join(s:sep), + \ #{ mode: 'skip' }) + + autocmd dpp User DenopsClosed call s:stopped() +endfunction + +function dpp#denops#_denops_running() abort + return 'g:loaded_denops'->exists() + \ && denops#server#status() ==# 'running' + \ && denops#plugin#is_loaded('dpp') +endfunction + +function s:init() abort + if 's:initialized'->exists() + return + endif + + if !has('patch-9.0.1276') && !has('nvim-0.10') + call dpp#util#_error('dpp.vim requires Vim 9.0.1276+ or NeoVim 0.10+.') + return 1 + endif + + augroup dpp + autocmd! + autocmd User DenopsPluginPost:dpp let s:initialized = v:true + augroup END + + let g:dpp#_started = reltime() + + " NOTE: dpp.vim must be registered manually. + + " NOTE: denops load may be started + autocmd dpp User DenopsReady silent! call dpp#_register() + if 'g:loaded_denops'->exists() && denops#server#status() ==# 'running' + silent! call dpp#_register() + endif +endfunction + +function s:stopped() abort + unlet! s:initialized +endfunction diff --git a/denops/dpp/app.ts b/denops/dpp/app.ts index 0ac6da3..08d9636 100644 --- a/denops/dpp/app.ts +++ b/denops/dpp/app.ts @@ -1,10 +1,12 @@ import { Denops, ensure, is, toFileUrl } from "./deps.ts"; +import { ContextBuilder } from "./context.ts"; import { Dpp } from "./dpp.ts"; import { Loader } from "./loader.ts"; export function main(denops: Denops) { const loader = new Loader(); const dpp = new Dpp(loader); + const contextBuilder = new ContextBuilder(); denops.dispatcher = { async makeState(arg1: unknown, arg2: unknown): Promise { @@ -17,7 +19,7 @@ export function main(denops: Denops) { `${toFileUrl(scriptPath).href}#${performance.now()}` ); const obj = new mod.Config(); - await obj.config({ denops, basePath }); + await obj.config({ denops, basePath, contextBuilder }); return Promise.resolve(); }, diff --git a/denops/dpp/context.ts b/denops/dpp/context.ts index 42ea9fa..9b1e2a5 100644 --- a/denops/dpp/context.ts +++ b/denops/dpp/context.ts @@ -150,10 +150,9 @@ function patchDppOptions( class Custom { global: Partial = {}; - get(userOptions: UserOptions): DppOptions { + get(): DppOptions { return foldMerge(mergeDppOptions, defaultDppOptions, [ this.global, - userOptions, ]); } @@ -172,9 +171,8 @@ export class ContextBuilder { async get( denops: Denops, - options: UserOptions, ): Promise<[Context, DppOptions]> { - const userOptions = this.custom.get(options); + const userOptions = this.custom.get(); await this.validate(denops, "options", userOptions, defaultDppOptions()); diff --git a/doc/dpp.txt b/doc/dpp.txt index 3ae7f81..2290210 100644 --- a/doc/dpp.txt +++ b/doc/dpp.txt @@ -8,7 +8,15 @@ CONTENTS *dpp-contents* Introduction |dpp-introduction| Install |dpp-install| Interface |dpp-interface| + Options |dpp-options| + Functions |dpp-functions| Examples |dpp-examples| +Exts |dpp-exts| + Ext option |dpp-ext-options| + Ext params |dpp-ext-params| +Protocols |dpp-protocols| + Protocol option |dpp-protocol-options| + Protocol params |dpp-protocol-params| FAQ |dpp-faq| Compatibility |dpp-compatibility| @@ -42,6 +50,13 @@ You can search dpp.vim plugins from https://github.com/topics/dpp-vim. ============================================================================== INTERFACE *dpp-interface* +------------------------------------------------------------------------------ +OPTIONS *dpp-options* + +------------------------------------------------------------------------------ +FUNCTIONS *dpp-functions* + + ============================================================================== EXAMPLES *dpp-examples* > @@ -62,12 +77,14 @@ EXAMPLES *dpp-examples* if dpp#load_state(s:dpp_base) " NOTE: dpp#make_state() requires denops.vim execute 'set runtimepath+=' .. s:denops_src - call dpp#make_state(s:dpp_base, '{your script path}') + autocmd dpp User DenopsReady + \ call dpp#make_state(s:dpp_base, '{your script path}') endif " Attempt to determine the type of a file based on its name and - " possibly its " contents. Use this to allow intelligent auto-indenting - " for each filetype, and for plugins that are filetype specific. + " possibly its " contents. Use this to allow intelligent + " auto-indenting " for each filetype, and for plugins that are + " filetype specific. filetype indent plugin on " Enable syntax highlighting @@ -76,6 +93,47 @@ EXAMPLES *dpp-examples* endif < +============================================================================== +EXTS *dpp-exts* + +NOTE: The Exts are not bundled in dpp.vim. You need to install them +to use dpp.vim. Please search them by https://github.com/topics/dpp-ext + + +------------------------------------------------------------------------------ +EXT OPTIONS *dpp-ext-options* + +NOTE: The Exts cannot set default options. If they need to specify the +recommended configuration, you should write it in the documentation instead. + + +------------------------------------------------------------------------------ +EXT PARAMS *dpp-ext-params* + +These are the parameters that each Ext can have. Please read the Ext +documentation. + + +============================================================================== +PROTOCOLS *dpp-protocols* + +NOTE: The Protocols are not bundled in dpp.vim. You need to install them +to use dpp.vim. Please search them by https://github.com/topics/dpp-protocol + + +------------------------------------------------------------------------------ +PROTOCOL OPTIONS *dpp-protocol-options* + +NOTE: The Protocols cannot set default options. If they need to specify the +recommended configuration, you should write it in the documentation instead. + +------------------------------------------------------------------------------ +PROTOCOL PARAMS *dpp-protocol-params* + +These are the parameters that each Protocol can have. Please read the +Protocol documentation. + + ============================================================================== FAQ *dpp-faq*