Re: Announce: ECMAScript interface for Vim

143 views
Skip to first unread message

Bram Moolenaar

unread,
Mar 5, 2019, 6:53:16 AM3/5/19
to vim...@googlegroups.com, vim...@googlegroups.com, Bob Pepin, v...@vim.org

Bob Pepin wrote:

> This is to announce the release of an ECMAScript scripting interface for Vim.
>
> Why? Because it seemed like the right thing to do.

[...]

Interesting. Javascript is a popular language these days, thus I assume
several users will be interested in this.

I wonder, is this also possible for Typescript? It's like a better
version of Javascript, and its popularity is growing.

Anyway, I would like to hear whether users would use this.

--
Micro$oft: where do you want to go today?
Linux: where do you want to go tomorrow?
FreeBSD: are you guys coming, or what?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Bob Pepin

unread,
Mar 5, 2019, 6:27:15 PM3/5/19
to Bram Moolenaar, vim...@googlegroups.com, vim...@googlegroups.com
> On 5 Mar 2019, at 20.15, Bob Pepin <b...@pepin.io> wrote:
>
> On 5 Mar 2019, at 12.53, Bram Moolenaar <Br...@moolenaar.net> wrote:
>>
>> I wonder, is this also possible for Typescript? It's like a better
>> version of Javascript, and its popularity is growing.
>
> How well this works in practice remains to be seen, I will try to play around with it a bit.
>

First results look promising, with the latest vim-duktape git and after downloading typescript.js from https://raw.githubusercontent.com/Microsoft/TypeScript/master/lib/typescript.js and putting it into a runtimepath directory:

Entering Ex mode. Type "visual" to go to Normal mode.
:duk var ts = require('typescript.js')

:duk var source = 'for(const x of [1, 2, 3]) msg(x)'

:duk var result = ts.transpileModule(source, {})

:duk JSON.stringify(result.outputText)
Duktape result: "for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {\r\n
var x = _a[_i];\r\n msg(x);\r\n}\r\n"
:duk var fun = compile(result.outputText, "<inline>", {})

:duk fun()
1
2
3

Performance-wise, we are at 500 ms for require(’typescript.js’) and 9 ms for everything else.

I will see if I can integrate the TypeScript module system with Vim sometime this week.

Bob

Prabir Shrestha

unread,
Mar 6, 2019, 12:29:42 AM3/6/19
to vim_dev
+1 for ECMAScript in vim.
-1 for TypeScript. It does sometime have breaking changes that needs to be fixed during upgrade. It also has flags on how strict we want to be so trying to come up with tsconfig.json that satisfies everyone as well as handle new ones will be a nightmare.

Can we also have webworker support in the JS implementation as first class support that would allow us to write plugins that are more responsive without starting threads :)

Andy Massimino

unread,
Mar 6, 2019, 7:36:11 AM3/6/19
to vim...@googlegroups.com, Bob Pepin, Bram Moolenaar, vim...@googlegroups.com
What is the performance of duktape like?

There is a very successful vim plugin written in typescript
(https://github.com/neoclide/coc.nvim) which was able to re-use open
source components of microsoft's vscode editor to provide language
server and "intellisense" support.  But it uses node through job_start. 
Will scripts written for the embedded duktape be faster than that solution?

It makes not much sense to embed language support in a second-class way
which won't get used either due to performance issues, or that it
doesn't support the modern language features for which much code is
already written (



Bob Pepin

unread,
Mar 6, 2019, 3:09:58 PM3/6/19
to Andy Massimino, vim...@googlegroups.com, Bram Moolenaar, vim...@googlegroups.com


> On 6 Mar 2019, at 13.36, Andy Massimino <vimpli...@gmail.com> wrote:

> What is the performance of duktape like?
>

Parsing typescript.js (~ 7 MB, 121 K lines) into an AST with Esprima takes 14 s on Duktape, versus 0.5 s on Node.js. Impressive performance by Node.js / V8 indeed. Note however that this still corresponds to around 10 000 lines per second for Duktape.

Also, binary sizes:
-r-xr-xr-x 1 bob staff 28M Mar 6 20:43 /usr/local/bin/node
-rwxr-xr-x 1 bob staff 330K Feb 11 21:56 ../../duktape-2.3.0/duk

Both with no external dependencies to speak of (Duktape is dynamically linked against system libc, node against libc, libc++ and libicu).

Bob

Prabir Shrestha

unread,
May 11, 2019, 9:21:11 PM5/11/19
to vim_dev
On Wednesday, March 6, 2019 at 12:09:58 PM UTC-8, Bob Pepin wrote:

Another idea is to actually support WASM VM inside vim so that plugins can be run in any language.

There are quite a few WASM VMs but this one seems quite small. I haven't personally tired it yet.
https://github.com/intel/wasm-micro-runtime

Reply all
Reply to author
Forward
0 new messages