Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Sep 13, 2023
1 parent f01d29b commit 56faf68
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ 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
autocmd dpp User DenopsReady
autocmd User DenopsReady
\ call dpp#make_state(s:dpp_base, '{your script path}')
endif
Expand Down
9 changes: 9 additions & 0 deletions autoload/dpp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ function dpp#source(plugins = g:dpp#_plugins->values()) abort
return dpp#source#_source(a:plugins)
endfunction

function dpp#make_state(base_path, config_path) abort
if !(a:config_path->filereadable())
call dpp#util#print_error(printf('"%s" is not found.', a:config_path))
return
endif

return dpp#denops#_notify('makeState', [a:base_path, a:config_path])
endfunction

function dpp#is_sudo() abort
return $SUDO_USER !=# '' && $USER !=# $SUDO_USER
\ && $HOME !=# ('~'.$USER)->expand()
Expand Down
80 changes: 40 additions & 40 deletions autoload/dpp/denops.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,45 @@
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#denops#_register()
if 'g:loaded_denops'->exists() && denops#server#status() ==# 'running'
silent! call dpp#denops#_register()
endif
endfunction

function dpp#denops#_denops_running() abort
return 'g:loaded_denops'->exists()
\ && denops#server#status() ==# 'running'
\ && denops#plugin#is_loaded('dpp')
endfunction

function s:stopped() abort
unlet! s:initialized
endfunction

function dpp#denops#_request(method, args) abort
if s:init()
return {}
endif

if !dpp#_denops_running()
if !dpp#denops#_denops_running()
" Lazy call request
execute printf('autocmd User DenopsPluginPost:dpp call '
\ .. 's:notify("%s", %s)', a:method, a:args->string())
Expand All @@ -20,7 +56,7 @@ function dpp#denops#_notify(method, args) abort
return {}
endif

if !dpp#_denops_running()
if !dpp#denops#_denops_running()
" Lazy call notify
execute printf('autocmd User DenopsPluginPost:dpp call '
\ .. 's:notify("%s", %s)', a:method, a:args->string())
Expand All @@ -39,48 +75,12 @@ function s:notify(method, args) abort
endif
endfunction

const s:root_dir = '<sfile>'->expand()->fnamemodify(':h:h')
const s:root_dir = '<sfile>'->expand()->fnamemodify(':h:h:h')
const s:sep = has('win32') ? '\' : '/'
function dpp#_register() abort
function dpp#denops#_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
24 changes: 24 additions & 0 deletions denops/@dpp-exts/local.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
Actions,
BaseExt,
} from "../dpp/types.ts";
import {
Denops,
} from "../dpp/deps.ts";

type Params = Record<string, never>;

export class Ext extends BaseExt<Params> {
override actions: Actions<Params> = {
local: {
description: "Load local plugins",
callback: async (args: { denops: Denops }) => {
console.log("hello");
},
},
}

override params(): Params {
return {};
}
}
6 changes: 3 additions & 3 deletions denops/dpp/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export function main(denops: Denops) {
denops.dispatcher = {
async makeState(arg1: unknown, arg2: unknown): Promise<void> {
const basePath = ensure(arg1, is.String);
const scriptPath = ensure(arg2, is.String);
const configPath = ensure(arg2, is.String);

// NOTE: Import module with fragment so that reload works properly.
// https://github.com/vim-denops/denops.vim/issues/227
const mod = await import(
`${toFileUrl(scriptPath).href}#${performance.now()}`
`${toFileUrl(configPath).href}#${performance.now()}`
);
const obj = new mod.Config();
await obj.config({ denops, basePath, contextBuilder });
await obj.config({ denops, basePath, contextBuilder, dpp });

return Promise.resolve();
},
Expand Down
4 changes: 3 additions & 1 deletion denops/dpp/base/ext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Denops } from "../deps.ts";
import { Actions } from "../types.ts";

export type BaseExtParams = Record<string, unknown>;

Expand All @@ -10,4 +10,6 @@ export abstract class BaseExt<Params extends BaseExtParams> {
isInitialized = false;

abstract params(): Params;

actions: Actions<Params> = {};
}
4 changes: 4 additions & 0 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ActionName, ExtName } from "./types.ts";
import { Loader } from "./loader.ts";
import { errorException } from "./utils.ts";

Expand All @@ -7,4 +8,7 @@ export class Dpp {
constructor(loader: Loader) {
this.loader = loader;
}

async extAction(extName: ExtName, actionName: ActionName, params: unknown) {
}
}
27 changes: 27 additions & 0 deletions denops/dpp/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BaseExtParams } from "./base/ext.ts";
import { BaseProtocolParams } from "./base/protocol.ts";
import { Denops } from "./deps.ts";

export { BaseConfig } from "./base/config.ts";
export { BaseExt } from "./base/ext.ts";
Expand All @@ -15,6 +16,7 @@ export type DppExtType = "ext" | "protocol";

export type ExtName = string;
export type ProtocolName = string;
export type ActionName = string;

export type Context = {
// TODO: remove placeholder
Expand All @@ -39,3 +41,28 @@ export type ProtocolOptions = {
// TODO: remove placeholder
placeholder?: unknown;
};

export type BaseActionParams = Record<string, unknown>;

export type ActionArguments<Params extends BaseActionParams> = {
denops: Denops;
context: Context;
options: DppOptions;
extOptions: ExtOptions;
extParams: Params;
actionParams: unknown;
};

export type ActionCallback<Params extends BaseExtParams> = (
args: ActionArguments<Params>,
) => unknown;

export type Actions<Params extends BaseActionParams> = Record<
ActionName,
Action<Params>
>;

export type Action<Params extends BaseActionParams> = {
description: string;
callback: ActionCallback<Params>;
};
2 changes: 1 addition & 1 deletion doc/dpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ EXAMPLES *dpp-examples*
if dpp#load_state(s:dpp_base)
" NOTE: dpp#make_state() requires denops.vim
execute 'set runtimepath+=' .. s:denops_src
autocmd dpp User DenopsReady
autocmd User DenopsReady
\ call dpp#make_state(s:dpp_base, '{your script path}')
endif
Expand Down

0 comments on commit 56faf68

Please sign in to comment.