File tree Expand file tree Collapse file tree 2 files changed +51
-12
lines changed Expand file tree Collapse file tree 2 files changed +51
-12
lines changed Original file line number Diff line number Diff line change @@ -6,21 +6,21 @@ import type {
6
6
/**
7
7
* Execute Vim script directly
8
8
*/
9
- export async function execute (
9
+ export function execute (
10
10
denops : Denops ,
11
11
script : string | string [ ] ,
12
12
ctx : Context = { } ,
13
13
) : Promise < void > {
14
- if ( Array . isArray ( script ) ) {
15
- ctx = {
16
- ...ctx ,
17
- __denops_internal_command : script
18
- . map ( ( x ) => x . replace ( / ^ \s + | \s + $ / g, "" ) )
19
- . filter ( ( x ) => ! ! x ) ,
20
- } ;
21
- await denops . cmd ( "call execute(l:__denops_internal_command, '')" , ctx ) ;
22
- return ;
14
+ if ( ! Array . isArray ( script ) ) {
15
+ // join line-continuation
16
+ script = script . replace ( / \r ? \n \s * \\ / g, "" ) ;
17
+ // convert to array
18
+ script = script . split ( / \r ? \n / g) ;
23
19
}
24
- script = script . replace ( / \r ? \n \s * \\ / g, "" ) ;
25
- await execute ( denops , script . split ( / \r ? \n / g) , ctx ) ;
20
+ script = script . map ( ( x ) => x . trimStart ( ) ) . filter ( ( x ) => ! ! x ) ;
21
+ ctx = {
22
+ ...ctx ,
23
+ __denops_internal_command : script ,
24
+ } ;
25
+ return denops . cmd ( "call execute(l:__denops_internal_command, '')" , ctx ) ;
26
26
}
Original file line number Diff line number Diff line change 1
1
import {
2
2
assertEquals ,
3
+ assertInstanceOf ,
3
4
assertRejects ,
4
5
} from "https://deno.land/std@0.167.0/testing/asserts.ts" ;
5
6
import { test } from "https://deno.land/x/denops_core@v3.2.2/test/mod.ts" ;
@@ -75,3 +76,41 @@ test({
75
76
assertEquals ( await denops . eval ( "g:denops_std_execute_test" ) as number , 25 ) ;
76
77
} ,
77
78
} ) ;
79
+
80
+ test ( {
81
+ mode : "any" ,
82
+ name : "execute() executes Vim script with line-continuation" ,
83
+ fn : async ( denops ) => {
84
+ await execute (
85
+ denops ,
86
+ `
87
+ let g:denops_std_execute_test = 1
88
+ \\ + 1
89
+ ` ,
90
+ ) ;
91
+ assertEquals ( await denops . eval ( "g:denops_std_execute_test" ) as number , 2 ) ;
92
+ } ,
93
+ } ) ;
94
+
95
+ test ( {
96
+ mode : "any" ,
97
+ name : "execute() executes Vim script with trailing spaces" ,
98
+ fn : async ( denops ) => {
99
+ try {
100
+ await execute ( denops , "setlocal path=foo\\\\\\ " ) ;
101
+ assertEquals ( await denops . eval ( "&l:path" ) as string , "foo\\ " ) ;
102
+ } finally {
103
+ await denops . cmd ( "setlocal path&" ) ;
104
+ }
105
+ } ,
106
+ } ) ;
107
+
108
+ test ( {
109
+ mode : "any" ,
110
+ name : "execute() returns Promise<void>" ,
111
+ fn : async ( denops ) => {
112
+ const actual = execute ( denops , "let g:denops_std_execute_test = 1" ) ;
113
+ assertInstanceOf ( actual , Promise ) ;
114
+ assertEquals ( await actual , undefined ) ;
115
+ } ,
116
+ } ) ;
You can’t perform that action at this time.
0 commit comments