aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/.local/share/nvim/site/plugin/node.vim
diff options
context:
space:
mode:
authorYaroslav <contact@yaroslavps.com>2020-03-31 17:52:49 +0300
committerYaroslav <contact@yaroslavps.com>2020-03-31 17:52:49 +0300
commit7217c7749e5403c9c7856c1d12c7986eb9c3b460 (patch)
treed60a112d9119a51af1cf5f590c5efad81751edf6 /dotfiles/.local/share/nvim/site/plugin/node.vim
parent9a3aa7b20a67c1b7991da1da9508ad5f78f76352 (diff)
downloadvimrice-7217c7749e5403c9c7856c1d12c7986eb9c3b460.tar.gz
vimrice-7217c7749e5403c9c7856c1d12c7986eb9c3b460.zip
Goodbye vim, been using neovim for ages now; home directory cleanup
Diffstat (limited to 'dotfiles/.local/share/nvim/site/plugin/node.vim')
-rw-r--r--dotfiles/.local/share/nvim/site/plugin/node.vim47
1 files changed, 47 insertions, 0 deletions
diff --git a/dotfiles/.local/share/nvim/site/plugin/node.vim b/dotfiles/.local/share/nvim/site/plugin/node.vim
new file mode 100644
index 0000000..a541292
--- /dev/null
+++ b/dotfiles/.local/share/nvim/site/plugin/node.vim
@@ -0,0 +1,47 @@
+if exists("g:loaded_node") || &cp || v:version < 700 | finish | endif
+let g:loaded_node = 1
+
+let s:filetypes = ["javascript", "json", "jsx"]
+if exists("g:node_filetypes") | let s:filetypes = g:node_filetypes | endif
+
+function! s:detect(dir)
+ if exists("b:node_root") | return | endif
+ let dir = a:dir
+
+ while 1
+ let is_node = 0
+ let is_node = is_node || filereadable(dir . "/package.json")
+ let is_node = is_node || isdirectory(dir . "/node_modules")
+ if is_node | return node#initialize(dir) | endif
+
+ let parent = fnamemodify(dir, ":h")
+ if parent == dir | return | endif
+ let dir = parent
+ endwhile
+endfunction
+
+function! s:permutate(ft)
+ " Don't know right now how to detect javascript.jsx and other permutations
+ " without precomputing them in advance. Please let me know if you do.
+ return [a:ft, a:ft . ".*", "*." . a:ft, "*." . a:ft . ".*"]
+endfunction
+
+function! s:flatten(list)
+ let values = []
+ for value in a:list
+ if type(value) == type([]) | call extend(values, value)
+ else | add(values, value)
+ endif
+ endfor
+ return values
+endfunction
+
+augroup Node
+ au!
+ au VimEnter * if empty(expand("<amatch>")) | call s:detect(getcwd()) | endif
+ au BufRead,BufNewFile * call s:detect(expand("<amatch>:p"))
+
+ let s:filetype_patterns = s:flatten(map(s:filetypes, "<SID>permutate(v:val)"))
+ let s:filetype_patterns_joined = join(s:filetype_patterns, ",")
+ execute "au FileType " s:filetype_patterns_joined " call node#javascript()"
+augroup end