Skip to content

Commit

Permalink
Split denops functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Sep 5, 2023
1 parent 2f24301 commit 0668844
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 93 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 0 additions & 82 deletions autoload/dpp.vim
Original file line number Diff line number Diff line change
@@ -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 = '<sfile>'->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+.')
Expand Down
86 changes: 86 additions & 0 deletions autoload/dpp/denops.vim
Original file line number Diff line number Diff line change
@@ -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 = '<sfile>'->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
4 changes: 3 additions & 1 deletion denops/dpp/app.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
Expand All @@ -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();
},
Expand Down
6 changes: 2 additions & 4 deletions denops/dpp/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ function patchDppOptions(
class Custom {
global: Partial<DppOptions> = {};

get(userOptions: UserOptions): DppOptions {
get(): DppOptions {
return foldMerge(mergeDppOptions, defaultDppOptions, [
this.global,
userOptions,
]);
}

Expand All @@ -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());

Expand Down
64 changes: 61 additions & 3 deletions doc/dpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|

Expand Down Expand Up @@ -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*
>
Expand All @@ -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
Expand All @@ -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*

Expand Down

0 comments on commit 0668844

Please sign in to comment.