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 {
66/**
77 * Execute Vim script directly
88 */
9- export async function execute (
9+ export function execute (
1010 denops : Denops ,
1111 script : string | string [ ] ,
1212 ctx : Context = { } ,
1313) : 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) ;
2319 }
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 ) ;
2626}
Original file line number Diff line number Diff line change 11import {
22 assertEquals ,
3+ assertInstanceOf ,
34 assertRejects ,
45} from "https://deno.land/[email protected] /testing/asserts.ts" ; 56import { test } from "https://deno.land/x/[email protected] /test/mod.ts" ; @@ -75,3 +76,41 @@ test({
7576 assertEquals ( await denops . eval ( "g:denops_std_execute_test" ) as number , 25 ) ;
7677 } ,
7778} ) ;
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