Skip to content

Commit 30a10aa

Browse files
Add nodejs tool layer
1 parent 79f8ddc commit 30a10aa

File tree

6 files changed

+186
-19
lines changed

6 files changed

+186
-19
lines changed

layers/+tools/lsp/README.md

Lines changed: 38 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 LSP Server Installation](#manual-lsp-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,42 @@
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 LS client for Neovim, and vim-lsp is the default LS client for Vim. Currently the LSP client builtin to Neovim is not supported [#483](https://github.com/liuchengxu/space-vim/issues/483).
38+
39+
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:
40+
41+
```vim
42+
let g:spacevim_layers = [
43+
\ 'lsp',
44+
\ ]
45+
46+
let g:spacevim_lsp_engine = 'coc'
47+
let g:spacevim_lsp_engine = 'vim_lsp'
48+
```
49+
50+
If using vim-lsp as the LSP client, this layer will handle the installation of many LSP servers for you. On opening a file it will detect if there is a LSP server for that filetype and prompt you to run the command `:LspInstallServer`.
51+
52+
Often Yarn or npm are needed to retrieve the LSP 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):
53+
54+
```vim
55+
let g:spacevim_layers = [
56+
\ 'programming', 'nodejs', 'lsp',
57+
\ ]
58+
```
59+
60+
## Manual LSP Server Installation
61+
62+
If not using vim-lsp (which handles server installation for you), directions for the manual installation of some LSP servers are as follows.
2863

2964
### Rust
3065

@@ -120,16 +155,6 @@ $ luarocks install --server=http://luarocks.org/dev lua-lsp
120155
$ npm install vue-language-server -g
121156
```
122157

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-
133158
## Key Bindings
134159

135160
Key Binding | Mode | Description

layers/+tools/lsp/packages.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ function! s:vim_lsp() abort
1212
MP 'prabirshrestha/async.vim'
1313
MP 'prabirshrestha/vim-lsp'
1414
MP 'mattn/vim-lsp-settings'
15+
if spacevim#load('ale')
16+
MP 'rhysd/vim-lsp-ale'
17+
endif
1518
endfunction
1619

1720
function! s:lcn() abort
@@ -21,6 +24,6 @@ function! s:lcn() abort
2124
\ }
2225
endfunction
2326

24-
let g:spacevim_lsp_engine = get(g:, 'spacevim_lsp_engine', 'lcn')
27+
let g:spacevim_lsp_engine = get(g:, 'spacevim_lsp_engine', (has('nvim') ? 'lcn' : 'vim_lsp'))
2528

2629
call s:{g:spacevim_lsp_engine}()

layers/+tools/nodejs/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# nodejs Layer
2+
3+
## Table of Contents
4+
5+
<!-- vim-markdown-toc GFM -->
6+
* [Description](#description)
7+
* [Install](#install)
8+
* [Key Bindings](#keybindings)
9+
10+
<!-- vim-markdown-toc -->
11+
12+
## Description
13+
14+
This layer adds support for the Node.js tool.
15+
16+
## Install
17+
18+
To use this layer, add it to your `~/.spacevim` as follows:
19+
20+
```
21+
let g:spacevim_layers = [
22+
\ 'programming', 'nodejs',
23+
\ ]
24+
```
25+
26+
If Node.js is installed system-wide and is version >= 16.10 then that will be used. Otherwise the nodejs layer requires the programming layer to build Node.js as a dependency within vim-plug's plugged directory.
27+
28+
Node.js built requires approx 900 MiB space, largely intermediate files.
29+
30+
If you instead wish to use Node.js elsewhere (not on `$PATH`), this package will look at `$NODE` and use that if it is of sufficient version.
31+
32+
The curated node will be added to `$PATH` for use by other plugins. Node.js >= v16.10 also includes yarn/npm, useful for other plugins to install dependencies.

layers/+tools/nodejs/config.vim

Whitespace-only changes.

layers/+tools/nodejs/packages.vim

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
" Check for Node.js >= v16.10
2+
function! s:isNodeJsVersionSufficient(node)
3+
let node_version = system(a:node.' --version')
4+
let node_version_parts = map(filter(split(node_version, '\v\ze\.|v'), 'v:val =~ "\\v\\d+"'), 'matchstr(v:val, "\\v\\d+")')
5+
if len(node_version_parts) >= 2 && (node_version_parts[0] > 16 || (node_version_parts[0] == 16 && node_version_parts[1] >= 10))
6+
return 1
7+
endif
8+
return 0
9+
endfunction
10+
11+
" Will do the following checks in order of precedence:
12+
" -Use $NODE or $NODE/node if they exist and are executable
13+
" -check for node as vim-plug plugin (user-specific)
14+
" -check for system-wide install of node
15+
" -If all above fail will get node as vim-plug plugin and build it
16+
" Changes $PATH to include node path
17+
function! s:isNewNodeJsRequired()
18+
let pathsep = g:spacevim.os.windows ? ';' : ':'
19+
" Prefer $NODE override
20+
if exists('$NODE')
21+
if executable('$NODE') == 1 && s:isNodeJsVersionSufficient('$NODE')
22+
let $PATH = fnamemodify($NODE, ':h').pathsep.$PATH
23+
return 0
24+
elseif executable('$NODE/node') == 1 && s:isNodeJsVersionSufficient('$NODE/node')
25+
let $PATH = $NODE.pathsep.$PATH
26+
return 0
27+
endif
28+
endif
29+
" Prefer user/plugin Node.js if it exists
30+
if executable(g:plug_home.'/node/node') == 1 && s:isNodeJsVersionSufficient(g:plug_home.'/node/node')
31+
let $PATH = g:plug_home.'/node'.pathsep.$PATH
32+
return 0
33+
endif
34+
" Last check for system-wide Node.js
35+
if executable('node') == 1 && s:isNodeJsVersionSufficient('node')
36+
return 0
37+
endif
38+
return 1
39+
endfunction
40+
41+
" If no valid $NODE or systemwide node.js: build node.js dependency
42+
function! BuildNodeJs(info)
43+
if g:spacevim.os.windows
44+
echom 'Building Node.js automatically is not supported on Windows, Build it manually or send PR'
45+
return
46+
endif
47+
if (!exists('$CC') && executable('gcc') != 1) || executable('make') != 1 || executable('python3') != 1
48+
echom 'Unable to build Node.js, requires a C++ compiler, make, and python3'
49+
return
50+
endif
51+
if !spacevim#load('programming')
52+
echom "nodejs layer requires the 'programming' layer to build. Add 'programming' layer to init.spacevim"
53+
return
54+
endif
55+
56+
echom 'Building Node.js, please wait... restart Vim on completion'
57+
let ninja_flag = ''
58+
let jobs_flag = ''
59+
if executable('ninja')
60+
let ninja_flag=' --ninja'
61+
else
62+
" Determine number of cores/threads for make -j, ninja autodetects
63+
if executable('lscpu')
64+
execute 'let num_threads = '.join(split(system("lscpu | grep -E '?^(CPU\\(s\\):|Thread\\(s\\) per core:)' | tr -s ' ' | cut -f 2 -d:")),'*')
65+
else
66+
let num_threads = 4
67+
endif
68+
let jobs_flag = ' -j '.num_threads
69+
endif
70+
71+
" This sets up corepack/npm links as default make taget doesn't
72+
" Could alternatively `make install` to prefix and set PATH to prefix/bin
73+
let temp_dir = fnamemodify(tempname(), ':p:h')
74+
call system('./configure --prefix=./build'.ninja_flag.' > '.temp_dir.'/nodejs_configure.log')
75+
76+
" Cache any existing Make definition and restore
77+
let makeDefinitionTest = split(execute(':command Make'), '\n')
78+
if len(makeDefinitionTest) > 1
79+
let makeDefinition = split(makeDefinitionTest[2], '\s\s\+')
80+
endif
81+
command! -bang -nargs=* -bar Make AsyncRun -mode=term -pos=tab -program=make @ <args>
82+
execute 'Make'.jobs_flag
83+
delcommand Make
84+
if exists('makeDefinition')
85+
" Restores prior definition. Has inadequacies.
86+
execute 'command! '.(makeDefinition[0] =~ '!' ? '-bang ' : '').(makeDefinition[0] =~ '|' ? '-bar ' : '').(makeDefinition[0] =~ 'b' ? '-buffer ' : '').makeDefinition[0] =~ '\"' ? '-register ' : '').'-nargs='.makeDefinition[1].' Make '.makeDefinition[3]
87+
endif
88+
let $NODE = fnamemodify('.', ':p').'/node'
89+
" TODO: Uncertain if correct node_modules
90+
let $NODE_PATH = fnamemodify('.', ':p').'/tools/node_modules'
91+
let pathsep = g:spacevim.os.windows ? ';' : ':'
92+
let $PATH = g:plug_home.'/node'.pathsep.$PATH
93+
94+
" Set links which `make install` does, they're necessary for use
95+
call system("ln -s deps/corepack/dist/corepack.js corepack")
96+
call system("ln -s deps/npm/bin/npm-cli.js npm")
97+
call system("ln -s deps/npm/bin/npx-cli.js npx")
98+
" Make Yarn available
99+
call system("node corepack enable")
100+
endfunction
101+
102+
" isNewNodeJsRequired will add node to $PATH if needed
103+
if s:isNewNodeJsRequired()
104+
MP 'nodejs/node', { 'do': function('BuildNodeJs') }
105+
endif

layers/LAYERS.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
Layer Manifest
22
==============
33

4-
Last updated: 2020-04-29 10:55:41
4+
Last updated: 2022-06-09 15:32:49
55

66
Default layers: `fzf`, `better-defaults` and `which-key`.
77

88
Topic | Layer | Plugins
99
:----: | :----: | :----
1010
+checkers | [syntax-checking](https://github.com/liuchengxu/space-vim/tree/master/layers/+checkers/syntax-checking) | <ul><li>[vim-syntastic/syntastic](https://github.com/vim-syntastic/syntastic)</li><li>[w0rp/ale](https://github.com/w0rp/ale)</li></ul>
11+
+completion | [asyncomplete](https://github.com/liuchengxu/space-vim/tree/master/layers/+completion/asyncomplete) | <ul><li>[prabirshrestha/asyncomplete-lsp.vim](https://github.com/prabirshrestha/asyncomplete-lsp.vim)</li><li>[prabirshrestha/asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim)</li></ul>
1112
+completion | [auto-completion](https://github.com/liuchengxu/space-vim/tree/master/layers/+completion/auto-completion) | <ul><li>[lifepillar/vim-mucomplete](https://github.com/lifepillar/vim-mucomplete)</li><li>[maralla/completor-neosnippet](https://github.com/maralla/completor-neosnippet)</li><li>[maralla/completor.vim](https://github.com/maralla/completor.vim)</li><li>[ncm2/float-preview.nvim](https://github.com/ncm2/float-preview.nvim)</li><li>[ncm2/ncm2](https://github.com/ncm2/ncm2)</li><li>[ncm2/ncm2-bufword](https://github.com/ncm2/ncm2-bufword)</li><li>[ncm2/ncm2-github](https://github.com/ncm2/ncm2-github)</li><li>[ncm2/ncm2-go](https://github.com/ncm2/ncm2-go)</li><li>[ncm2/ncm2-jedi](https://github.com/ncm2/ncm2-jedi)</li><li>[ncm2/ncm2-path](https://github.com/ncm2/ncm2-path)</li><li>[ncm2/ncm2-pyclang](https://github.com/ncm2/ncm2-pyclang)</li><li>[ncm2/ncm2-racer](https://github.com/ncm2/ncm2-racer)</li><li>[ncm2/ncm2-tmux](https://github.com/ncm2/ncm2-tmux)</li><li>[ncm2/ncm2-ultisnips](https://github.com/ncm2/ncm2-ultisnips)</li><li>[ncm2/ncm2-vim](https://github.com/ncm2/ncm2-vim)</li><li>[roxma/nvim-yarp](https://github.com/roxma/nvim-yarp)</li><li>[roxma/vim-hug-neovim-rpc](https://github.com/roxma/vim-hug-neovim-rpc)</li></ul>
1213
+completion | [deoplete](https://github.com/liuchengxu/space-vim/tree/master/layers/+completion/deoplete) | <ul><li>[Shougo/deoplete.nvim](https://github.com/Shougo/deoplete.nvim)</li><li>[Shougo/neco-vim](https://github.com/Shougo/neco-vim)</li><li>[eagletmt/neco-ghc](https://github.com/eagletmt/neco-ghc)</li><li>[sebastianmarkow/deoplete-rust](https://github.com/sebastianmarkow/deoplete-rust)</li><li>[zchee/deoplete-go](https://github.com/zchee/deoplete-go)</li></ul>
1314
+completion | [unite](https://github.com/liuchengxu/space-vim/tree/master/layers/+completion/unite) | <ul><li>[Shougo/unite.vim](https://github.com/Shougo/unite.vim)</li></ul>
14-
+distributions | [better-defaults](https://github.com/liuchengxu/space-vim/tree/master/layers/+distributions/better-defaults) | <ul><li>[dominikduda/vim_current_word](https://github.com/dominikduda/vim_current_word)</li><li>[google/vim-searchindex](https://github.com/google/vim-searchindex)</li><li>[haya14busa/incsearch-fuzzy.vim](https://github.com/haya14busa/incsearch-fuzzy.vim)</li><li>[haya14busa/incsearch.vim](https://github.com/haya14busa/incsearch.vim)</li><li>[haya14busa/is.vim](https://github.com/haya14busa/is.vim)</li><li>[kshenoy/vim-signature](https://github.com/kshenoy/vim-signature)</li><li>[mhinz/vim-startify](https://github.com/mhinz/vim-startify)</li><li>[ntpeters/vim-better-whitespace](https://github.com/ntpeters/vim-better-whitespace)</li><li>[tpope/vim-rsi](https://github.com/tpope/vim-rsi)</li><li>[xtal8/traces.vim](https://github.com/xtal8/traces.vim)</li><li>[ybian/smartim](https://github.com/ybian/smartim)</li></ul>
15+
+distributions | [better-defaults](https://github.com/liuchengxu/space-vim/tree/master/layers/+distributions/better-defaults) | <ul><li>[dominikduda/vim_current_word](https://github.com/dominikduda/vim_current_word)</li><li>[google/vim-searchindex](https://github.com/google/vim-searchindex)</li><li>[haya14busa/incsearch-fuzzy.vim](https://github.com/haya14busa/incsearch-fuzzy.vim)</li><li>[haya14busa/incsearch.vim](https://github.com/haya14busa/incsearch.vim)</li><li>[haya14busa/is.vim](https://github.com/haya14busa/is.vim)</li><li>[kshenoy/vim-signature](https://github.com/kshenoy/vim-signature)</li><li>[markonm/traces.vim](https://github.com/markonm/traces.vim)</li><li>[mhinz/vim-startify](https://github.com/mhinz/vim-startify)</li><li>[ntpeters/vim-better-whitespace](https://github.com/ntpeters/vim-better-whitespace)</li><li>[tpope/vim-rsi](https://github.com/tpope/vim-rsi)</li><li>[ybian/smartim](https://github.com/ybian/smartim)</li></ul>
1516
+distributions | [spacevim](https://github.com/liuchengxu/space-vim/tree/master/layers/+distributions/spacevim) | <ul><li>[liuchengxu/eleline.vim](https://github.com/liuchengxu/eleline.vim)</li><li>[liuchengxu/space-vim-dark](https://github.com/liuchengxu/space-vim-dark)</li><li>[liuchengxu/space-vim-theme](https://github.com/liuchengxu/space-vim-theme)</li><li>[liuchengxu/vim-better-default](https://github.com/liuchengxu/vim-better-default)</li></ul>
1617
+fun | [emoji](https://github.com/liuchengxu/space-vim/tree/master/layers/+fun/emoji) | <ul><li>[junegunn/vim-emoji](https://github.com/junegunn/vim-emoji)</li></ul>
1718
+fun | [games](https://github.com/liuchengxu/space-vim/tree/master/layers/+fun/games) | <ul><li>[johngrib/vim-game-code-break](https://github.com/johngrib/vim-game-code-break)</li></ul>
@@ -47,9 +48,10 @@ Topic | Layer | Plugins
4748
+tools | [cscope](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/cscope) | <ul><li>[romainl/vim-qf](https://github.com/romainl/vim-qf)</li></ul>
4849
+tools | [ctags](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/ctags) | <ul><li>[ludovicchabant/vim-gutentags](https://github.com/ludovicchabant/vim-gutentags)</li></ul>
4950
+tools | [docker](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/docker) | <ul><li>[ekalinin/Dockerfile.vim](https://github.com/ekalinin/Dockerfile.vim)</li></ul>
50-
+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>
51-
+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>
52-
+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></ul>
51+
+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><li>[tiagofumo/vim-nerdtree-syntax-highlight](https://github.com/tiagofumo/vim-nerdtree-syntax-highlight)</li></ul>
52+
+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><li>[vn-ki/coc-clap](https://github.com/vn-ki/coc-clap)</li></ul>
53+
+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>
54+
+tools | [nodejs](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/nodejs) | <ul><li>[nodejs/node](https://github.com/nodejs/node)</li></ul>
5355
+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>
5456
+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>
5557
+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)