Skip to content

Commit 422fe9a

Browse files
Add nodejs tool layer
1 parent e2daa1f commit 422fe9a

File tree

7 files changed

+192
-13
lines changed

7 files changed

+192
-13
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function! spacevim#plug#nodejs#Build(cache) abort
2+
if !a:cache.posix_compiler
3+
" vcbuild appears to not have '--prefix' equivalent but can improvise
4+
call execute('AsyncRun -cwd='.a:cache.plugpath.' -mode=term -pos=tab -post=call\ spacevim\#vim\#plug\#PostBuild(code,\ \"node\") @ .\\vcbuild openssl-no-asm')
5+
else
6+
let jobs_flag = ''
7+
let ninja_flag = ''
8+
if executable('ninja')
9+
let ninja_flag=' --ninja'
10+
else
11+
" Determine number of cores/threads for make -j, ninja autodetects
12+
let num_threads = 4
13+
if executable('lscpu')
14+
let result = system("lscpu | grep -E '?^(CPU\\(s\\):|Thread\\(s\\) per core:)' | tr -s ' ' | cut -f 2 -d:")
15+
if !v:shell_error
16+
let num_threads = join(split(result), '*')
17+
endif
18+
endif
19+
let jobs_flag = ' -j '.num_threads
20+
endif
21+
call system('./configure --prefix=./install'.ninja_flag.' > '.a:cache.temppath.'/nodejs_configure.log')
22+
call execute('AsyncRun -cwd='.a:cache.plugpath.' -mode=term -pos=tab -program=make -post=call\ spacevim\#vim\#plug\#PostBuild(code,\ \"node\") @ install'.jobs_flag)
23+
endif
24+
execute 'tcd' a:cache.cwd
25+
endfunction
26+
27+
function! spacevim#plug#nodejs#PostBuild(cache) abort
28+
call delete('config.gypi')
29+
call delete('config.mk')
30+
call delete('config.status')
31+
call delete('icu_config.gypi')
32+
call delete('deps', 'rf')
33+
call delete('node')
34+
call delete('__pycache__', 'rf')
35+
call delete('tools', 'rf')
36+
37+
execute 'tcd' a:cache.binpath
38+
call system('node corepack enable')
39+
endfunction

layers/+tools/lsp/README.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<!-- vim-markdown-toc GFM -->
66

77
* [Description](#description)
8-
* [Requrement](#requrement)
8+
* [Install](#install)
9+
* [Manual Language Server Installation](#manual-language-server-installation)
910
* [Rust](#rust)
1011
* [Python](#python)
1112
* [Go](#go)
@@ -14,7 +15,6 @@
1415
* [Haskell](#haskell)
1516
* [Lua](#lua)
1617
* [vue](#vue)
17-
* [Install](#install)
1818
* [Key Bindings](#key-bindings)
1919
* [Related Projects](#related-projects)
2020

@@ -24,7 +24,48 @@
2424

2525
This layer adds supports [Language Server Protocol](https://langserver.org/).
2626

27-
## Requrement
27+
## Install
28+
29+
To use this configuration layer, add it to your `~/.spacevim`, set it up like so:
30+
31+
```vim
32+
let g:spacevim_layers = [
33+
\ 'lsp',
34+
\ ]
35+
```
36+
37+
Currently [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) is the default *language server client* when using the lsp layer.
38+
39+
Currently the *language server client* builtin to Neovim is not supported by space-vim [#483](https://github.com/liuchengxu/space-vim/issues/483).
40+
41+
To use [coc.nvim](https://github.com/neoclide/coc.nvim) or [vim-lsp](https://github.com/prabirshrestha/vim-lsp) instead of the default set `g:spacevim_lsp_engine` as desired:
42+
43+
```vim
44+
let g:spacevim_layers = [
45+
\ 'lsp',
46+
\ ]
47+
48+
let g:spacevim_lsp_engine = 'coc'
49+
let g:spacevim_lsp_engine = 'vim_lsp'
50+
```
51+
52+
Note that coc.nvim is dependent on Node.js, the nodejs layer will satisfy that dependency.
53+
54+
If using vim-lsp as the *language server client*, this layer will handle the configuration and installation of many *language servers* for you (this layer includes the [vim-lsp-settings](https://github.com/mattn/vim-lsp-settings) plugin). On opening a file this layer will detect if there is a *language server* for that filetype and prompt you to run the command `:LspInstallServer`.
55+
56+
Unlike other Vim *language server clients*, LanguageClient-neovim does not include configuration and installation of *language servers*. space-vim includes some configuration for *language servers* and this client, but installation must be done manually.
57+
58+
Often the Yarn or npm tools are needed to retrieve a *language server* and its dependencies. For convenience space-vim includes these tools within the nodejs layer, which builds them or locates them using the `$PATH` and `$NODE` environmental variables. You may include the nodejs layer as follows (which may require the programming layer):
59+
60+
```vim
61+
let g:spacevim_layers = [
62+
\ 'programming', 'nodejs', 'lsp',
63+
\ ]
64+
```
65+
66+
## Manual Language Server Installation
67+
68+
If using LanguageClient-neovim, directions for the manual installation of some LSP servers are as follows. Other configuration and installation directions can be found in locations like its github wiki pages.
2869

2970
### Rust
3071

@@ -120,16 +161,6 @@ $ luarocks install --server=http://luarocks.org/dev lua-lsp
120161
$ npm install vue-language-server -g
121162
```
122163

123-
## Install
124-
125-
To use this configuration layer, add it to your `~/.spacevim`.
126-
127-
Currently, [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) is the default LS client. To use [coc.nvim](https://github.com/neoclide/coc.nvim) instead:
128-
129-
```vim
130-
let g:spacevim_lsp_engine = 'coc'
131-
```
132-
133164
## Key Bindings
134165

135166
Key Binding | Mode | Description

layers/+tools/nodejs/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# nodejs tool Layer
2+
3+
## Table of Contents
4+
5+
<!-- vim-markdown-toc GFM -->
6+
* [Description](#description)
7+
* [Install](#install)
8+
* [Building](#building)
9+
* [MS Windows](#ms-windows)
10+
11+
<!-- vim-markdown-toc -->
12+
13+
## Description
14+
15+
Folowing the zero-install philosophy, this layer adds the Node.js tool, built from source if needed.
16+
17+
If `node` is found on $PATH, or $NODE points to `node`, and either is of sufficient version, that will be used instead of building from source.
18+
19+
The curated node will be added to `$PATH` for use by other plugins and language servers. Including yarn/npm which language servers may use to download dependencies.
20+
21+
## Install
22+
23+
To use this layer, add it to your `~/.spacevim`.
24+
25+
### Building
26+
27+
On building from source, around 200MiB is installed into the prefix `./install` relative to the plugin directory. The building process requires around 4GiB, which will be deleted on completion.
28+
29+
If the automated building doesn't work, you may navigate to the plugin directory and build manually, into the prefix `./install`; installing system-wide isn't required. Or install prebuilt binaries and set $PATH or $NODE accordingly.
30+
31+
#### MS Windows
32+
33+
You have two ABI choices: GNU and MSVC (comes with Visual Studio Tools). Your choice depends on the C/C++ libraries you want to interoperate with.
34+
35+
Automated building from source isn't tested. However it should work in Cygwin or with the environmental variables as defined by `msys2_shell.cmd` or `vcvars64.bat` per the desired ABI.

layers/+tools/nodejs/config.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'
2+
3+
let location = spacevim#vim#plug#LocateDependency('node')
4+
if location[0] ==# 'none'
5+
call spacevim#util#warn('nodejs layer failure, try ":call dein#get('.
6+
\ '"node").hook_post_update()" to build as plugin, or set $NODE/'.
7+
\ '$PATH to existing build, or install system-wide with version >= '.
8+
\ join(g:spacevim#vim#plug#native_dependency['node'].v_req, '.').'.')
9+
else
10+
" Don't install devDependencies on `npm install`
11+
let $NODE_ENV = 'production'
12+
let f = expand(g:spacevim.state_base.'/node_npm_configured_v'.location[1][0].'.'.location[1][1])
13+
if location[0] ==# 'plugin' && !filereadable(f)
14+
" npm install packages into {prefix}/lib/node_modules
15+
call system('npm config set location global')
16+
" node-gpy needs to know where headers are
17+
call system('npm config set nodedir '.fnamemodify(location[2], ':h'))
18+
call writefile([], f, 'S')
19+
endif
20+
endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function! Build(native) abort
2+
if !a:native.posix_compiler
3+
" vcbuild appears to not have '--prefix' equivalent but can improvise
4+
call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '.
5+
\ '-pos=tab -post='.
6+
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''node'') @ '.
7+
\ '.\\vcbuild openssl-no-asm')
8+
else
9+
let configure_log = a:native.temppath.'/nodejs_configure.log'
10+
call system(a:native.plugpath.'/configure --prefix='.
11+
\ a:native.plugpath.'/install'.c.ninja_flag.' > '.configure_log)
12+
call rename(configure_log, a:native.plugpath.'/configure.log')
13+
call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '.
14+
\ '-pos=tab -program=make -post='.
15+
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''node'') @ '.
16+
\ 'install'.c.jobs_flag)
17+
endif
18+
endfunction
19+
20+
function! PostBuild(native) abort
21+
call delete('config.gypi')
22+
call delete('config.mk')
23+
call delete('config.status')
24+
call delete('icu_config.gypi')
25+
call delete('deps', 'rf')
26+
call delete('node')
27+
call delete('__pycache__', 'rf')
28+
call delete('tools', 'rf')
29+
30+
execute 'tcd' a:native.binpath
31+
call system('node corepack enable')
32+
endfunction
33+
34+
let g:spacevim#vim#plug#native_dependency = get(g:, 'spacevim#vim#plug#native_dependency', {})
35+
let g:spacevim#vim#plug#native_dependency['node'] = #{
36+
\ bin: 'node',
37+
\ override: '$NODE',
38+
\ repo: 'nodejs/node',
39+
\ vregex: '\Vv\(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\+\)',
40+
\ v_req: [16, 10, 0],
41+
\ Build: function('Build'),
42+
\ PostBuild: function('PostBuild'),
43+
\ }

layers/+tools/nodejs/packages.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'
2+
3+
" v >= 16.10 is required for corepack
4+
" v < 17 required for tree-sitter
5+
" https://github.com/tree-sitter/node-tree-sitter/issues/102
6+
if spacevim#vim#plug#LocateDependency('node')[0] ==# 'none'
7+
MP 'nodejs/node', { 'merged': v:false, 'rtp': '',
8+
\ 'rev': 'v16.16.0',
9+
\ 'hook_post_update': function('spacevim#vim#plug#Build', ['node']) }
10+
endif

layers/LAYERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Topic | Layer | Plugins
5050
+tools | [file-manager](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/file-manager) | <ul><li>[Xuyuanp/nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin)</li><li>[danro/rename.vim](https://github.com/danro/rename.vim)</li><li>[liuchengxu/nerdtree-dash](https://github.com/liuchengxu/nerdtree-dash)</li><li>[ryanoasis/vim-devicons](https://github.com/ryanoasis/vim-devicons)</li><li>[scrooloose/nerdtree](https://github.com/scrooloose/nerdtree)</li></ul>
5151
+tools | [fzf](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/fzf) | <ul><li>[Yggdroot/LeaderF](https://github.com/Yggdroot/LeaderF)</li><li>[junegunn/fzf](https://github.com/junegunn/fzf)</li><li>[junegunn/fzf.vim](https://github.com/junegunn/fzf.vim)</li><li>[liuchengxu/vim-clap](https://github.com/liuchengxu/vim-clap)</li></ul>
5252
+tools | [lsp](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/lsp) | <ul><li>[autozimu/LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim)</li><li>[mattn/vim-lsp-settings](https://github.com/mattn/vim-lsp-settings)</li><li>[neoclide/coc-neco](https://github.com/neoclide/coc-neco)</li><li>[neoclide/coc.nvim](https://github.com/neoclide/coc.nvim)</li><li>[prabirshrestha/async.vim](https://github.com/prabirshrestha/async.vim)</li><li>[prabirshrestha/vim-lsp](https://github.com/prabirshrestha/vim-lsp)</li><li>[rhysd/vim-lsp-ale](https://github.com/rhysd/vim-lsp-ale)</li></ul>
53+
+tools | [nodejs](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/nodejs) | <ul><li>[nodejs/node](https://github.com/nodejs/node)</li></ul>
5354
+tools | [tmux](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/tmux) | <ul><li>[christoomey/vim-tmux-navigator](https://github.com/christoomey/vim-tmux-navigator)</li><li>[jebaum/vim-tmuxify](https://github.com/jebaum/vim-tmuxify)</li><li>[lucidstack/ctrlp-tmux.vim](https://github.com/lucidstack/ctrlp-tmux.vim)</li></ul>
5455
+tools | [ycmd](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/ycmd) | <ul><li>[rdnetto/YCM-Generator](https://github.com/rdnetto/YCM-Generator)</li><li>[ycm-core/YouCompleteMe](https://github.com/ycm-core/YouCompleteMe)</li></ul>
5556
+version-control | [git](https://github.com/liuchengxu/space-vim/tree/master/layers/+version-control/git) | <ul><li>[junegunn/gv.vim](https://github.com/junegunn/gv.vim)</li><li>[mhinz/vim-signify](https://github.com/mhinz/vim-signify)</li><li>[tpope/vim-fugitive](https://github.com/tpope/vim-fugitive)</li></ul>

0 commit comments

Comments
 (0)