Skip to content

Commit

Permalink
Add nodejs tool layer
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-descartes2021 committed Dec 8, 2022
1 parent b4c507e commit 4ea4d0a
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 13 deletions.
57 changes: 44 additions & 13 deletions layers/+tools/lsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<!-- vim-markdown-toc GFM -->

* [Description](#description)
* [Requrement](#requrement)
* [Install](#install)
* [Manual Language Server Installation](#manual-language-server-installation)
* [Rust](#rust)
* [Python](#python)
* [Go](#go)
Expand All @@ -14,7 +15,6 @@
* [Haskell](#haskell)
* [Lua](#lua)
* [vue](#vue)
* [Install](#install)
* [Key Bindings](#key-bindings)
* [Related Projects](#related-projects)

Expand All @@ -24,7 +24,48 @@

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

## Requrement
## Install

To use this configuration layer, add it to your `~/.spacevim`, set it up like so:

```vim
let g:spacevim_layers = [
\ 'lsp',
\ ]
```

Currently [LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) is the default *language server client* when using the lsp layer.

Currently the *language server client* builtin to Neovim is not supported by space-vim [#483](https://github.com/liuchengxu/space-vim/issues/483).

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:

```vim
let g:spacevim_layers = [
\ 'lsp',
\ ]
let g:spacevim_lsp_engine = 'coc'
let g:spacevim_lsp_engine = 'vim_lsp'
```

Note that coc.nvim is dependent on Node.js, the nodejs layer will satisfy that dependency.

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`.

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.

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):

```vim
let g:spacevim_layers = [
\ 'programming', 'nodejs', 'lsp',
\ ]
```

## Manual Language Server Installation

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.

### Rust

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

## Install

To use this configuration layer, add it to your `~/.spacevim`.

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:

```vim
let g:spacevim_lsp_engine = 'coc'
```

## Key Bindings

Key Binding | Mode | Description
Expand Down
35 changes: 35 additions & 0 deletions layers/+tools/nodejs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# nodejs tool Layer

## Table of Contents

<!-- vim-markdown-toc GFM -->
* [Description](#description)
* [Install](#install)
* [Building](#building)
* [MS Windows](#ms-windows)

<!-- vim-markdown-toc -->

## Description

Folowing the zero-install philosophy, this layer adds the Node.js tool, built from source if needed.

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.

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.

## Install

To use this layer, add it to your `~/.spacevim`.

### Building

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.

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.

#### MS Windows

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.

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.
20 changes: 20 additions & 0 deletions layers/+tools/nodejs/config.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'

let location = spacevim#vim#plug#LocateDependency('node')
if location[0] ==# 'none'
call spacevim#util#warn('nodejs layer failure, try ":call dein#get('.
\ '"node").hook_post_update()" to build as plugin, or set $NODE/'.
\ '$PATH to existing build, or install system-wide with version >= '.
\ join(g:spacevim#vim#plug#native_dependency['node'].v_req, '.').'.')
else
" Don't install devDependencies on `npm install`
let $NODE_ENV = 'production'
let f = expand(g:spacevim.state_base.'/node_npm_configured_v'.location[1][0].'.'.location[1][1])
if location[0] ==# 'plugin' && !filereadable(f)
" npm install packages into {prefix}/lib/node_modules
call system('npm config set location global')
" node-gpy needs to know where headers are
call system('npm config set nodedir '.fnamemodify(location[2], ':h'))
call writefile([], f, 'S')
endif
endif
44 changes: 44 additions & 0 deletions layers/+tools/nodejs/native-dependency.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function! Build(native) abort
if !a:native.posix_compiler
" vcbuild appears to not have '--prefix' equivalent but can improvise
call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '.
\ '-pos=tab -post='.
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''node'') @ '.
\ '.\\vcbuild openssl-no-asm')
else
let configure_log = a:native.temppath.'/nodejs_configure.log'
call system(a:native.plugpath.'/configure --prefix='.
\ a:native.plugpath.'/install'.a:native.ninja_flag.' > '.
\ configure_log)
call rename(configure_log, a:native.plugpath.'/configure.log')
call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '.
\ '-pos=tab -program=make -post='.
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''node'') @ '.
\ 'install'.a:native.jobs_flag)
endif
endfunction

function! PostBuild(native) abort
call delete('config.gypi')
call delete('config.mk')
call delete('config.status')
call delete('icu_config.gypi')
call delete('deps', 'rf')
call delete('node')
call delete('__pycache__', 'rf')
call delete('tools', 'rf')

execute 'tcd' a:native.binpath
call system('node corepack enable')
endfunction

let g:spacevim#vim#plug#native_dependency = get(g:, 'spacevim#vim#plug#native_dependency', {})
let g:spacevim#vim#plug#native_dependency['node'] = {
\ 'bin': 'node',
\ 'override': '$NODE',
\ 'repo': 'nodejs/node',
\ 'vregex': '\Vv\(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\+\)',
\ 'v_req': [16, 10, 0],
\ 'Build': function('Build'),
\ 'PostBuild': function('PostBuild'),
\ }
10 changes: 10 additions & 0 deletions layers/+tools/nodejs/packages.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'

" v >= 16.10 is required for corepack
" v < 17 required for tree-sitter
" https://github.com/tree-sitter/node-tree-sitter/issues/102
if spacevim#vim#plug#LocateDependency('node')[0] ==# 'none'
MP 'nodejs/node', { 'merged': v:false, 'rtp': '',
\ 'rev': 'v16.16.0',
\ 'hook_post_update': function('spacevim#vim#plug#Build', ['node']) }
endif
1 change: 1 addition & 0 deletions layers/LAYERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Topic | Layer | Plugins
+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>
+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>
+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>
+tools | [nodejs](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/nodejs) | <ul><li>[nodejs/node](https://github.com/nodejs/node)</li></ul>
+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>
+tools | [vimspector](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/vimspector) | <ul><li>[puremourning/vimspector](https://github.com/puremourning/vimspector)</li></ul>
+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>
Expand Down

0 comments on commit 4ea4d0a

Please sign in to comment.