Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call node file detection less often (fix #37) #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions plugin/node.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,16 @@ function! s:detect(dir)
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
if is_node | call node#javascript() | 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()"
let s:filetype_patterns_joined = join(s:filetypes, ",")
execute "au FileType " s:filetype_patterns_joined ' call <SID>detect(expand("\<afile>:p"))'
augroup end