1
1
// Import 'start' function from denops_std
2
- import { main } from "https://deno.land/x/[email protected] /mod.ts" ;
2
+ import {
3
+ ensureString ,
4
+ main ,
5
+ } from "https://deno.land/x/[email protected] /mod.ts" ;
3
6
4
7
// Call 'main' with async callback. The callback get RunnerContext.
5
8
main ( async ( { vim } ) => {
@@ -8,44 +11,23 @@ main(async ({ vim }) => {
8
11
// Developers can define multiple endpoints which take arbitrary number of arguments
9
12
// and return arbitrary value as a Promise.
10
13
// This function can be called by denops#request() or denops#notify() functions.
11
- async echo ( text : unknown ) : Promise < unknown > {
12
- if ( typeof text !== "string" ) {
13
- throw new Error ( `'text' in 'echo()' of ${ vim . name } must be a string` ) ;
14
- }
15
- // console.log (console.info, console.debug as well) output message to Vim echo
16
- // area with [denops] prefix.
17
- console . log ( "echo is called" ) ;
18
-
19
- // console.error (console.warn, console.critical as well) output message to Vim
20
- // echo area with [denops] prefix as error message
21
- console . error ( "echo is not really implemented yet" ) ;
22
-
23
- return await Promise . resolve ( text ) ;
24
- } ,
25
-
26
- async hello ( app : unknown ) : Promise < void > {
27
- if ( typeof app !== "string" ) {
28
- throw new Error ( `'app' in 'say()' of ${ vim . name } must be a string` ) ;
29
- }
30
-
31
- // Use 'vim.call(func, ...args)' to call Vim's function and get result
14
+ async say ( where : unknown ) : Promise < void > {
15
+ // Ensure that `prefix` is 'string' here
16
+ ensureString ( where , "where" ) ;
17
+ // Use `call` to call Vim's function
32
18
const name = await vim . call ( "input" , "Your name: " ) ;
33
- console . log ( "name" , name ) ;
34
-
35
- // Use 'vim.eval(expr, context)' to evaluate Vim's expression and get result
36
- const result = await vim . eval ( "1 + 1 + value" , {
37
- value : 2 ,
19
+ // Use `eval` to evaluate Vim's expression
20
+ const progname = await vim . eval ( "v:progname" ) ;
21
+ // Construct messages
22
+ const messages = [
23
+ `Hello ${ where } ` ,
24
+ `Your name is ${ name } ` ,
25
+ `This is ${ progname } ` ,
26
+ ] ;
27
+ // Use `cmd` to execute Vim's command
28
+ await vim . cmd ( `redraw | echomsg message` , {
29
+ message : messages . join ( ". " ) ,
38
30
} ) ;
39
- console . log ( "result" , result ) ;
40
-
41
- // Use 'vim.cmd(cmd, context)' to execute Vim's ex command
42
- await vim . cmd (
43
- `echomsg printf('Hello %s. Your are using ${ app } in Vim/Neovim: %s', name, result)` ,
44
- {
45
- name,
46
- result,
47
- } ,
48
- ) ;
49
31
} ,
50
32
51
33
async get_variables ( ) : Promise < void > {
@@ -110,12 +92,8 @@ main(async ({ vim }) => {
110
92
111
93
// Use 'vim.execute()' to execute Vim script
112
94
await vim . execute ( `
113
- command! DenopsEcho echo denops#request("${ vim . name } ", "echo", ["This is hello world message"])
114
- command! DenopsHello echo denops#notify("${ vim . name } ", "hello", ["Denops"])
115
- command! DenopsGetVariables echo denops#notify("${ vim . name } ", "get_variables", [])
116
- command! DenopsSetVariables echo denops#notify("${ vim . name } ", "set_variables", [])
117
- command! DenopsRemoveVariables echo denops#notify("${ vim . name } ", "remove_variables", [])
118
- command! DenopsRegisterAutocmd echo denops#notify("${ vim . name } ", "register_autocmd", [])
95
+ command! HelloWorld call denops#notify("${ vim . name } ", "say", ["World"])
96
+ command! HelloDenops call denops#notify("${ vim . name } ", "say", ["Denops"])
119
97
` ) ;
120
98
121
99
console . log ( "denops-helloworld.vim (std) has loaded" ) ;
0 commit comments