moll / vim-node

Tools and environment to make Vim superb for developing with Node.js. Like Rails.vim for Node.
http://www.vim.org/scripts/script.php?script_id=4674
Other
807 stars 59 forks source link

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

Open mMontu opened 7 years ago

mMontu commented 7 years ago

The expression used for 'includeexpr' (which is triggerd by [+I or insertion completion, as specified by default in 'complete') fails if b:node_root is undefined.

The b:node_root variable is created by the node#initialize(), which is called from s:detect() when it detects that the file is part of Node.js project.

A possible solution is to avoid change anything (as the 'includeexpr' option) if a file isn't detected as node file. Maybe it is also possible to improve the detection by searching the buffer for some node specific keywords (such as require) and setting the b:node_root to the env variable $NODE_PATH instead of leaving it undefined.

In any case, I didn't understood the need for all the autocmds in the end of the plugin/node.vim, and while debugging the E121 error I noticed that s:detect() is called for every buffer opened, including the help files, which causes unnecessary overhead. I've implemented a simpler solution, but it is possible it missed some corner case.

I intended to run the automated tests, but I'm not familiar with ruby. Did you have the chance to write the post explaining the tests which is mentioned in #4?