| @ -0,0 +1,2 @@ | |||
| doc/tags | |||
| .netrwhist | |||
| @ -1 +0,0 @@ | |||
| Andri Möll <andri@dot.ee> | |||
| @ -1,8 +0,0 @@ | |||
| /Makefile | |||
| /test/* | |||
| /Gemfile | |||
| /Gemfile.lock | |||
| /Guardfile | |||
| /*.zip | |||
| /node.tar.gz | |||
| tags | |||
| @ -1,7 +0,0 @@ | |||
| language: ruby | |||
| rvm: | |||
| - 1.9.3 | |||
| before_install: sudo apt-get install vim-gtk | |||
| install: bundle install --deployment --without development | |||
| script: xvfb-run make test | |||
| @ -1,57 +0,0 @@ | |||
| ## Unreleased | |||
| - Fixes `gf` on scoped modules (`require("@scope/example")`). | |||
| - Initializes Node.vim `gf` and other mappings when the `'filetype'` is set, | |||
| rather than when reading a file. | |||
| This allows you to manually set the filetype to JavaScript after opening | |||
| a file, for example, and still get Node.vim's mappings. | |||
| - Initializes Node.vim mappings for JSX (those with the `jsx` filetype) files. | |||
| - Adds `.es` to detected suffixes, so you can `gf` over `./foo` to open | |||
| `./foo.es`. | |||
| - Updates URLs to use <https://github.com/nodejs/node> instead of the previous | |||
| Joyent repo. | |||
| Thanks, [Jacky Alciné](https://jacky.wtf), for the help! | |||
| ## 0.8.1 (Apr 15, 2014) | |||
| - Updates the URL from which Node.vim downloads Node core module source files. | |||
| Uses <http://rawgit.com> which used to be named <http://rawgithub.com>. | |||
| Because of Vim Netrw's inability to handle HTTPS, it does so over HTTP. Sorry. | |||
| ## 0.8.0 (Sep 6, 2013) | |||
| - Adds `node` as a core module so you could use `:Nedit node` to open the file Node uses to bootstrap its core. | |||
| ## 0.7.0 (Aug 28, 2013) | |||
| - Adds support for opening core Node.js modules, such as `http`, `util`, etc. with `gf` or `:Nedit`. | |||
| They're shown straight from Node's online repository without you having to download everything. | |||
| ## 0.6.0 (Aug 23, 2013) | |||
| - Adds `:Nedit` command for editing modules or files relative to the Node project root. | |||
| For example: `:Nedit any-module/lib` or `:Nedit ./package`. | |||
| - Adds `:Nopen` command which behaves like `:Nedit`, but also `lcd`s to the module's directory. | |||
| - Makes `<Plug>NodeGotoFile` available for your mapping in any Node project file, but maps it to `gf` automatically only on JavaScript files. | |||
| - Maps `gf` also for JSON files for easy jumping to modules. | |||
| - Makes `:Nedit` and `:Nopen` available immediately when starting Vim in a directory of a Node project. | |||
| ## 0.5.1 (Aug 8, 2013) | |||
| - Adds `Node` autocommand. | |||
| Use it with `autocmd User Node` to customize settings for files in Node projects. | |||
| - Adds `<Plug>NodeVSplitGotoFile` for those who want `<C-w>f` to split vertically. | |||
| ## 0.5.0 (Aug 5, 2013) | |||
| - Adds `&include` pattern so Vim can recognize included/required files, e.g. for looking up keywords with `[I`. | |||
| - Cleans `&path` from `/usr/include` for JavaScript files. | |||
| - Adds a new superb `gf` handler to handle all relative and module paths, incl. support for `require(".")` to open `./index.js`. This is spot on how Node.js finds your requires. | |||
| - Adds `<Plug>NodeGotoFile` should you want to remap Node.vim's file opener. | |||
| - Opens files before directories should both, e.g. `./foo.js` and `./foo`, exist. This matches Node.js's behavior. | |||
| - Adds a full automated integration test suite to Node.vim which is freaking amazing! | |||
| ## 0.2.0 (Jul 28, 2013) | |||
| - Adds full support for navigating to module files by using `gf` on `require("any-module")`. | |||
| - Adds `.json` to `&suffixesadd` so you could use `gf` on `require("./package")` to open package.json. | |||
| ## 0.1.1 (Jul 28, 2013) | |||
| - Removes an innocent but forgotten debugging line. | |||
| ## 0.1.0 (Jul 28, 2013) | |||
| - First release to get the nodeballs rolling. | |||
| - Sets the filetype to JavaScript for files with Node's shebang (`#!`). | |||
| - Adds `.js` to `&suffixesadd` so you could use `gf` on `require("./foo")` to open `foo.js`. | |||
| @ -1,11 +0,0 @@ | |||
| source "https://rubygems.org" | |||
| group :development do | |||
| gem "guard-minitest" | |||
| gem "minitest-reporters" | |||
| end | |||
| group :test do | |||
| gem "minitest", "< 5" | |||
| gem "vimrunner", :git => "https://github.com/moll/vimrunner.git" | |||
| end | |||
| @ -1,59 +0,0 @@ | |||
| GIT | |||
| remote: https://github.com/moll/vimrunner.git | |||
| revision: 4b1ee072e52dea871a0c3370f215f54fe596a9dc | |||
| specs: | |||
| vimrunner (0.3.0) | |||
| GEM | |||
| remote: https://rubygems.org/ | |||
| specs: | |||
| ansi (1.4.3) | |||
| builder (3.2.2) | |||
| coderay (1.0.9) | |||
| ffi (1.9.0) | |||
| formatador (0.2.4) | |||
| guard (1.8.2) | |||
| formatador (>= 0.2.4) | |||
| listen (>= 1.0.0) | |||
| lumberjack (>= 1.0.2) | |||
| pry (>= 0.9.10) | |||
| thor (>= 0.14.6) | |||
| guard-minitest (1.0.1) | |||
| guard (>= 1.8) | |||
| minitest (>= 2.1) | |||
| hashie (2.0.5) | |||
| listen (1.2.2) | |||
| rb-fsevent (>= 0.9.3) | |||
| rb-inotify (>= 0.9) | |||
| rb-kqueue (>= 0.2) | |||
| lumberjack (1.0.4) | |||
| method_source (0.8.2) | |||
| minitest (4.7.5) | |||
| minitest-reporters (0.14.20) | |||
| ansi | |||
| builder | |||
| minitest (>= 2.12, < 5.0) | |||
| powerbar | |||
| powerbar (1.0.11) | |||
| ansi (~> 1.4.0) | |||
| hashie (>= 1.1.0) | |||
| pry (0.9.12.2) | |||
| coderay (~> 1.0.5) | |||
| method_source (~> 0.8) | |||
| slop (~> 3.4) | |||
| rb-fsevent (0.9.3) | |||
| rb-inotify (0.9.0) | |||
| ffi (>= 0.5.0) | |||
| rb-kqueue (0.2.0) | |||
| ffi (>= 0.5.0) | |||
| slop (3.4.6) | |||
| thor (0.18.1) | |||
| PLATFORMS | |||
| ruby | |||
| DEPENDENCIES | |||
| guard-minitest | |||
| minitest (< 5) | |||
| minitest-reporters | |||
| vimrunner! | |||
| @ -1,8 +0,0 @@ | |||
| guard :minitest, :all_on_start => false, :cli => ENV["TEST_OPTS"] do | |||
| watch(%r(^(.*)\.vim$)) {|m| "test/#{m[1]}_test.rb" } | |||
| watch(%r(^([^/]+)/[^/]+\.vim$)) {|m| "test/#{m[1]}_test.rb" } | |||
| watch(%r(^([^/]+)/[^/]+/(.*)\.vim$)) {|m| "test/#{m[1]}/#{m[2]}_test.rb" } | |||
| watch(%r(^test/(.*)\/?_test\.rb)) | |||
| watch(%r(^test/helper\.rb)) { "test" } | |||
| end | |||
| @ -1,20 +0,0 @@ | |||
| Node.vim | |||
| Copyright (C) 2013 Andri Möll | |||
| This program is free software: you can redistribute it and/or modify it under | |||
| the terms of the GNU Affero General Public License as published by the Free | |||
| Software Foundation, either version 3 of the License, or any later version. | |||
| Additional permission under the GNU Affero GPL version 3 section 7: | |||
| If you modify this Program, or any covered work, by linking or | |||
| combining it with other code, such other code is not for that reason | |||
| alone subject to any of the requirements of the GNU Affero GPL version 3. | |||
| In summary: | |||
| - You can use this program for no cost. | |||
| - You can use this program for both personal and commercial reasons. | |||
| - You do not have to share your own program's code which uses this program. | |||
| - You have to share modifications (e.g bug-fixes) you've made to this program. | |||
| For the full copy of the GNU Affero General Public License see: | |||
| http://www.gnu.org/licenses. | |||
| @ -1,40 +0,0 @@ | |||
| NAME = node | |||
| TITLE = Node.vim | |||
| VERSION = 0.8.1 | |||
| ID = 4674 | |||
| TEST_OPTS = | |||
| love: | |||
| @echo "Feel like makin' love." | |||
| test: spec | |||
| autotest: autospec | |||
| spec: $(shell find . -name "*_test.rb") | |||
| @ruby -rbundler/setup $(addprefix -r./,$^) -e "" -- $(TEST_OPTS) | |||
| autospec: | |||
| @bundle exec guard start --no-interactions | |||
| pack: | |||
| rm -rf "$(NAME)-$(VERSION).zip" | |||
| zip -r "$(NAME)-$(VERSION).zip" * -x @.packignore | |||
| publish: | |||
| open "http://www.vim.org/scripts/add_script_version.php?script_id=$(ID)" | |||
| tag: | |||
| git tag "v$(VERSION)" | |||
| node.tar.gz: | |||
| wget -c "https://github.com/nodejs/node/archive/master.tar.gz" -O node.tar.gz | |||
| list-core-modules: node.tar.gz | |||
| tar tf node.tar.gz |\ | |||
| egrep "^node[^/]*/lib/.+" |\ | |||
| xargs -n1 basename -s .js |\ | |||
| { cat; echo node; } | sort | |||
| .PHONY: love | |||
| .PHONY: spec autospec | |||
| .PHONY: pack publish tag | |||
| @ -1,105 +0,0 @@ | |||
| Node.vim | |||
| ======== | |||
| [](https://travis-ci.org/moll/vim-node) | |||
| Tools to make Vim superb for developing with Node.js. | |||
| It's the Node equivalent of [Rails.vim (vimscript #1567)](https://github.com/tpope/vim-rails) and [Rake.vim (vimscript #3669)](https://github.com/tpope/vim-rake). | |||
| This is just the first release to get the nodes rolling. If you've collected great helpers and shortcuts that help you work with Node, please share them via [email](mailto:andri@dot.ee), [Twitter](https://twitter.com/theml) or [GitHub issues](https://github.com/moll/vim-node/issues) so we could incorporate them here, too! Thanks! | |||
| ### Tour | |||
| - Use `gf` on paths or requires to open the same file Node.js would. | |||
| - Use `gf` on `require(".")` to open `./index.js` | |||
| - Use `gf` on `require("./dir")` to open `./dir/index.js` | |||
| - Use `gf` on `require("./foo")` to open `foo.js`. | |||
| - Use `gf` on `require("./package")` and have it open package.json. | |||
| - Use `gf` on `require("module")` to open the module's main file (parsed for you from `package.json`). | |||
| - Use `gf` on `require("module/lib/utils")` and open files inside the module. | |||
| - Automatically sets the filetype to JavaScript for files with Node's shebang (`#!`). | |||
| - Use `[I` etc. to look for a keyword in required files (Sets Vim's `&include`). | |||
| - Use `:Nedit` to quickly edit any module, file in a module or your project file. | |||
| - Use `:Nopen` to quickly edit any module and `lcd` to its directory. | |||
| - Lets you even open Node's core modules. They're shown straight from Node's online repository without you having to download everything. | |||
| - Node.vim itself is tested with a thorough automated integration test suite! No cowboy coding here! | |||
| Expect more to come soon and feel free to let me know what you're after! | |||
| PS. Node.vim is absolutely intended to work on Windows, but not yet tested there at all. If you could help, try it out and report issues, I'd be grateful! | |||
| Installing | |||
| ---------- | |||
| The easiest and most modular way is to download this to `~/.vim/bundle`: | |||
| ``` | |||
| mkdir -p ~/.vim/bundle/node | |||
| ``` | |||
| Using Git: | |||
| ``` | |||
| git clone https://github.com/moll/vim-node.git ~/.vim/bundle/node | |||
| ``` | |||
| Using Wget: | |||
| ``` | |||
| wget https://github.com/moll/vim-node/archive/master.tar.gz -O- | tar -xf- --strip-components 1 -C ~/.vim/bundle/node | |||
| ``` | |||
| Then prepend that directory to Vim's `&runtimepath` (or use [Pathogen](https://github.com/tpope/vim-pathogen)): | |||
| ``` | |||
| :set runtimepath^=~/.vim/bundle/node | |||
| ``` | |||
| ### Vundle | |||
| Or use [Vundle](https://github.com/gmarik/Vundle.vim): | |||
| ``` | |||
| :BundleInstall moll/vim-node | |||
| ``` | |||
| Using | |||
| ----- | |||
| Open any JavaScript file inside a Node project and you're all set. | |||
| - Use `gf` inside `require("...")` to jump to source and module files. | |||
| - Use `[I` on any keyword to look for it in the current and required files. | |||
| - Use `:Nedit module_name` to edit the main file of a module. | |||
| - Use `:Nedit module_name/lib/foo` to edit its `lib/foo.js` file. | |||
| - Use `:Nedit .` to edit your Node projects main (usually `index.js`) file. | |||
| #### Want to customize settings for files inside a Node projects? | |||
| Use the `Node` autocommand. For example: | |||
| ```vim | |||
| autocmd User Node if &filetype == "javascript" | setlocal expandtab | endif | |||
| ``` | |||
| #### Want `<C-w>f` to open the file under the cursor in a new vertical split? | |||
| `<C-w>f` by default opens it in a horizontal split. To have it open vertically, drop this in your `vimrc`: | |||
| ```vim | |||
| autocmd User Node | |||
| \ if &filetype == "javascript" | | |||
| \ nmap <buffer> <C-w>f <Plug>NodeVSplitGotoFile | | |||
| \ nmap <buffer> <C-w><C-f> <Plug>NodeVSplitGotoFile | | |||
| \ endif | |||
| ``` | |||
| License | |||
| ------- | |||
| Node.vim is released under a *Lesser GNU Affero General Public License*, which in summary means: | |||
| - You **can** use this program for **no cost**. | |||
| - You **can** use this program for **both personal and commercial reasons**. | |||
| - You **do not have to share your own program's code** which uses this program. | |||
| - You **have to share modifications** (e.g bug-fixes) you've made to this program. | |||
| For more convoluted language, see the `LICENSE` file. | |||
| About | |||
| ----- | |||
| **[Andri Möll](http://themoll.com)** authored this in SublemacslipseMate++. | |||
| [Monday Calendar](https://mondayapp.com) supported the engineering work. | |||
| If you find Node.vim needs improving or you've got a question, please don't hesitate to email me anytime at [andri@dot.ee](mailto:andri@dot.ee), tweet at [@theml](https://twitter.com/theml) or [create an issue online](https://github.com/moll/vim-node/issues). | |||
| @ -1,110 +0,0 @@ | |||
| " Vim by default sets the filetype to JavaScript for the following suffices. | |||
| " And, yes, it has .jsx there. | |||
| let node#suffixesadd = [".js", ".json", ".es", ".jsx"] | |||
| function! node#initialize(root) | |||
| let b:node_root = a:root | |||
| command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nedit | |||
| \ exe s:nedit(<q-args>, bufname("%"), "edit<bang>") | |||
| command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nopen | |||
| \ exe s:nopen(<q-args>, bufname("%"), "edit<bang>") | |||
| nnoremap <buffer><silent> <Plug>NodeGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"))<CR> | |||
| nnoremap <buffer><silent> <Plug>NodeSplitGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"), "split")<CR> | |||
| nnoremap <buffer><silent> <Plug>NodeVSplitGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"), "vsplit")<CR> | |||
| nnoremap <buffer><silent> <Plug>NodeTabGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"), "tab split")<CR> | |||
| silent doautocmd User Node | |||
| endfunction | |||
| function! node#javascript() | |||
| " This might be called multiple times if multiple filetypes match. | |||
| if exists("b:node_javascript") && b:node_javascript | return | endif | |||
| let b:node_javascript = 1 | |||
| setlocal path-=/usr/include | |||
| let &l:suffixesadd .= "," . join(g:node#suffixesadd, ",") | |||
| let &l:include = '\<require(\(["'']\)\zs[^\1]\+\ze\1' | |||
| let &l:includeexpr = "node#lib#find(v:fname, bufname('%'))" | |||
| " @ is used for scopes, but isn't a default filename character on | |||
| " non-Windows sytems. | |||
| setlocal isfname+=@-@ | |||
| if !hasmapto("<Plug>NodeGotoFile") | |||
| " Split gotofiles don't take a count for the new window's width, but for | |||
| " opening the nth file. Though Node.vim doesn't support counts atm. | |||
| nmap <buffer> gf <Plug>NodeGotoFile | |||
| nmap <buffer> <C-w>f <Plug>NodeSplitGotoFile | |||
| nmap <buffer> <C-w><C-f> <Plug>NodeSplitGotoFile | |||
| nmap <buffer> <C-w>gf <Plug>NodeTabGotoFile | |||
| endif | |||
| endfunction | |||
| function! s:edit(name, from, ...) | |||
| if empty(a:name) | return | endif | |||
| let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h") | |||
| let command = a:0 == 1 ? a:1 : "edit" | |||
| " If just a plain filename with no directory part, check if it exists: | |||
| if a:name !~# '^\v(/|\./|\.\./)' && filereadable(dir . "/" . a:name) | |||
| let path = dir . "/" . a:name | |||
| else | |||
| let path = node#lib#find(a:name, dir) | |||
| end | |||
| if empty(path) | |||
| return s:error("E447: Can't find file \"" . a:name . "\" in path") | |||
| endif | |||
| exe command . " " . fnameescape(path) | |||
| endfunction | |||
| function! s:nedit(name, from, ...) | |||
| let command = a:0 == 1 ? a:1 : "edit" | |||
| call s:edit(a:name, b:node_root, command) | |||
| endfunction | |||
| function! s:nopen(name, from, ...) | |||
| let command = a:0 == 1 ? a:1 : "edit" | |||
| call s:nedit(a:name, a:from, command) | |||
| if exists("b:node_root") | exe "lcd " . fnameescape(b:node_root) | endif | |||
| endfunction | |||
| function! s:complete(arg, cmd, cursor) | |||
| let matches = node#lib#glob(s:dirname(a:arg)) | |||
| " Show private modules (_*) only if explicitly asked: | |||
| if a:arg[0] != "_" | call filter(matches, "v:val[0] != '_'") | endif | |||
| let filter = "stridx(v:val, a:arg) == 0" | |||
| let ignorecase = 0 | |||
| let ignorecase = ignorecase || exists("&fileignorecase") && &fileignorecase | |||
| let ignorecase = ignorecase || exists("&wildignorecase") && &wildignorecase | |||
| if ignorecase | let filter = "stridx(tolower(v:val),tolower(a:arg)) == 0" | en | |||
| return filter(matches, filter) | |||
| endfunction | |||
| function! s:dirname(path) | |||
| let dirname = fnamemodify(a:path, ":h") | |||
| if dirname == "." | return "" | endif | |||
| " To not change the amount of final consecutive slashes, using this | |||
| " dirname/basename trick: | |||
| let basename = fnamemodify(a:path, ":t") | |||
| return a:path[0 : 0 - len(basename) - 1] | |||
| endfunction | |||
| " Using the built-in :echoerr prints a stacktrace, which isn't that nice. | |||
| function! s:error(msg) | |||
| echohl ErrorMsg | |||
| echomsg a:msg | |||
| echohl NONE | |||
| let v:errmsg = a:msg | |||
| endfunction | |||
| @ -1,151 +0,0 @@ | |||
| let s:ABSPATH = '^/' | |||
| let s:RELPATH = '\v^\.\.?(/|$)' | |||
| let s:MODULE = '\v^(/|\.\.?(/|$))@!' | |||
| " Damn Netrw can't handle HTTPS at all. It's 2013! Insecure bastard! | |||
| let s:CORE_URL_PREFIX = "http://rawgit.com/nodejs/node" | |||
| let s:CORE_MODULES = ["_debugger", "_http_agent", "_http_client", | |||
| \ "_http_common", "_http_incoming", "_http_outgoing", "_http_server", | |||
| \ "_linklist", "_stream_duplex", "_stream_passthrough", "_stream_readable", | |||
| \ "_stream_transform", "_stream_writable", "_tls_legacy", "_tls_wrap", | |||
| \ "assert", "buffer", "child_process", "cluster", "console", "constants", | |||
| \ "crypto", "dgram", "dns", "domain", "events", "freelist", "fs", "http", | |||
| \ "https", "module", "net", "node", "os", "path", "punycode", "querystring", | |||
| \ "readline", "repl", "smalloc", "stream", "string_decoder", "sys", | |||
| \ "timers", "tls", "tty", "url", "util", "vm", "zlib"] | |||
| function! node#lib#find(name, from) | |||
| if index(s:CORE_MODULES, a:name) != -1 | |||
| let l:version = node#lib#version() | |||
| let l:version = empty(l:version) ? "master" : "v" . l:version | |||
| let l:dir = a:name == "node" ? "src" : "lib" | |||
| return s:CORE_URL_PREFIX ."/". l:version ."/". l:dir ."/". a:name .".js" | |||
| endif | |||
| return s:resolve(s:absolutize(a:name, a:from)) | |||
| endfunction | |||
| function! node#lib#version() | |||
| if exists("b:node_version") | return b:node_version | endif | |||
| if !executable("node") | let b:node_version = "" | return | endif | |||
| let b:node_version = matchstr(system("node --version"), '^v\?\zs[0-9.]\+') | |||
| return b:node_version | |||
| endfunction | |||
| function! s:absolutize(name, from) | |||
| if a:name =~# s:ABSPATH | |||
| return a:name | |||
| elseif a:name =~# s:RELPATH | |||
| let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h") | |||
| return dir . "/" . a:name | |||
| else | |||
| return b:node_root . "/node_modules/" . a:name | |||
| endif | |||
| endfunction | |||
| function! s:resolve(path) | |||
| " Node checks for files *before* directories, so see if the path does not | |||
| " end with a slash or dots and try to match it as a file. | |||
| if a:path !~# '\v/(\.\.?/?)?$' | |||
| let path_with_suffix = s:resolveSuffix(a:path) | |||
| if !empty(path_with_suffix) | return path_with_suffix | endif | |||
| endif | |||
| if isdirectory(a:path) | return s:resolveFromDirectory(a:path) | endif | |||
| endfunction | |||
| function! s:resolveFromDirectory(path) | |||
| " Node.js checks for package.json in every directory, not just the | |||
| " module's parent. According to: | |||
| " http://nodejs.org/api/modules.html#modules_all_together | |||
| if filereadable(a:path . "/package.json") | |||
| " Turns out, even though Node says it does not support directories in | |||
| " main, it does. | |||
| " NOTE: If package.json's main is empty or refers to a non-existent file, | |||
| " ./index.js is still tried. | |||
| let main = s:mainFromPackage(a:path . "/package.json") | |||
| if !empty(main) && main != "" | |||
| let path = s:resolve(a:path . "/" . main) | |||
| if !empty(path) | return path | endif | |||
| endif | |||
| endif | |||
| " We need to check for ./index.js's existence here rather than leave it to | |||
| " the caller, because otherwise we can't distinguish if this ./index was | |||
| " from the directory defaulting to ./index.js or it was the package.json | |||
| " which referred to ./index, which in itself could mean both ./index.js and | |||
| " ./index/index.js. | |||
| return s:resolveSuffix(a:path . "/index") | |||
| endfunction | |||
| function! s:mainFromPackage(path) | |||
| for line in readfile(a:path) | |||
| if line !~# '"main"\s*:' | continue | endif | |||
| return matchstr(line, '"main"\s*:\s*"\zs[^"]\+\ze"') | |||
| endfor | |||
| endfunction | |||
| function! s:resolveSuffix(path) | |||
| for suffix in s:uniq([""] + g:node#suffixesadd + split(&l:suffixesadd, ",")) | |||
| let path = a:path . suffix | |||
| if filereadable(path) | return path | endif | |||
| endfor | |||
| endfunction | |||
| let s:GLOB_WILDIGNORE = 1 | |||
| function! node#lib#glob(name) | |||
| let matches = [] | |||
| if empty(a:name) | |||
| let matches += s:CORE_MODULES | |||
| endif | |||
| if empty(a:name) || a:name =~# s:MODULE | |||
| let root = b:node_root . "/node_modules" | |||
| let matches += s:glob(empty(a:name) ? root : root . "/" . a:name, root) | |||
| endif | |||
| if a:name =~# s:ABSPATH | |||
| let matches += s:glob(a:name, 0) | |||
| endif | |||
| if empty(a:name) || a:name =~# s:RELPATH | |||
| let root = b:node_root | |||
| let relatives = s:glob(empty(a:name) ? root : root . "/" . a:name, root) | |||
| "call map(relatives, "substitute(v:val, '^\./\./', './', '')") | |||
| if empty(a:name) | call map(relatives, "'./' . v:val") | endif | |||
| call filter(relatives, "v:val !~# '^\\.//*node_modules/$'") | |||
| let matches += relatives | |||
| endif | |||
| return matches | |||
| endfunction | |||
| function! s:glob(path, stripPrefix) | |||
| " Remove a single trailing slash because we're adding one with the glob. | |||
| let path = substitute(a:path, '/$', "", "") | |||
| " Glob() got the ability to return a list only in Vim 7.3.465. Using split | |||
| " for compatibility. | |||
| let list = split(glob(fnameescape(path)."/*", s:GLOB_WILDIGNORE), "\n") | |||
| " Add slashes to directories, like /bin/ls. | |||
| call map(list, "v:val . (isdirectory(v:val) ? '/' : '')") | |||
| if !empty(a:stripPrefix) | |||
| " Counting and removing bytes intentionally as there's no substr function | |||
| " that takes character count, only bytes. | |||
| let prefix_length = len(a:stripPrefix) + 1 | |||
| return map(list, "strpart(v:val, prefix_length)") | |||
| endif | |||
| return list | |||
| endfunction | |||
| function! s:uniq(list) | |||
| let list = reverse(copy(a:list)) | |||
| return reverse(filter(list, "index(list, v:val, v:key + 1) == -1")) | |||
| endfunction | |||
| @ -1,8 +0,0 @@ | |||
| function! s:isNode() | |||
| let shebang = getline(1) | |||
| if shebang =~# '^#!.*/bin/env\s\+node\>' | return 1 | en | |||
| if shebang =~# '^#!.*/bin/node\>' | return 1 | en | |||
| return 0 | |||
| endfunction | |||
| au BufRead,BufNewFile * if !did_filetype() && s:isNode() | setf javascript | en | |||
| @ -1,47 +0,0 @@ | |||
| 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 | |||
| @ -1,466 +0,0 @@ | |||
| require_relative "../helper" | |||
| require "json" | |||
| describe "Lib" do | |||
| include WithTemporaryDirectory | |||
| before do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| end | |||
| def set_node_version(version) | |||
| executable = File.join(@dir, "node") | |||
| touch executable, <<-end.strip | |||
| #!/bin/sh | |||
| [ $# != 1 -o "$1" != --version ] && exit 1 | |||
| echo "v#{version}" | |||
| end | |||
| File.chmod 0755, executable | |||
| $vim.command(%(let $PATH = "#@dir:" . $PATH)) | |||
| end | |||
| describe "node#lib#find" do | |||
| def find(name) | |||
| path = $vim.echo(%(node#lib#find("#{name}", expand("%")))) | |||
| File.exists?(path) ? File.realpath(path) : path | |||
| end | |||
| it "must return ./README before ./README.js" do | |||
| target = touch File.join(@dir, "README") | |||
| touch File.join(@dir, "README.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./README").must_equal target | |||
| end | |||
| it "must return ./README.txt relative to file" do | |||
| target = touch File.join(@dir, "lib", "README.txt") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("./README.txt").must_equal target | |||
| end | |||
| it "must return ../README.txt" do | |||
| target = touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("../README.txt").must_equal target | |||
| end | |||
| it "must return /.../README.txt" do | |||
| target = touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir/README.txt").must_equal target | |||
| end | |||
| it "must return ./other.js given ./other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.jsx given ./other" do | |||
| target = touch File.join(@dir, "other.jsx") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.es given ./other" do | |||
| target = touch File.join(@dir, "other.es") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.js given ./other relative to file" do | |||
| target = touch File.join(@dir, "lib", "other.js") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.js before ./other/index.js given ./other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| touch File.join(@dir, "other", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ../other.js given ../other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("../other").must_equal target | |||
| end | |||
| it "must return /.../other.js given /.../other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir/other").must_equal target | |||
| end | |||
| it "must return ./package.json given ./package" do | |||
| target = touch File.join(@dir, "package.json") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./package").must_equal target | |||
| end | |||
| it "must return ./index.js given ." do | |||
| target = touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| find(".").must_equal target | |||
| end | |||
| it "must return ./index.js given ./" do | |||
| target = touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| find("./").must_equal target | |||
| end | |||
| it "must not find ./index/index.js given ./" do | |||
| touch File.join(@dir, "index", "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.echo(%(empty(node#lib#find("./", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must not find ./.js given ./" do | |||
| touch File.join(@dir, ".js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.echo(%(empty(node#lib#find("./", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must return ../index.js given .." do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "other.js") | |||
| find("..").must_equal target | |||
| end | |||
| it "must return ../index.js given ../" do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "other.js") | |||
| find("../").must_equal target | |||
| end | |||
| it "must return /.../index.js given /..." do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir").must_equal target | |||
| end | |||
| it "must return /.../index.js given /.../" do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir/").must_equal target | |||
| end | |||
| it "must return ./lib/index.js given ./lib" do | |||
| target = touch File.join(@dir, "lib", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./lib/other.js given ./lib with main" do | |||
| target = touch File.join(@dir, "lib", "other.js") | |||
| touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "other") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./lib/index.js given ./lib with empty main" do | |||
| target = touch File.join(@dir, "lib", "index.js") | |||
| touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./lib/index.js given ./lib with non-existent main" do | |||
| target = touch File.join(@dir, "lib", "index.js") | |||
| touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "new") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./other.js before ./other/index.js given . with main" do | |||
| touch File.join(@dir, "package.json"), JSON.dump(:main => "other") | |||
| target = touch File.join(@dir, "other.js") | |||
| touch File.join(@dir, "other", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find(".").must_equal target | |||
| end | |||
| it "must return node_modules/foo/index.js given foo" do | |||
| index = File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch index | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal index | |||
| end | |||
| it "must return node_modules/foo/other.js given foo/other" do | |||
| other = File.join(@dir, "node_modules", "foo", "other.js") | |||
| touch other | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo/other").must_equal other | |||
| end | |||
| it "must return node_modules/foo/other.js given foo/other.js" do | |||
| other = File.join(@dir, "node_modules", "foo", "other.js") | |||
| touch other | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo/other.js").must_equal other | |||
| end | |||
| # When package.json refers to a regular file. | |||
| it "must return node_modules/foo/other.js given foo with main" do | |||
| mod = File.join(@dir, "node_modules", "foo") | |||
| touch File.join(mod, "package.json"), JSON.dump(:main => "./other.js") | |||
| target = touch File.join(mod, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal target | |||
| end | |||
| # When package.json refers to a directory. | |||
| it "must return node_modules/foo/lib/index.js given foo with main as ./lib" do | |||
| mod = File.join(@dir, "node_modules", "foo") | |||
| touch File.join(mod, "package.json"), JSON.dump(:main => "./lib") | |||
| target = touch File.join(mod, "lib/index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal target | |||
| end | |||
| it "must return node_modules/foo/lib/index.js given foo with main as lib" do | |||
| mod = File.join(@dir, "node_modules", "foo") | |||
| touch File.join(mod, "package.json"), JSON.dump(:main => "lib") | |||
| target = touch File.join(mod, "lib/index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal target | |||
| end | |||
| it "must return node_modules/@scope/foo/index.js given @scope/foo" do | |||
| target = File.join(@dir, "node_modules", "@scope", "foo", "index.js") | |||
| touch target | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("@scope/foo").must_equal target | |||
| end | |||
| it "must return empty when looking for nothing" do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo(%(empty(node#lib#find("", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must return empty when nothing found" do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo(%(empty(node#lib#find("new", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must return URL for core module for current Node version" do | |||
| set_node_version "0.13.37" | |||
| $vim.edit File.join(@dir, "index.js") | |||
| url = "http://rawgit.com/nodejs/node/v0.13.37/lib/assert.js" | |||
| find("assert").must_equal url | |||
| end | |||
| it "must return URL for core module on master if no Node version" do | |||
| touch File.join(@dir, "node"), "#!/bin/sh\nexit 1" | |||
| File.chmod 0755, File.join(@dir, "node") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let $PATH = "#@dir:" . $PATH)) | |||
| url = "http://rawgit.com/nodejs/node/master/lib/assert.js" | |||
| find("assert").must_equal url | |||
| end | |||
| it "must return URL for node.js for current Node version" do | |||
| set_node_version "0.13.37" | |||
| $vim.edit File.join(@dir, "index.js") | |||
| url = "http://rawgit.com/nodejs/node/v0.13.37/src/node.js" | |||
| find("node").must_equal url | |||
| end | |||
| it "must return URL for node.js on master if no Node version" do | |||
| touch File.join(@dir, "node"), "#!/bin/sh\nexit 1" | |||
| File.chmod 0755, File.join(@dir, "node") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let $PATH = "#@dir:" . $PATH)) | |||
| url = "http://rawgit.com/nodejs/node/master/src/node.js" | |||
| find("node").must_equal url | |||
| end | |||
| end | |||
| describe "node#lib#glob" do | |||
| require "json" | |||
| before do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| end | |||
| def glob(arg = "") | |||
| # Because of possible locale and filesystem case-sensitiveness | |||
| # differences, sort the output explicitly to be resistant. | |||
| JSON.parse($vim.echo(%(node#lib#glob("#{arg}"))).gsub("'", '"')).sort | |||
| end | |||
| describe "given nothing" do | |||
| it "must return files and directories" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| files = %w[./README.txt ./index.js ./test/] | |||
| glob.must_equal (CORE_MODULES + files).sort | |||
| end | |||
| it "must return modules and core modules" do | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "require-guard") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "export") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul") | |||
| glob.must_equal (CORE_MODULES + %w[export/ require-guard/ soul/]).sort | |||
| end | |||
| it "must return core modules without slashes" do | |||
| glob.must_equal CORE_MODULES | |||
| glob.wont_equal /\// | |||
| end | |||
| # Even though node.js is the bootstrapper file in src/. | |||
| it "must return \"node\" as one of those core modules" do | |||
| glob.must_include "node" | |||
| end | |||
| it "must return files, directories and modules" do | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "export") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul") | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| files = %w[./README.txt ./index.js ./test/ export/ soul/] | |||
| glob.must_equal (CORE_MODULES + files).sort | |||
| end | |||
| it "must not return the node_modules directory" do | |||
| FileUtils.mkpath File.join(@dir, "node_modules") | |||
| glob.must_equal CORE_MODULES | |||
| end | |||
| end | |||
| describe "given absolute path" do | |||
| it "must return files and directories given /" do | |||
| files = Dir.entries("/") | |||
| files.reject! {|f| f =~ /^\./ } | |||
| files.sort! | |||
| files.map! {|f| "/" + f } | |||
| files.map! {|f| File.directory?(f) ? f + "/" : f } | |||
| glob("/").must_equal files | |||
| end | |||
| it "must return files and directories given /.../" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/] | |||
| glob(@dir).must_equal files | |||
| end | |||
| it "must return files and directories given /.../test" do | |||
| touch File.join(@dir, "test", "index_test.js") | |||
| touch File.join(@dir, "test", "helpers.js") | |||
| files = %W[#@dir/test/helpers.js #@dir/test/index_test.js] | |||
| glob(File.join(@dir, "test")).must_equal files | |||
| end | |||
| it "must not return modules along with files" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul") | |||
| files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/] | |||
| glob(@dir).must_equal files | |||
| end | |||
| end | |||
| describe "given relative path" do | |||
| it "must return files and directories given ." do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob(".").must_equal %W[./README ./index.js ./test/] | |||
| end | |||
| it "must return files and directories given ./" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob("./").must_equal %W[./README ./index.js ./test/] | |||
| end | |||
| it "must return files and directories given .//" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob(".//").must_equal %W[.//README.txt .//index.js .//test/] | |||
| end | |||
| it "must return files and directories given .///" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob(".///").must_equal %W[.///README.txt .///index.js .///test/] | |||
| end | |||
| it "must return files and directories given ./test" do | |||
| touch File.join(@dir, "test", "test.js") | |||
| touch File.join(@dir, "test", "helpers.js") | |||
| glob("./test/").must_equal %W[./test/helpers.js ./test/test.js] | |||
| end | |||
| end | |||
| describe "given module name" do | |||
| it "must return files and directories given soul" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "README") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul").must_equal %w[soul/README soul/index.js soul/test/] | |||
| end | |||
| it "must return files and directories given soul/" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul/").must_equal %w[soul/index.js soul/test/] | |||
| end | |||
| it "must return files and directories given soul//" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul//").must_equal %w[soul//index.js soul//test/] | |||
| end | |||
| it "must return files and directories given soul///" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul///").must_equal %w[soul///index.js soul///test/] | |||
| end | |||
| it "must return files and directories given soul/test" do | |||
| touch File.join(@dir, "node_modules", "soul", "test", "test.js") | |||
| touch File.join(@dir, "node_modules", "soul", "test", "helpers.js") | |||
| glob("soul/test").must_equal %w[soul/test/helpers.js soul/test/test.js] | |||
| end | |||
| end | |||
| end | |||
| describe "node#lib#version" do | |||
| it "should return current Node's version" do | |||
| set_node_version "0.13.37" | |||
| $vim.echo("node#lib#version()").must_equal "0.13.37" | |||
| end | |||
| end | |||
| end | |||
| @ -1,538 +0,0 @@ | |||
| require_relative "./helper" | |||
| require "json" | |||
| describe "Autoloaded" do | |||
| include WithTemporaryDirectory | |||
| before do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| end | |||
| after do | |||
| $vim.command("windo wincmd c") | |||
| end | |||
| describe "Autocommand" do | |||
| it "must fire user autcommand \"Node\"" do | |||
| $vim.command "au User Node let node_autocommand = 1337" | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.echo(%(g:node_autocommand)).must_equal "1337" | |||
| end | |||
| end | |||
| describe "Goto file" do | |||
| it "must define plug mapping in non-JavaScript files" do | |||
| $vim.edit File.join(@dir, "README") | |||
| $vim.echo(%(maparg("<Plug>NodeGotoFile", "n"))).wont_equal "" | |||
| end | |||
| it "must not be mapped in non-JavaScript files" do | |||
| $vim.edit File.join(@dir, "README") | |||
| $vim.echo(%(hasmapto("<Plug>NodeGotoFile"))).must_equal "0" | |||
| end | |||
| it "must edit README.txt" do | |||
| touch File.join(@dir, "index.js"), %(// Please read README.txt) | |||
| touch File.join(@dir, "README.txt") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$gf" | |||
| $vim.echo(%(bufname("%"))).must_equal File.join(@dir, "README.txt") | |||
| end | |||
| it "must edit README before README.js" do | |||
| touch File.join(@dir, "index.js"), "// Please read README" | |||
| touch File.join(@dir, "README") | |||
| touch File.join(@dir, "README.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "README") | |||
| end | |||
| it "must edit ./README.txt relative to file" do | |||
| touch File.join(@dir, "foo", "index.js"), %(// Please read ./README.txt) | |||
| touch File.join(@dir, "foo", "README.txt") | |||
| $vim.edit File.join(@dir, "foo", "index.js") | |||
| $vim.feedkeys "$gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "foo", "README.txt") | |||
| end | |||
| it "must edit /.../README.txt" do | |||
| touch File.join(@dir, "index.js"), %(// Read #@dir/lib/README.txt) | |||
| touch File.join(@dir, "lib", "README.txt") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "lib", "README.txt") | |||
| end | |||
| it "must edit ./other.js relative to file" do | |||
| touch File.join(@dir, "foo", "index.js"), %(require("./other")) | |||
| touch File.join(@dir, "foo", "other.js") | |||
| $vim.edit File.join(@dir, "foo", "index.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "foo", "other.js") | |||
| end | |||
| it "must edit ./index.js given ." do | |||
| touch File.join(@dir, "other.js"), %(require(".")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./index.js given ./" do | |||
| touch File.join(@dir, "other.js"), %(require("./")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ../index.js given .." do | |||
| touch File.join(@dir, "foo", "other.js"), %(require("..")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "foo", "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ../index.js given ../" do | |||
| touch File.join(@dir, "foo", "other.js"), %(require("../")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "foo", "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./node_modules/foo/index.js given foo" do | |||
| touch File.join(@dir, "index.js"), %(require("foo")) | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must edit ./node_modules/@scope/foo/index.js given @scope/foo" do | |||
| touch File.join(@dir, "index.js"), %(require("@scope/foo")) | |||
| target = File.join(@dir, "node_modules", "@scope", "foo", "index.js") | |||
| touch target | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must not show an error when searching for nothing" do | |||
| touch File.join(@dir, "index.js"), %("") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let v:errmsg = "")) | |||
| $vim.feedkeys "gf" | |||
| error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "") | |||
| error.must_equal "" | |||
| end | |||
| it "must show error when searching for a non-existent file" do | |||
| touch File.join(@dir, "index.js"), %(require("new")) | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let v:errmsg = "")) | |||
| $vim.feedkeys "$hhgf" | |||
| error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "") | |||
| error.must_equal %(E447: Can't find file "new" in path) | |||
| end | |||
| it "must find when filetype is JavaScript and file exists" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.js"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype is JavaScript and file new" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.insert %(require("foo")) | |||
| $vim.normal | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype is JSON" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| # NOTE: Use an extensionless file and set ft manually to not have | |||
| # filetype.vim set its filetype to JavaScript automatically. | |||
| $vim.command("au BufReadPre package set ft=json") | |||
| touch File.join(@dir, "package"), %({"dependencies": {"foo": "1.x"}}) | |||
| $vim.edit File.join(@dir, "package") | |||
| $vim.echo("&filetype").must_equal "json" | |||
| $vim.feedkeys "/foo\\<CR>gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal target | |||
| end | |||
| it "must find when filetype set to JavaScript after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype javascript") | |||
| $vim.echo("&filetype").must_equal "javascript" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype set to JSX after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype jsx") | |||
| $vim.echo("&filetype").must_equal "jsx" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype set to JavaScript and Foo after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype javascript.foo") | |||
| $vim.echo("&filetype").must_equal "javascript.foo" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| # Ensure the autocommand detects both orderings. | |||
| it "must find when filetype set to Foo and JavaScript after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype foo.javascript") | |||
| $vim.echo("&filetype").must_equal "foo.javascript" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| end | |||
| describe "Goto file with split" do | |||
| it "must edit file in a new split" do | |||
| touch File.join(@dir, "index.js"), %(require("./other")) | |||
| touch File.join(@dir, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "f.\\<C-w>f" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "other.js") | |||
| $vim.echo(%(winnr("$"))).must_equal "2" | |||
| end | |||
| end | |||
| describe "Goto file with tab" do | |||
| it "must edit file in a new tab" do | |||
| touch File.join(@dir, "index.js"), %(require("./other")) | |||
| touch File.join(@dir, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "f.\\<C-w>gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "other.js") | |||
| $vim.echo(%(tabpagenr("$"))).must_equal "2" | |||
| end | |||
| end | |||
| describe "Include file search pattern" do | |||
| it "must find matches given a require" do | |||
| touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "") | |||
| var awesome = require("foo") | |||
| awesome() | |||
| end | |||
| definition = %(module.exports = function awesome() { return 1337 }) | |||
| touch File.join(@dir, "node_modules", "foo", "index.js"), definition | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command("normal G[i").must_equal definition | |||
| end | |||
| it "must find matches given a relative require" do | |||
| touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "") | |||
| var awesome = require("./other") | |||
| awesome() | |||
| end | |||
| definition = %(module.exports = function awesome() { return 1337 }) | |||
| touch File.join(@dir, "other.js"), definition | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command("normal G[i").must_equal definition | |||
| end | |||
| it "must find matches given a relative require in another directory" do | |||
| touch File.join(@dir, "foo", "index.js"), <<-end.gsub(/^\s+/, "") | |||
| var awesome = require("./other") | |||
| awesome() | |||
| end | |||
| definition = %(module.exports = function awesome() { return 1337 }) | |||
| touch File.join(@dir, "foo", "other.js"), definition | |||
| $vim.edit File.join(@dir, "foo", "index.js") | |||
| $vim.command("normal G[i").must_equal definition | |||
| end | |||
| end | |||
| describe ":Nedit" do | |||
| # NOTE: Test from a non-JavaScript file everywhere to make sure there are | |||
| # no dependencies on JavaScript specific settings. | |||
| FULL_COMMAND_MATCH = "2" | |||
| it "must be available in non-JavaScript files" do | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH | |||
| end | |||
| it "must be available in JavaScript files" do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH | |||
| end | |||
| it "must edit ./README.txt" do | |||
| touch File.join(@dir, "README.txt") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit ./README.txt" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "README.txt") | |||
| end | |||
| it "must edit ./README.txt relative to node_root" do | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") | |||
| $vim.command "Nedit ./README.txt" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "README.txt") | |||
| end | |||
| it "must edit /.../README.txt" do | |||
| touch File.join(@dir, "lib", "README.txt") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit #@dir/lib/README.txt" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "lib", "README.txt") | |||
| end | |||
| it "must edit ./other.js relative to node_root" do | |||
| touch File.join(@dir, "other.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") | |||
| $vim.command "Nedit ./other" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "other.js") | |||
| end | |||
| it "must edit ./index.js given ." do | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit ." | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./index.js given . relative to node_root" do | |||
| touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") | |||
| $vim.command "Nedit ." | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./index.js given ./" do | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit ./" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit /node_modules/foo/index.js given foo" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.command("Nedit foo") | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| describe "completion" do | |||
| after do | |||
| $vim.command("set wildignorecase&") | |||
| $vim.command("set fileignorecase&") | |||
| end | |||
| def complete(cmd) | |||
| cmdline = $vim.command(%(silent! normal! :#{cmd}e)) | |||
| cmdline.sub(/^:\w+\s+/, "") | |||
| end | |||
| public_core_modules = CORE_MODULES.select {|m| m[0] != "_" } | |||
| private_core_modules = CORE_MODULES.select {|m| m[0] == "_" } | |||
| it "must return files, directories, modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| Dir.mkdir File.join(@dir, "node_modules", "require-guard") | |||
| Dir.mkdir File.join(@dir, "node_modules", "export") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soul") | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| files = %w[export/ require-guard/ soul/ ./index.js ./package.json] | |||
| all = public_core_modules + files | |||
| complete("Nedit ").split.sort.must_equal all.sort | |||
| end | |||
| it "must return only public core modules" do | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| modules = public_core_modules + ["./package.json"] | |||
| complete("Nedit ").must_equal modules.join(" ") | |||
| end | |||
| it "must return private core modules if explicitly asked" do | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit _").must_equal private_core_modules.join(" ") | |||
| end | |||
| it "must return only matching modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| Dir.mkdir File.join(@dir, "node_modules", "export") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soul") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soulstash") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| modules = "smalloc stream string_decoder sys soul/ soulstash/" | |||
| complete("Nedit s").must_equal modules | |||
| end | |||
| it "must not return modules with matching bit in the middle" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soul") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soulstash") | |||
| Dir.mkdir File.join(@dir, "node_modules", "asoul") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit sou").must_equal "soul/ soulstash/" | |||
| end | |||
| it "must return files and directories in module's directory" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "test", "test.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul/").must_equal "soul/index.js soul/test/" | |||
| end | |||
| it "must return files and directories given a double slash" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "test", "test.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul//").must_equal "soul//index.js soul//test/" | |||
| end | |||
| it "must return files case-insensitively given &fileignorecase" do | |||
| skip if $vim.echo(%(exists("&fileignorecase"))) != "1" | |||
| $vim.command("set fileignorecase") | |||
| $vim.command("set nowildignorecase") | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "CHANGELOG") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul/chan").must_equal "soul/CHANGELOG" | |||
| end | |||
| it "must return files case-insensitively given only &wildignorecase" do | |||
| skip if $vim.echo(%(exists("&wildignorecase"))) != "1" | |||
| $vim.command("set nofileignorecase") | |||
| $vim.command("set wildignorecase") | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "CHANGELOG") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul/chan").must_equal "soul/CHANGELOG" | |||
| end | |||
| end | |||
| end | |||
| describe ":Nopen" do | |||
| it "must edit and lcd to module's directory" do | |||
| touch File.join(@dir, "node_modules", "foo", "package.json") | |||
| touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.command("vsplit") | |||
| $vim.command("Nopen foo") | |||
| $vim.echo(%(bufname("%"))).must_equal "index.js" | |||
| $vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo") | |||
| $vim.command("wincmd p") | |||
| $vim.command("pwd").must_equal Dir.pwd | |||
| end | |||
| it "must edit and lcd to module's root directory" do | |||
| touch File.join(@dir, "node_modules", "foo", "package.json") | |||
| utils = touch File.join(@dir, "node_modules", "foo", "lib", "utils.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.command("vsplit") | |||
| $vim.command("Nopen foo/lib/utils") | |||
| $vim.echo(%(bufname("%"))).must_equal "lib/utils.js" | |||
| $vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo") | |||
| $vim.command("wincmd p") | |||
| $vim.command("pwd").must_equal Dir.pwd | |||
| end | |||
| end | |||
| end | |||
| @ -1,45 +0,0 @@ | |||
| require_relative "./helper" | |||
| describe "Ftdetect" do | |||
| [ | |||
| "#!/usr/bin/env node", | |||
| "#!/usr/bin/env node --harmony-generators", | |||
| "#!/usr/local/bin/env node", | |||
| "#!/usr/local/bin/env node --harmony-generators", | |||
| "#!/usr/bin/node", | |||
| "#!/usr/bin/node --harmony-generators", | |||
| "#!/usr/local/bin/node", | |||
| "#!/usr/local/bin/node --harmony-generators", | |||
| ].each do |shebang| | |||
| it %(must detect a file with "#{shebang}" shebang as JavaScript) do | |||
| file = Tempfile.new("bang") | |||
| file.write shebang + $/ | |||
| file.close | |||
| $vim.edit file.path | |||
| $vim.echo("&ft").must_equal "javascript" | |||
| end | |||
| end | |||
| [ | |||
| "#!/usr/bin/env noder", | |||
| "#!/usr/bin/noder", | |||
| ].each do |shebang| | |||
| it %(must not detect a file with "#{shebang}" shebang as JavaScript) do | |||
| file = Tempfile.new("bang") | |||
| file.write shebang + $/ | |||
| file.close | |||
| $vim.edit file.path | |||
| $vim.echo("&ft").wont_equal "javascript" | |||
| end | |||
| end | |||
| it "must not detect a .c file as JavaScript even with Node's shebang" do | |||
| file = Tempfile.new(%w[tea .c]) | |||
| file.write "#!/usr/bin/node" + $/ | |||
| file.close | |||
| $vim.edit file.path | |||
| $vim.echo("&ft").wont_equal "javascript" | |||
| end | |||
| end | |||
| @ -1,54 +0,0 @@ | |||
| require "minitest/autorun" | |||
| require "vimrunner" | |||
| require "fileutils" | |||
| require "tempfile" | |||
| MiniTest::Unit::TestCase.define_singleton_method(:test_order) do :alpha end | |||
| begin | |||
| require "minitest/reporters" | |||
| MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new | |||
| rescue LoadError | |||
| end | |||
| $vimrc = File.expand_path("../vimrc", __FILE__) | |||
| $vim = Vimrunner::Server.new(:vimrc => $vimrc).start | |||
| Minitest::Unit.after_tests { $vim.kill } | |||
| module WithTemporaryDirectory | |||
| def self.included(base) | |||
| require "tmpdir" | |||
| end | |||
| def setup | |||
| super | |||
| # Mac has the temporary directory symlinked, so need File.realpath to | |||
| # match the paths that Vim returns. | |||
| @dir = File.realpath(Dir.mktmpdir) | |||
| end | |||
| def teardown | |||
| FileUtils.remove_entry_secure @dir | |||
| super | |||
| end | |||
| end | |||
| def touch(path, contents = nil) | |||
| FileUtils.mkpath File.dirname(path) | |||
| if contents.nil? || contents.empty? | |||
| FileUtils.touch(path) | |||
| else | |||
| File.open(path, "w") {|f| f.write contents } | |||
| end | |||
| path | |||
| end | |||
| CORE_MODULES = %w[_debugger _http_agent _http_client _http_common | |||
| _http_incoming _http_outgoing _http_server _linklist _stream_duplex | |||
| _stream_passthrough _stream_readable _stream_transform _stream_writable | |||
| _tls_legacy _tls_wrap assert buffer child_process cluster console | |||
| constants crypto dgram dns domain events freelist fs http https module | |||
| net node os path punycode querystring readline repl smalloc stream | |||
| string_decoder sys timers tls tty url util vm zlib] | |||
| @ -1,85 +0,0 @@ | |||
| require_relative "./helper" | |||
| describe "Plugin" do | |||
| include WithTemporaryDirectory | |||
| describe "b:node_root" do | |||
| it "must be set when in same directory with package.json" do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set when in same directory with node_modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set when ancestor directory has package.json" do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| nested = File.join(@dir, "lib", "awesomeness") | |||
| FileUtils.mkdir_p nested | |||
| $vim.edit File.join(nested, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set when ancestor directory has node_modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| nested = File.join(@dir, "lib", "awesomeness") | |||
| FileUtils.mkdir_p nested | |||
| $vim.edit File.join(nested, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set also for other filetypes" do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set in nested Node projects" do | |||
| nested = File.join(@dir, "node_modules", "require-guard") | |||
| FileUtils.mkdir_p nested | |||
| FileUtils.touch File.join(nested, "package.json") | |||
| test = File.join(nested, "test") | |||
| FileUtils.mkdir_p test | |||
| $vim.edit File.join(test, "index_test.js") | |||
| $vim.echo("b:node_root").must_equal nested | |||
| end | |||
| it "must not be set when no ancestor has one" do | |||
| $vim.edit File.join(@dir, "index_test.js") | |||
| $vim.echo(%(exists("b:node_root"))).must_equal "0" | |||
| end | |||
| it "must be set from file, not working directory" do | |||
| $vim.command "cd #{@dir}" | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| nested = File.join(@dir, "node_modules", "require-guard") | |||
| FileUtils.mkdir_p nested | |||
| FileUtils.touch File.join(nested, "package.json") | |||
| $vim.edit File.join(nested, "index_test.js") | |||
| $vim.echo("b:node_root").must_equal nested | |||
| end | |||
| it "must detect directory as Node's when opening Vim" do | |||
| begin | |||
| Dir.chdir @dir | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| vim = Vimrunner::Server.new(:vimrc => $vimrc).start | |||
| vim.command("pwd").must_equal @dir | |||
| vim.echo("b:node_root").must_equal @dir | |||
| ensure | |||
| vim.kill if vim | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @ -1,14 +0,0 @@ | |||
| set nocompatible | |||
| set noswapfile | |||
| set nobackup | |||
| set hidden | |||
| set runtimepath-=~/.vim | |||
| set runtimepath-=~/.vim/after | |||
| let &runtimepath = expand("<sfile>:p:h:h") . "," . &runtimepath | |||
| filetype plugin indent on | |||
| syntax on | |||
| set columns=80 lines=24 | |||
| winpos 1337 0 | |||
| @ -1,13 +0,0 @@ | |||
| *Requisite minimal reproducible example, formatted as plain text :* | |||
| <hr> | |||
| #### Optional: concerning jsx. | |||
| PLEASE PLEASE PLEASE make sure you have properly | |||
| setup and are sourcing this plugin https://github.com/mxw/vim-jsx | |||
| WE DO NOT support JSX automatically, you need another plugin to add get this | |||
| functionality. | |||
| Make sure the bug still exists if you disable all other javascript plugins | |||
| except the one noted above, mxw/vim-jsx | |||
| @ -1,119 +0,0 @@ | |||
| # vim-javascript | |||
| JavaScript bundle for vim, this bundle provides syntax highlighting and | |||
| improved indentation. | |||
| ## Installation | |||
| ### Install with [pathogen](https://github.com/tpope/vim-pathogen) | |||
| git clone https://github.com/pangloss/vim-javascript.git ~/.vim/bundle/vim-javascript | |||
| alternatively, use a package manager like [vim-plug](https://github.com/junegunn/vim-plug) | |||
| ## Configuration Variables | |||
| The following variables control certain syntax highlighting plugins. You can | |||
| add them to your `.vimrc` to enable their features. | |||
| ----------------- | |||
| ``` | |||
| let g:javascript_plugin_jsdoc = 1 | |||
| ``` | |||
| Enables syntax highlighting for [JSDocs](http://usejsdoc.org/). | |||
| Default Value: 0 | |||
| ----------------- | |||
| ``` | |||
| let g:javascript_plugin_ngdoc = 1 | |||
| ``` | |||
| Enables some additional syntax highlighting for NGDocs. Requires JSDoc plugin | |||
| to be enabled as well. | |||
| Default Value: 0 | |||
| ----------------- | |||
| ``` | |||
| let g:javascript_plugin_flow = 1 | |||
| ``` | |||
| Enables syntax highlighting for [Flow](https://flowtype.org/). | |||
| Default Value: 0 | |||
| ----------------- | |||
| ```vim | |||
| augroup javascript_folding | |||
| au! | |||
| au FileType javascript setlocal foldmethod=syntax | |||
| augroup END | |||
| ``` | |||
| Enables code folding for javascript based on our syntax file. | |||
| Please note this can have a dramatic effect on performance. | |||
| ## Concealing Characters | |||
| You can customize concealing characters, if your font provides the glyph you want, by defining one or more of the following | |||
| variables: | |||
| let g:javascript_conceal_function = "ƒ" | |||
| let g:javascript_conceal_null = "ø" | |||
| let g:javascript_conceal_this = "@" | |||
| let g:javascript_conceal_return = "⇚" | |||
| let g:javascript_conceal_undefined = "¿" | |||
| let g:javascript_conceal_NaN = "ℕ" | |||
| let g:javascript_conceal_prototype = "¶" | |||
| let g:javascript_conceal_static = "•" | |||
| let g:javascript_conceal_super = "Ω" | |||
| let g:javascript_conceal_arrow_function = "⇒" | |||
| let g:javascript_conceal_noarg_arrow_function = "🞅" | |||
| let g:javascript_conceal_underscore_arrow_function = "🞅" | |||
| You can enable concealing within VIM with: | |||
| set conceallevel=1 | |||
| OR if you wish to toggle concealing you may wish to bind a command such as the following which will map `<LEADER>l` (leader is usually the `\` key) to toggling conceal mode: | |||
| map <leader>l :exec &conceallevel ? "set conceallevel=0" : "set conceallevel=1"<CR> | |||
| ## Indentation Specific | |||
| * `:h cino-:` | |||
| * `:h cino-=` | |||
| * `:h cino-star` | |||
| * `:h cino-(` | |||
| * `:h cino-w` | |||
| * `:h cino-W` | |||
| * `:h cino-U` | |||
| * `:h cino-m` | |||
| * `:h cino-M` | |||
| * `:h 'indentkeys'` | |||
| ## Contributing | |||
| Please follow the general code style | |||
| guides (read the code) and in your pull request explain the reason for the | |||
| proposed change and how it is valuable. All p.r.'s will be reviewed by a | |||
| maintainer(s) then, hopefully, merged. | |||
| Thank you! | |||
| ## License | |||
| Distributed under the same terms as Vim itself. See `:help license`. | |||
| @ -1,12 +0,0 @@ | |||
| " Vim filetype plugin file | |||
| " Language: JavaScript | |||
| " Maintainer: vim-javascript community | |||
| " URL: https://github.com/pangloss/vim-javascript | |||
| setlocal iskeyword+=$ suffixesadd+=.js | |||
| if exists('b:undo_ftplugin') | |||
| let b:undo_ftplugin .= ' | setlocal iskeyword< suffixesadd<' | |||
| else | |||
| let b:undo_ftplugin = 'setlocal iskeyword< suffixesadd<' | |||
| endif | |||
| @ -1,16 +0,0 @@ | |||
| " Vim compiler plugin | |||
| " Language: JavaScript | |||
| " Maintainer: vim-javascript community | |||
| " URL: https://github.com/pangloss/vim-javascript | |||
| if exists("current_compiler") | |||
| finish | |||
| endif | |||
| let current_compiler = "eslint" | |||
| if exists(":CompilerSet") != 2 | |||
| command! -nargs=* CompilerSet setlocal <args> | |||
| endif | |||
| CompilerSet makeprg=eslint\ -f\ compact\ % | |||
| CompilerSet errorformat=%f:\ line\ %l\\,\ col\ %c\\,\ %m | |||
| @ -1,8 +0,0 @@ | |||
| --langdef=js | |||
| --langmap=js:.js | |||
| --regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/,object/ | |||
| --regex-js=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/,function/ | |||
| --regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*([^)])/\1/,function/ | |||
| --regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/,array/ | |||
| --regex-js=/([^= ]+)[ \t]*=[ \t]*[^"]'[^']*/\1/,string/ | |||
| --regex-js=/([^= ]+)[ \t]*=[ \t]*[^']"[^"]*/\1/,string/ | |||
| @ -1,105 +0,0 @@ | |||
| syntax region jsFlowDefinition contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen | |||
| syntax region jsFlowArgumentDef contained start=/:/ end=/\%(\s*[,)]\|=>\@!\)\@=/ contains=@jsFlowCluster | |||
| syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster,jsComment fold | |||
| syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster,jsComment fold | |||
| syntax region jsFlowExactObject contained matchgroup=jsFlowNoise start=/{|/ end=/|}/ contains=@jsFlowCluster,jsComment fold | |||
| syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster keepend fold | |||
| syntax match jsFlowNoise contained /[:;,<>]/ | |||
| syntax keyword jsFlowType contained boolean number string null void any mixed JSON array Function object array bool class | |||
| syntax keyword jsFlowTypeof contained typeof skipempty skipempty nextgroup=jsFlowTypeCustom,jsFlowType | |||
| syntax match jsFlowTypeCustom contained /[0-9a-zA-Z_.]*/ skipwhite skipempty nextgroup=jsFlowGroup | |||
| syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=/</ end=/>/ contains=@jsFlowCluster | |||
| syntax region jsFlowArrowArguments contained matchgroup=jsFlowNoise start=/(/ end=/)\%(\s*=>\)\@=/ oneline skipwhite skipempty nextgroup=jsFlowArrow contains=@jsFlowCluster | |||
| syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens | |||
| syntax match jsFlowObjectKey contained /[0-9a-zA-Z_$?]*\(\s*:\)\@=/ contains=jsFunctionKey,jsFlowMaybe skipwhite skipempty nextgroup=jsObjectValue containedin=jsObject | |||
| syntax match jsFlowOrOperator contained /|/ skipwhite skipempty nextgroup=@jsFlowCluster | |||
| syntax keyword jsFlowImportType contained type skipwhite skipempty nextgroup=jsModuleAsterisk,jsModuleKeyword,jsModuleGroup | |||
| syntax match jsFlowWildcard contained /*/ | |||
| syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster,jsFlowArrow,jsFlowReturnParens | |||
| syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold | |||
| syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp fold | |||
| syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp,jsFlowReturnArrow fold | |||
| syntax match jsFlowReturnArrow contained /=>/ skipwhite skipempty nextgroup=@jsFlowReturnCluster | |||
| syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock,jsFlowReturnOrOp | |||
| syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword,jsFlowReturnObject | |||
| syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=/</ end=/>/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp | |||
| syntax match jsFlowReturnOrOp contained /\s*|\s*/ skipwhite skipempty nextgroup=@jsFlowReturnCluster | |||
| syntax match jsFlowWildcardReturn contained /*/ skipwhite skipempty nextgroup=jsFuncBlock | |||
| syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=/</ end=/>/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncArgs | |||
| syntax region jsFlowClassGroup contained matchgroup=jsFlowNoise start=/</ end=/>/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock | |||
| syntax region jsFlowTypeStatement start=/type\%(\s\+\k\)\@=/ end=/=\@=/ contains=jsFlowTypeOperator oneline skipwhite skipempty nextgroup=jsFlowTypeValue keepend | |||
| syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/=/ end=/[\n;]/ contains=@jsFlowCluster,jsFlowGroup,jsFlowMaybe | |||
| syntax match jsFlowTypeOperator contained /=/ containedin=jsFlowTypeValue | |||
| syntax match jsFlowTypeOperator contained /=/ | |||
| syntax keyword jsFlowTypeKeyword contained type | |||
| syntax keyword jsFlowDeclare declare skipwhite skipempty nextgroup=jsFlowTypeStatement,jsClassDefinition,jsStorageClass,jsFlowModule,jsFlowInterface | |||
| syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlowClassDef containedin=jsClassBlock | |||
| syntax region jsFlowClassDef contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassValue | |||
| syntax region jsFlowModule contained start=/module/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowDeclareBlock contains=jsString | |||
| syntax region jsFlowInterface contained start=/interface/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowInterfaceBlock contains=@jsFlowCluster | |||
| syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise fold | |||
| " NOTE: It appears the nextgroup was causing a ton of breakages... testing it | |||
| " witout a nextgroup, but keeping this arround for reference incase something breaks | |||
| " syntax match jsFlowMaybe contained /?/ nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments,jsFlowObject,jsFlowReturnObject extend keepend | |||
| syntax match jsFlowMaybe contained /?/ | |||
| syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend fold | |||
| syntax region jsFlowParenAnnotation contained start=/:/ end=/[,=)]\@=/ containedin=jsParen contains=@jsFlowCluster | |||
| syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp,jsFlowWildcardReturn,jsFlowReturnArrow | |||
| syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowExactObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator,jsFlowWildcard | |||
| if version >= 508 || !exists("did_javascript_syn_inits") | |||
| if version < 508 | |||
| let did_javascript_syn_inits = 1 | |||
| command -nargs=+ HiLink hi link <args> | |||
| else | |||
| command -nargs=+ HiLink hi def link <args> | |||
| endif | |||
| HiLink jsFlowDefinition PreProc | |||
| HiLink jsFlowClassDef jsFlowDefinition | |||
| HiLink jsFlowArgumentDef jsFlowDefinition | |||
| HiLink jsFlowType Type | |||
| HiLink jsFlowTypeCustom PreProc | |||
| HiLink jsFlowTypeof PreProc | |||
| HiLink jsFlowArray PreProc | |||
| HiLink jsFlowObject PreProc | |||
| HiLink jsFlowExactObject PreProc | |||
| HiLink jsFlowParens PreProc | |||
| HiLink jsFlowGroup PreProc | |||
| HiLink jsFlowReturn PreProc | |||
| HiLink jsFlowParenAnnotation PreProc | |||
| HiLink jsFlowReturnObject jsFlowReturn | |||
| HiLink jsFlowReturnArray jsFlowArray | |||
| HiLink jsFlowReturnParens jsFlowParens | |||
| HiLink jsFlowReturnGroup jsFlowGroup | |||
| HiLink jsFlowFunctionGroup PreProc | |||
| HiLink jsFlowClassGroup PreProc | |||
| HiLink jsFlowArrowArguments PreProc | |||
| HiLink jsFlowArrow PreProc | |||
| HiLink jsFlowReturnArrow PreProc | |||
| HiLink jsFlowTypeStatement PreProc | |||
| HiLink jsFlowTypeKeyword PreProc | |||
| HiLink jsFlowTypeOperator Operator | |||
| HiLink jsFlowMaybe PreProc | |||
| HiLink jsFlowReturnMaybe PreProc | |||
| HiLink jsFlowClassProperty jsClassProperty | |||
| HiLink jsFlowDeclare PreProc | |||
| HiLink jsFlowModule PreProc | |||
| HiLink jsFlowInterface PreProc | |||
| HiLink jsFlowNoise Noise | |||
| HiLink jsFlowObjectKey jsObjectKey | |||
| HiLink jsFlowOrOperator jsOperator | |||
| HiLink jsFlowReturnOrOp jsFlowOrOperator | |||
| HiLink jsFlowWildcard PreProc | |||
| HiLink jsFlowWildcardReturn PreProc | |||
| HiLink jsFlowImportType PreProc | |||
| HiLink jsFlowTypeValue PreProc | |||
| delcommand HiLink | |||
| endif | |||
| @ -1,39 +0,0 @@ | |||
| "" syntax coloring for javadoc comments (HTML) | |||
| syntax region jsComment matchgroup=jsComment start="/\*\s*" end="\*/" contains=jsDocTags,jsCommentTodo,jsCvsTag,@jsHtml,@Spell fold | |||
| " tags containing a param | |||
| syntax match jsDocTags contained "@\(alias\|api\|augments\|borrows\|class\|constructs\|default\|defaultvalue\|emits\|exception\|exports\|extends\|fires\|kind\|link\|listens\|member\|member[oO]f\|mixes\|module\|name\|namespace\|requires\|template\|throws\|var\|variation\|version\)\>" skipwhite nextgroup=jsDocParam | |||
| " tags containing type and param | |||
| syntax match jsDocTags contained "@\(arg\|argument\|cfg\|param\|property\|prop\|typedef\)\>" skipwhite nextgroup=jsDocType | |||
| " tags containing type but no param | |||
| syntax match jsDocTags contained "@\(callback\|define\|enum\|external\|implements\|this\|type\|return\|returns\)\>" skipwhite nextgroup=jsDocTypeNoParam | |||
| " tags containing references | |||
| syntax match jsDocTags contained "@\(lends\|see\|tutorial\)\>" skipwhite nextgroup=jsDocSeeTag | |||
| " other tags (no extra syntax) | |||
| syntax match jsDocTags contained "@\(abstract\|access\|accessor\|async\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>" | |||
| syntax region jsDocType contained matchgroup=jsDocTypeBrackets start="{" end="}" contains=jsDocTypeRecord oneline skipwhite nextgroup=jsDocParam | |||
| syntax match jsDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" skipwhite nextgroup=jsDocParam | |||
| syntax region jsDocTypeRecord contained start=/{/ end=/}/ contains=jsDocTypeRecord extend | |||
| syntax region jsDocTypeRecord contained start=/\[/ end=/\]/ contains=jsDocTypeRecord extend | |||
| syntax region jsDocTypeNoParam contained start="{" end="}" oneline | |||
| syntax match jsDocTypeNoParam contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" | |||
| syntax match jsDocParam contained "\%(#\|\$\|-\|'\|\"\|{.\{-}}\|\w\|\.\|:\|\/\|\[.\{-}]\|=\)\+" | |||
| syntax region jsDocSeeTag contained matchgroup=jsDocSeeTag start="{" end="}" contains=jsDocTags | |||
| if version >= 508 || !exists("did_javascript_syn_inits") | |||
| if version < 508 | |||
| let did_javascript_syn_inits = 1 | |||
| command -nargs=+ HiLink hi link <args> | |||
| else | |||
| command -nargs=+ HiLink hi def link <args> | |||
| endif | |||
| HiLink jsDocTags Special | |||
| HiLink jsDocSeeTag Function | |||
| HiLink jsDocType Type | |||
| HiLink jsDocTypeBrackets jsDocType | |||
| HiLink jsDocTypeRecord jsDocType | |||
| HiLink jsDocTypeNoParam Type | |||
| HiLink jsDocParam Label | |||
| delcommand HiLink | |||
| endif | |||
| @ -1,3 +0,0 @@ | |||
| syntax match jsDocTags contained /@\(link\|method[oO]f\|ngdoc\|ng[iI]nject\|restrict\)/ nextgroup=jsDocParam skipwhite | |||
| syntax match jsDocType contained "\%(#\|\$\|\w\|\"\|-\|\.\|:\|\/\)\+" nextgroup=jsDocParam skipwhite | |||
| syntax match jsDocParam contained "\%(#\|\$\|\w\|\"\|-\|\.\|:\|{\|}\|\/\|\[\|]\|=\)\+" | |||
| @ -1,17 +0,0 @@ | |||
| au BufNewFile,BufRead *.{js,mjs,jsm,es,es6},Jakefile setf javascript | |||
| fun! s:SourceFlowSyntax() | |||
| if !exists('javascript_plugin_flow') && !exists('b:flow_active') && | |||
| \ search('\v\C%^\_s*%(//\s*|/\*[ \t\n*]*)\@flow>','nw') | |||
| runtime extras/flow.vim | |||
| let b:flow_active = 1 | |||
| endif | |||
| endfun | |||
| au FileType javascript au BufRead,BufWritePost <buffer> call s:SourceFlowSyntax() | |||
| fun! s:SelectJavascript() | |||
| if getline(1) =~# '^#!.*/bin/\%(env\s\+\)\?node\>' | |||
| set ft=javascript | |||
| endif | |||
| endfun | |||
| au BufNewFile,BufRead * call s:SelectJavascript() | |||
| @ -1,475 +0,0 @@ | |||
| " Vim indent file | |||
| " Language: Javascript | |||
| " Maintainer: Chris Paul ( https://github.com/bounceme ) | |||
| " URL: https://github.com/pangloss/vim-javascript | |||
| " Last Change: September 18, 2017 | |||
| " Only load this indent file when no other was loaded. | |||
| if exists('b:did_indent') | |||
| finish | |||
| endif | |||
| let b:did_indent = 1 | |||
| " Now, set up our indentation expression and keys that trigger it. | |||
| setlocal indentexpr=GetJavascriptIndent() | |||
| setlocal autoindent nolisp nosmartindent | |||
| setlocal indentkeys+=0],0) | |||
| " Testable with something like: | |||
| " vim -eNs "+filetype plugin indent on" "+syntax on" "+set ft=javascript" \ | |||
| " "+norm! gg=G" '+%print' '+:q!' testfile.js \ | |||
| " | diff -uBZ testfile.js - | |||
| let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<' | |||
| " Only define the function once. | |||
| if exists('*GetJavascriptIndent') | |||
| finish | |||
| endif | |||
| let s:cpo_save = &cpo | |||
| set cpo&vim | |||
| " indent correctly if inside <script> | |||
| " vim/vim@690afe1 for the switch from cindent | |||
| " overridden with b:html_indent_script1 | |||
| call extend(g:,{'html_indent_script1': 'inc'},'keep') | |||
| " Regex of syntax group names that are or delimit string or are comments. | |||
| let s:bvars = { | |||
| \ 'syng_strcom': 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!', | |||
| \ 'syng_str': 'string\|template\|special' } | |||
| " template strings may want to be excluded when editing graphql: | |||
| " au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special' | |||
| " au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc' | |||
| function s:GetVars() | |||
| call extend(b:,extend(s:bvars,{'js_cache': [0,0,0]}),'keep') | |||
| endfunction | |||
| " Get shiftwidth value | |||
| if exists('*shiftwidth') | |||
| function s:sw() | |||
| return shiftwidth() | |||
| endfunction | |||
| else | |||
| function s:sw() | |||
| return &l:shiftwidth ? &l:shiftwidth : &l:tabstop | |||
| endfunction | |||
| endif | |||
| " Performance for forwards search(): start search at pos rather than masking | |||
| " matches before pos. | |||
| let s:z = has('patch-7.4.984') ? 'z' : '' | |||
| " Expression used to check whether we should skip a match with searchpair(). | |||
| let s:skip_expr = "s:SynAt(line('.'),col('.')) =~? b:syng_strcom" | |||
| let s:in_comm = s:skip_expr[:-14] . "'comment\\|doc'" | |||
| let s:rel = has('reltime') | |||
| " searchpair() wrapper | |||
| if s:rel | |||
| function s:GetPair(start,end,flags,skip) | |||
| return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1,a:skip ==# 's:SkipFunc()' ? 2000 : 200) | |||
| endfunction | |||
| else | |||
| function s:GetPair(start,end,flags,skip) | |||
| return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1) | |||
| endfunction | |||
| endif | |||
| function s:SynAt(l,c) | |||
| let byte = line2byte(a:l) + a:c - 1 | |||
| let pos = index(s:synid_cache[0], byte) | |||
| if pos == -1 | |||
| let s:synid_cache[:] += [[byte], [synIDattr(synID(a:l, a:c, 0), 'name')]] | |||
| endif | |||
| return s:synid_cache[1][pos] | |||
| endfunction | |||
| function s:ParseCino(f) | |||
| let [divider, n, cstr] = [0] + matchlist(&cino, | |||
| \ '\%(.*,\)\=\%(\%d'.char2nr(a:f).'\(-\)\=\([.s0-9]*\)\)\=')[1:2] | |||
| for c in split(cstr,'\zs') | |||
| if c == '.' && !divider | |||
| let divider = 1 | |||
| elseif c ==# 's' | |||
| if n !~ '\d' | |||
| return n . s:sw() + 0 | |||
| endif | |||
| let n = str2nr(n) * s:sw() | |||
| break | |||
| else | |||
| let [n, divider] .= [c, 0] | |||
| endif | |||
| endfor | |||
| return str2nr(n) / max([str2nr(divider),1]) | |||
| endfunction | |||
| " Optimized {skip} expr, only callable from the search loop which | |||
| " GetJavascriptIndent does to find the containing [[{(] (side-effects) | |||
| function s:SkipFunc() | |||
| if s:top_col == 1 | |||
| throw 'out of bounds' | |||
| elseif s:check_in | |||
| if eval(s:skip_expr) | |||
| return 1 | |||
| endif | |||
| let s:check_in = 0 | |||
| elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$' | |||
| if eval(s:skip_expr) | |||
| return 1 | |||
| endif | |||
| elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) | |||
| if eval(s:skip_expr) | |||
| let s:check_in = 1 | |||
| return 1 | |||
| endif | |||
| else | |||
| let s:synid_cache[:] += [[line2byte('.') + col('.') - 1], ['']] | |||
| endif | |||
| let [s:looksyn, s:top_col] = getpos('.')[1:2] | |||
| endfunction | |||
| function s:AlternatePair() | |||
| let [pat, l:for] = ['[][(){};]', 2] | |||
| while s:SearchLoop(pat,'bW','s:SkipFunc()') | |||
| if s:LookingAt() == ';' | |||
| if !l:for | |||
| if s:GetPair('{','}','bW','s:SkipFunc()') | |||
| return | |||
| endif | |||
| break | |||
| else | |||
| let [pat, l:for] = ['[{}();]', l:for - 1] | |||
| endif | |||
| else | |||
| let idx = stridx('])}',s:LookingAt()) | |||
| if idx == -1 | |||
| return | |||
| elseif !s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()') | |||
| break | |||
| endif | |||
| endif | |||
| endwhile | |||
| throw 'out of bounds' | |||
| endfunction | |||
| function s:Nat(int) | |||
| return a:int * (a:int > 0) | |||
| endfunction | |||
| function s:LookingAt() | |||
| return getline('.')[col('.')-1] | |||
| endfunction | |||
| function s:Token() | |||
| return s:LookingAt() =~ '\k' ? expand('<cword>') : s:LookingAt() | |||
| endfunction | |||
| function s:PreviousToken(...) | |||
| let [l:pos, tok] = [getpos('.'), ''] | |||
| if search('\m\k\{1,}\|\S','ebW') | |||
| if getline('.')[col('.')-2:col('.')-1] == '*/' | |||
| if eval(s:in_comm) && !s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm) | |||
| call setpos('.',l:pos) | |||
| else | |||
| let tok = s:Token() | |||
| endif | |||
| else | |||
| let two = a:0 || line('.') != l:pos[1] ? strridx(getline('.')[:col('.')],'//') + 1 : 0 | |||
| if two && eval(s:in_comm) | |||
| call cursor(0,two) | |||
| let tok = s:PreviousToken(1) | |||
| if tok is '' | |||
| call setpos('.',l:pos) | |||
| endif | |||
| else | |||
| let tok = s:Token() | |||
| endif | |||
| endif | |||
| endif | |||
| return tok | |||
| endfunction | |||
| function s:Pure(f,...) | |||
| return eval("[call(a:f,a:000),cursor(a:firstline,".col('.').")][0]") | |||
| endfunction | |||
| function s:SearchLoop(pat,flags,expr) | |||
| return s:GetPair(a:pat,'\_$.',a:flags,a:expr) | |||
| endfunction | |||
| function s:ExprCol() | |||
| if getline('.')[col('.')-2] == ':' | |||
| return 1 | |||
| endif | |||
| let bal = 0 | |||
| while s:SearchLoop('[{}?:]','bW',s:skip_expr) | |||
| if s:LookingAt() == ':' | |||
| if getline('.')[col('.')-2] == ':' | |||
| call cursor(0,col('.')-1) | |||
| continue | |||
| endif | |||
| let bal -= 1 | |||
| elseif s:LookingAt() == '?' | |||
| if getline('.')[col('.'):col('.')+1] =~ '^\.\d\@!' | |||
| continue | |||
| elseif !bal | |||
| return 1 | |||
| endif | |||
| let bal += 1 | |||
| elseif s:LookingAt() == '{' | |||
| return !s:IsBlock() | |||
| elseif !s:GetPair('{','}','bW',s:skip_expr) | |||
| break | |||
| endif | |||
| endwhile | |||
| endfunction | |||
| " configurable regexes that define continuation lines, not including (, {, or [. | |||
| let s:opfirst = '^' . get(g:,'javascript_opfirst', | |||
| \ '\C\%([<>=,.?^%|/&]\|\([-:+]\)\1\@!\|\*\+\|!=\|in\%(stanceof\)\=\>\)') | |||
| let s:continuation = get(g:,'javascript_continuation', | |||
| \ '\C\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$' | |||
| function s:Continues() | |||
| let tok = matchstr(strpart(getline('.'),col('.')-15,15),s:continuation) | |||
| if tok =~ '[a-z:]' | |||
| return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.' | |||
| elseif tok !~ '[/>]' | |||
| return tok isnot '' | |||
| endif | |||
| return s:SynAt(line('.'),col('.')) !~? (tok == '>' ? 'jsflow\|^html' : 'regex') | |||
| endfunction | |||
| " Check if line 'lnum' has a balanced amount of parentheses. | |||
| function s:Balanced(lnum,line) | |||
| let l:open = 0 | |||
| let pos = match(a:line, '[][(){}]') | |||
| while pos != -1 | |||
| if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom | |||
| let l:open += match(' ' . a:line[pos],'[[({]') | |||
| if l:open < 0 | |||
| return | |||
| endif | |||
| endif | |||
| let pos = match(a:line, !l:open ? '[][(){}]' : '()' =~ a:line[pos] ? | |||
| \ '[()]' : '{}' =~ a:line[pos] ? '[{}]' : '[][]', pos + 1) | |||
| endwhile | |||
| return !l:open | |||
| endfunction | |||
| function s:OneScope() | |||
| if s:LookingAt() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr) | |||
| let tok = s:PreviousToken() | |||
| return (count(split('for if let while with'),tok) || | |||
| \ tok =~# '^await$\|^each$' && s:PreviousToken() ==# 'for') && | |||
| \ s:Pure('s:PreviousToken') != '.' && !(tok == 'while' && s:DoWhile()) | |||
| elseif s:Token() =~# '^else$\|^do$' | |||
| return s:Pure('s:PreviousToken') != '.' | |||
| endif | |||
| return strpart(getline('.'),col('.')-2,2) == '=>' | |||
| endfunction | |||
| function s:DoWhile() | |||
| let cpos = searchpos('\m\<','cbW') | |||
| while s:SearchLoop('\C[{}]\|\<\%(do\|while\)\>','bW',s:skip_expr) | |||
| if s:LookingAt() =~ '\a' | |||
| if s:Pure('s:IsBlock') | |||
| if s:LookingAt() ==# 'd' | |||
| return 1 | |||
| endif | |||
| break | |||
| endif | |||
| elseif s:LookingAt() != '}' || !s:GetPair('{','}','bW',s:skip_expr) | |||
| break | |||
| endif | |||
| endwhile | |||
| call call('cursor',cpos) | |||
| endfunction | |||
| " returns total offset from braceless contexts. 'num' is the lineNr which | |||
| " encloses the entire context, 'cont' if whether a:firstline is a continued | |||
| " expression, which could have started in a braceless context | |||
| function s:IsContOne(cont) | |||
| let [l:num, b_l] = [b:js_cache[1] + !b:js_cache[1], 0] | |||
| let pind = b:js_cache[1] ? indent(b:js_cache[1]) + s:sw() : 0 | |||
| let ind = indent('.') + !a:cont | |||
| while line('.') > l:num && ind > pind || line('.') == l:num | |||
| if indent('.') < ind && s:OneScope() | |||
| let b_l += 1 | |||
| elseif !a:cont || b_l || ind < indent(a:firstline) | |||
| break | |||
| else | |||
| call cursor(0,1) | |||
| endif | |||
| let ind = min([ind, indent('.')]) | |||
| if s:PreviousToken() is '' | |||
| break | |||
| endif | |||
| endwhile | |||
| return b_l | |||
| endfunction | |||
| function s:IsSwitch() | |||
| call call('cursor',b:js_cache[1:]) | |||
| return search('\m\C\%#.\_s*\%(\%(\/\/.*\_$\|\/\*\_.\{-}\*\/\)\@>\_s*\)*\%(case\|default\)\>','nWc'.s:z) | |||
| endfunction | |||
| " https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader | |||
| function s:IsBlock() | |||
| let tok = s:PreviousToken() | |||
| if join(s:stack) =~? 'xml\|jsx' && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx' | |||
| let s:in_jsx = 1 | |||
| return tok != '{' | |||
| elseif tok =~ '\k' | |||
| if tok ==# 'type' | |||
| return s:Pure('eval',"s:PreviousToken() !~# '^\\%(im\\|ex\\)port$' || s:PreviousToken() == '.'") | |||
| elseif tok ==# 'of' | |||
| return s:Pure('eval',"!s:GetPair('[[({]','[])}]','bW',s:skip_expr) || s:LookingAt() != '(' ||" | |||
| \ ."s:{s:PreviousToken() ==# 'await' ? 'Previous' : ''}Token() !=# 'for' || s:PreviousToken() == '.'") | |||
| endif | |||
| return index(split('return const let import export extends yield default delete var await void typeof throw case new in instanceof') | |||
| \ ,tok) < (line('.') != a:firstline) || s:Pure('s:PreviousToken') == '.' | |||
| elseif tok == '>' | |||
| return getline('.')[col('.')-2] == '=' || s:SynAt(line('.'),col('.')) =~? 'jsflow\|^html' | |||
| elseif tok == '*' | |||
| return s:Pure('s:PreviousToken') == ':' | |||
| elseif tok == ':' | |||
| return s:Pure('eval',"s:PreviousToken() =~ '^\\K\\k*$' && !s:ExprCol()") | |||
| elseif tok == '/' | |||
| return s:SynAt(line('.'),col('.')) =~? 'regex' | |||
| elseif tok !~ '[=~!<,.?^%|&([]' | |||
| return tok !~ '[-+]' || line('.') != a:firstline && getline('.')[col('.')-2] == tok | |||
| endif | |||
| endfunction | |||
| function GetJavascriptIndent() | |||
| call s:GetVars() | |||
| let s:synid_cache = [[],[]] | |||
| let l:line = getline(v:lnum) | |||
| " use synstack as it validates syn state and works in an empty line | |||
| let s:stack = [''] + map(synstack(v:lnum,1),"synIDattr(v:val,'name')") | |||
| " start with strings,comments,etc. | |||
| if s:stack[-1] =~? 'comment\|doc' | |||
| if l:line =~ '^\s*\*' | |||
| return cindent(v:lnum) | |||
| elseif l:line !~ '^\s*\/[/*]' | |||
| return -1 | |||
| endif | |||
| elseif s:stack[-1] =~? b:syng_str | |||
| if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1,getline(v:lnum-1)) | |||
| let b:js_cache[0] = v:lnum | |||
| endif | |||
| return -1 | |||
| endif | |||
| let s:l1 = max([0,prevnonblank(v:lnum) - (s:rel ? 2000 : 1000), | |||
| \ get(get(b:,'hi_indent',{}),'blocklnr')]) | |||
| call cursor(v:lnum,1) | |||
| if s:PreviousToken() is '' | |||
| return | |||
| endif | |||
| let [l:lnum, pline] = [line('.'), getline('.')[:col('.')-1]] | |||
| let l:line = substitute(l:line,'^\s*','','') | |||
| let l:line_raw = l:line | |||
| if l:line[:1] == '/*' | |||
| let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','') | |||
| endif | |||
| if l:line =~ '^\/[/*]' | |||
| let l:line = '' | |||
| endif | |||
| " the containing paren, bracket, or curly. Many hacks for performance | |||
| call cursor(v:lnum,1) | |||
| let idx = index([']',')','}'],l:line[0]) | |||
| if b:js_cache[0] > l:lnum && b:js_cache[0] < v:lnum || | |||
| \ b:js_cache[0] == l:lnum && s:Balanced(l:lnum,pline) | |||
| call call('cursor',b:js_cache[1:]) | |||
| else | |||
| let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0, | |||
| \ max([s:l1, &smc ? search('\m^.\{'.&smc.',}','nbW',s:l1 + 1) + 1 : 0])] | |||
| try | |||
| if idx != -1 | |||
| call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()') | |||
| elseif getline(v:lnum) !~ '^\S' && s:stack[-1] =~? 'block\|^jsobject$' | |||
| call s:GetPair('{','}','bW','s:SkipFunc()') | |||
| else | |||
| call s:AlternatePair() | |||
| endif | |||
| catch /^\Cout of bounds$/ | |||
| call cursor(v:lnum,1) | |||
| endtry | |||
| let b:js_cache[1:] = line('.') == v:lnum ? [0,0] : getpos('.')[1:2] | |||
| endif | |||
| let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]] | |||
| let [num_ind, is_op, b_l, l:switch_offset, s:in_jsx] = [s:Nat(indent(num)),0,0,0,0] | |||
| if !num || s:LookingAt() == '{' && s:IsBlock() | |||
| let ilnum = line('.') | |||
| if num && !s:in_jsx && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr) | |||
| if ilnum == num | |||
| let [num, num_ind] = [line('.'), indent('.')] | |||
| endif | |||
| if idx == -1 && s:PreviousToken() ==# 'switch' && s:IsSwitch() | |||
| let l:switch_offset = &cino !~ ':' ? s:sw() : s:ParseCino(':') | |||
| if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>' | |||
| return s:Nat(num_ind + l:switch_offset) | |||
| elseif &cino =~ '=' | |||
| let l:case_offset = s:ParseCino('=') | |||
| endif | |||
| endif | |||
| endif | |||
| if idx == -1 && pline[-1:] !~ '[{;]' | |||
| call cursor(l:lnum, len(pline)) | |||
| let sol = matchstr(l:line,s:opfirst) | |||
| if sol is '' || sol == '/' && s:SynAt(v:lnum, | |||
| \ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex' | |||
| if s:Continues() | |||
| let is_op = s:sw() | |||
| endif | |||
| elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' && | |||
| \ s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) && | |||
| \ s:PreviousToken() == ')' && s:GetPair('(',')','bW',s:skip_expr) && | |||
| \ (s:PreviousToken() == ']' || s:LookingAt() =~ '\k' && | |||
| \ s:{s:PreviousToken() == '*' ? 'Previous' : ''}Token() !=# 'function') | |||
| return num_ind + s:sw() | |||
| else | |||
| let is_op = s:sw() | |||
| endif | |||
| call cursor(l:lnum, len(pline)) | |||
| let b_l = s:Nat(s:IsContOne(is_op) - (!is_op && l:line =~ '^{')) * s:sw() | |||
| endif | |||
| elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U')) | |||
| let pval = s:ParseCino('(') | |||
| if !pval | |||
| let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')] | |||
| if search('\m\S','W',num) | |||
| return s:ParseCino('w') ? vcol : virtcol('.')-1 | |||
| endif | |||
| return Wval ? s:Nat(num_ind + Wval) : vcol | |||
| endif | |||
| return s:Nat(num_ind + pval + searchpair('\m(','','\m)','nbrmW',s:skip_expr,num) * s:sw()) | |||
| endif | |||
| " main return | |||
| if l:line =~ '^[])}]\|^|}' | |||
| if l:line_raw[0] == ')' | |||
| if s:ParseCino('M') | |||
| return indent(l:lnum) | |||
| elseif num && &cino =~# 'm' && !s:ParseCino('m') | |||
| return virtcol('.') - 1 | |||
| endif | |||
| endif | |||
| return num_ind | |||
| elseif num | |||
| return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op) | |||
| endif | |||
| return b_l + is_op | |||
| endfunction | |||
| let &cpo = s:cpo_save | |||
| unlet s:cpo_save | |||
| @ -1,387 +0,0 @@ | |||
| " Vim syntax file | |||
| " Language: JavaScript | |||
| " Maintainer: vim-javascript community | |||
| " URL: https://github.com/pangloss/vim-javascript | |||
| if !exists("main_syntax") | |||
| if version < 600 | |||
| syntax clear | |||
| elseif exists("b:current_syntax") | |||
| finish | |||
| endif | |||
| let main_syntax = 'javascript' | |||
| endif | |||
| " Dollar sign is permitted anywhere in an identifier | |||
| if v:version > 704 || v:version == 704 && has('patch1142') | |||
| syntax iskeyword @,48-57,_,192-255,$ | |||
| else | |||
| setlocal iskeyword+=$ | |||
| endif | |||
| syntax sync fromstart | |||
| " TODO: Figure out what type of casing I need | |||
| " syntax case ignore | |||
| syntax case match | |||
| syntax match jsNoise /[:,;]/ | |||
| syntax match jsNoise /\./ skipwhite skipempty nextgroup=jsObjectProp,jsFuncCall,jsPrototype,jsTaggedTemplate | |||
| syntax match jsObjectProp contained /\<\K\k*/ | |||
| syntax match jsFuncCall /\<\K\k*\ze\s*(/ | |||
| syntax match jsParensError /[)}\]]/ | |||
| " Program Keywords | |||
| syntax keyword jsStorageClass const var let skipwhite skipempty nextgroup=jsDestructuringBlock,jsDestructuringArray,jsVariableDef | |||
| syntax match jsVariableDef contained /\<\K\k*/ skipwhite skipempty nextgroup=jsFlowDefinition | |||
| syntax keyword jsOperator delete instanceof typeof void new in of skipwhite skipempty nextgroup=@jsExpression | |||
| syntax match jsOperator "[-!|&+<>=%/*~^]" skipwhite skipempty nextgroup=@jsExpression | |||
| syntax match jsOperator /::/ skipwhite skipempty nextgroup=@jsExpression | |||
| syntax keyword jsBooleanTrue true | |||
| syntax keyword jsBooleanFalse false | |||
| " Modules | |||
| syntax keyword jsImport import skipwhite skipempty nextgroup=jsModuleAsterisk,jsModuleKeyword,jsModuleGroup,jsFlowImportType | |||
| syntax keyword jsExport export skipwhite skipempty nextgroup=@jsAll,jsModuleGroup,jsExportDefault,jsModuleAsterisk,jsModuleKeyword,jsFlowTypeStatement | |||
| syntax match jsModuleKeyword contained /\<\K\k*/ skipwhite skipempty nextgroup=jsModuleAs,jsFrom,jsModuleComma | |||
| syntax keyword jsExportDefault contained default skipwhite skipempty nextgroup=@jsExpression | |||
| syntax keyword jsExportDefaultGroup contained default skipwhite skipempty nextgroup=jsModuleAs,jsFrom,jsModuleComma | |||
| syntax match jsModuleAsterisk contained /\*/ skipwhite skipempty nextgroup=jsModuleKeyword,jsModuleAs,jsFrom | |||
| syntax keyword jsModuleAs contained as skipwhite skipempty nextgroup=jsModuleKeyword,jsExportDefaultGroup | |||
| syntax keyword jsFrom contained from skipwhite skipempty nextgroup=jsString | |||
| syntax match jsModuleComma contained /,/ skipwhite skipempty nextgroup=jsModuleKeyword,jsModuleAsterisk,jsModuleGroup,jsFlowTypeKeyword | |||
| " Strings, Templates, Numbers | |||
| syntax region jsString start=+\z(["']\)+ skip=+\\\%(\z1\|$\)+ end=+\z1\|$+ contains=jsSpecial,@Spell extend | |||
| syntax region jsTemplateString start=+`+ skip=+\\`+ end=+`+ contains=jsTemplateExpression,jsSpecial,@Spell extend | |||
| syntax match jsTaggedTemplate /\<\K\k*\ze`/ nextgroup=jsTemplateString | |||
| syntax match jsNumber /\c\<\%(\d\+\%(e[+-]\=\d\+\)\=\|0b[01]\+\|0o\o\+\|0x\x\+\)\>/ | |||
| syntax keyword jsNumber Infinity | |||
| syntax match jsFloat /\c\<\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%(e[+-]\=\d\+\)\=\>/ | |||
| " Regular Expressions | |||
| syntax match jsSpecial contained "\v\\%(x\x\x|u%(\x{4}|\{\x{4,5}})|c\u|.)" | |||
| syntax region jsTemplateExpression contained matchgroup=jsTemplateBraces start=+${+ end=+}+ contains=@jsExpression keepend | |||
| syntax region jsRegexpCharClass contained start=+\[+ skip=+\\.+ end=+\]+ contains=jsSpecial | |||
| syntax match jsRegexpBoundary contained "\v\c[$^]|\\b" | |||
| syntax match jsRegexpBackRef contained "\v\\[1-9]\d*" | |||
| syntax match jsRegexpQuantifier contained "\v[^\\]%([?*+]|\{\d+%(,\d*)?})\??"lc=1 | |||
| syntax match jsRegexpOr contained "|" | |||
| syntax match jsRegexpMod contained "\v\(\?[:=!>]"lc=1 | |||
| syntax region jsRegexpGroup contained start="[^\\]("lc=1 skip="\\.\|\[\(\\.\|[^]]\+\)\]" end=")" contains=jsRegexpCharClass,@jsRegexpSpecial keepend | |||
| syntax region jsRegexpString start=+\%(\%(\<return\|\<typeof\|\_[^)\]'"[:blank:][:alnum:]_$]\)\s*\)\@<=/\ze[^*/]+ skip=+\\.\|\[[^]]\{1,}\]+ end=+/[gimyus]\{,6}+ contains=jsRegexpCharClass,jsRegexpGroup,@jsRegexpSpecial oneline keepend extend | |||
| syntax cluster jsRegexpSpecial contains=jsSpecial,jsRegexpBoundary,jsRegexpBackRef,jsRegexpQuantifier,jsRegexpOr,jsRegexpMod | |||
| " Objects | |||
| syntax match jsObjectKey contained /\<\k*\ze\s*:/ contains=jsFunctionKey skipwhite skipempty nextgroup=jsObjectValue | |||
| syntax match jsObjectColon contained /:/ skipwhite skipempty | |||
| syntax region jsObjectKeyString contained start=+\z(["']\)+ skip=+\\\%(\z1\|$\)+ end=+\z1\|$+ contains=jsSpecial,@Spell skipwhite skipempty nextgroup=jsObjectValue | |||
| syntax region jsObjectKeyComputed contained matchgroup=jsBrackets start=/\[/ end=/]/ contains=@jsExpression skipwhite skipempty nextgroup=jsObjectValue,jsFuncArgs extend | |||
| syntax match jsObjectSeparator contained /,/ | |||
| syntax region jsObjectValue contained matchgroup=jsNoise start=/:/ end=/[,}]\@=/ contains=@jsExpression extend | |||
| syntax match jsObjectFuncName contained /\<\K\k*\ze\_s*(/ skipwhite skipempty nextgroup=jsFuncArgs | |||
| syntax match jsFunctionKey contained /\<\K\k*\ze\s*:\s*function\>/ | |||
| syntax match jsObjectMethodType contained /\<[gs]et\ze\s\+\K\k*/ skipwhite skipempty nextgroup=jsObjectFuncName | |||
| syntax region jsObjectStringKey contained start=+\z(["']\)+ skip=+\\\%(\z1\|$\)+ end=+\z1\|$+ contains=jsSpecial,@Spell extend skipwhite skipempty nextgroup=jsFuncArgs,jsObjectValue | |||
| exe 'syntax keyword jsNull null '.(exists('g:javascript_conceal_null') ? 'conceal cchar='.g:javascript_conceal_null : '') | |||
| exe 'syntax keyword jsReturn return contained '.(exists('g:javascript_conceal_return') ? 'conceal cchar='.g:javascript_conceal_return : '').' skipwhite skipempty nextgroup=@jsExpression' | |||
| exe 'syntax keyword jsUndefined undefined '.(exists('g:javascript_conceal_undefined') ? 'conceal cchar='.g:javascript_conceal_undefined : '') | |||
| exe 'syntax keyword jsNan NaN '.(exists('g:javascript_conceal_NaN') ? 'conceal cchar='.g:javascript_conceal_NaN : '') | |||
| exe 'syntax keyword jsPrototype prototype '.(exists('g:javascript_conceal_prototype') ? 'conceal cchar='.g:javascript_conceal_prototype : '') | |||
| exe 'syntax keyword jsThis this '.(exists('g:javascript_conceal_this') ? 'conceal cchar='.g:javascript_conceal_this : '') | |||
| exe 'syntax keyword jsSuper super contained '.(exists('g:javascript_conceal_super') ? 'conceal cchar='.g:javascript_conceal_super : '') | |||
| " Statement Keywords | |||
| syntax match jsBlockLabel /\<\K\k*\s*::\@!/ contains=jsNoise skipwhite skipempty nextgroup=jsBlock | |||
| syntax match jsBlockLabelKey contained /\<\K\k*\ze\s*\_[;]/ | |||
| syntax keyword jsStatement contained with yield debugger | |||
| syntax keyword jsStatement contained break continue skipwhite skipempty nextgroup=jsBlockLabelKey | |||
| syntax keyword jsConditional if skipwhite skipempty nextgroup=jsParenIfElse | |||
| syntax keyword jsConditional else skipwhite skipempty nextgroup=jsCommentIfElse,jsIfElseBlock | |||
| syntax keyword jsConditional switch skipwhite skipempty nextgroup=jsParenSwitch | |||
| syntax keyword jsRepeat while for skipwhite skipempty nextgroup=jsParenRepeat,jsForAwait | |||
| syntax keyword jsDo do skipwhite skipempty nextgroup=jsRepeatBlock | |||
| syntax region jsSwitchCase contained matchgroup=jsLabel start=/\<\%(case\|default\)\>/ end=/:\@=/ contains=@jsExpression,jsLabel skipwhite skipempty nextgroup=jsSwitchColon keepend | |||
| syntax keyword jsTry try skipwhite skipempty nextgroup=jsTryCatchBlock | |||
| syntax keyword jsFinally contained finally skipwhite skipempty nextgroup=jsFinallyBlock | |||
| syntax keyword jsCatch contained catch skipwhite skipempty nextgroup=jsParenCatch | |||
| syntax keyword jsException throw | |||
| syntax keyword jsAsyncKeyword async await | |||
| syntax match jsSwitchColon contained /::\@!/ skipwhite skipempty nextgroup=jsSwitchBlock | |||
| " Keywords | |||
| syntax keyword jsGlobalObjects Array Boolean Date Function Iterator Number Object Symbol Map WeakMap Set WeakSet RegExp String Proxy Promise Buffer ParallelArray ArrayBuffer DataView Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray JSON Math console document window Intl Collator DateTimeFormat NumberFormat fetch | |||
| syntax keyword jsGlobalNodeObjects module exports global process __dirname __filename | |||
| syntax match jsGlobalNodeObjects /\<require\>/ containedin=jsFuncCall | |||
| syntax keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError | |||
| syntax keyword jsBuiltins decodeURI decodeURIComponent encodeURI encodeURIComponent eval isFinite isNaN parseFloat parseInt uneval | |||
| " DISCUSS: How imporant is this, really? Perhaps it should be linked to an error because I assume the keywords are reserved? | |||
| syntax keyword jsFutureKeys abstract enum int short boolean interface byte long char final native synchronized float package throws goto private transient implements protected volatile double public | |||
| " DISCUSS: Should we really be matching stuff like this? | |||
| " DOM2 Objects | |||
| syntax keyword jsGlobalObjects DOMImplementation DocumentFragment Document Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction | |||
| syntax keyword jsExceptions DOMException | |||
| " DISCUSS: Should we really be matching stuff like this? | |||
| " DOM2 CONSTANT | |||
| syntax keyword jsDomErrNo INDEX_SIZE_ERR DOMSTRING_SIZE_ERR HIERARCHY_REQUEST_ERR WRONG_DOCUMENT_ERR INVALID_CHARACTER_ERR NO_DATA_ALLOWED_ERR NO_MODIFICATION_ALLOWED_ERR NOT_FOUND_ERR NOT_SUPPORTED_ERR INUSE_ATTRIBUTE_ERR INVALID_STATE_ERR SYNTAX_ERR INVALID_MODIFICATION_ERR NAMESPACE_ERR INVALID_ACCESS_ERR | |||
| syntax keyword jsDomNodeConsts ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE | |||
| " DISCUSS: Should we really be special matching on these props? | |||
| " HTML events and internal variables | |||
| syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize | |||
| " Code blocks | |||
| syntax region jsBracket matchgroup=jsBrackets start=/\[/ end=/\]/ contains=@jsExpression,jsSpreadExpression extend fold | |||
| syntax region jsParen matchgroup=jsParens start=/(/ end=/)/ contains=@jsExpression extend fold nextgroup=jsFlowDefinition | |||
| syntax region jsParenDecorator contained matchgroup=jsParensDecorator start=/(/ end=/)/ contains=@jsAll extend fold | |||
| syntax region jsParenIfElse contained matchgroup=jsParensIfElse start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentIfElse,jsIfElseBlock extend fold | |||
| syntax region jsParenRepeat contained matchgroup=jsParensRepeat start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentRepeat,jsRepeatBlock extend fold | |||
| syntax region jsParenSwitch contained matchgroup=jsParensSwitch start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold | |||
| syntax region jsParenCatch contained matchgroup=jsParensCatch start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold | |||
| syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsDestructuringArray,jsRestExpression,jsFlowArgumentDef skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold | |||
| syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsAsyncKeyword,jsNoise extend fold | |||
| syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold | |||
| syntax region jsIfElseBlock contained matchgroup=jsIfElseBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold | |||
| syntax region jsTryCatchBlock contained matchgroup=jsTryCatchBraces start=/{/ end=/}/ contains=@jsAll,jsBlock skipwhite skipempty nextgroup=jsCatch,jsFinally extend fold | |||
| syntax region jsFinallyBlock contained matchgroup=jsFinallyBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold | |||
| syntax region jsSwitchBlock contained matchgroup=jsSwitchBraces start=/{/ end=/}/ contains=@jsAll,jsBlock,jsSwitchCase extend fold | |||
| syntax region jsRepeatBlock contained matchgroup=jsRepeatBraces start=/{/ end=/}/ contains=@jsAll,jsBlock extend fold | |||
| syntax region jsDestructuringBlock contained matchgroup=jsDestructuringBraces start=/{/ end=/}/ contains=jsDestructuringProperty,jsDestructuringAssignment,jsDestructuringNoise,jsDestructuringPropertyComputed,jsSpreadExpression,jsComment extend fold | |||
| syntax region jsDestructuringArray contained matchgroup=jsDestructuringBraces start=/\[/ end=/\]/ contains=jsDestructuringPropertyValue,jsNoise,jsDestructuringProperty,jsSpreadExpression,jsComment extend fold | |||
| syntax region jsObject contained matchgroup=jsObjectBraces start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsDecorator,jsAsyncKeyword extend fold | |||
| syntax region jsBlock matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll,jsSpreadExpression extend fold | |||
| syntax region jsModuleGroup contained matchgroup=jsModuleBraces start=/{/ end=/}/ contains=jsModuleKeyword,jsModuleComma,jsModuleAs,jsComment,jsFlowTypeKeyword skipwhite skipempty nextgroup=jsFrom fold | |||
| syntax region jsSpreadExpression contained matchgroup=jsSpreadOperator start=/\.\.\./ end=/[,}\]]\@=/ contains=@jsExpression | |||
| syntax region jsRestExpression contained matchgroup=jsRestOperator start=/\.\.\./ end=/[,)]\@=/ | |||
| syntax region jsTernaryIf matchgroup=jsTernaryIfOperator start=/?/ end=/\%(:\|}\@=\)/ contains=@jsExpression extend skipwhite skipempty nextgroup=@jsExpression | |||
| syntax match jsOperator /?\.\ze\_D/ | |||
| syntax match jsGenerator contained /\*/ skipwhite skipempty nextgroup=jsFuncName,jsFuncArgs,jsFlowFunctionGroup | |||
| syntax match jsFuncName contained /\<\K\k*/ skipwhite skipempty nextgroup=jsFuncArgs,jsFlowFunctionGroup | |||
| syntax region jsFuncArgExpression contained matchgroup=jsFuncArgOperator start=/=/ end=/[,)]\@=/ contains=@jsExpression extend | |||
| syntax match jsFuncArgCommas contained ',' | |||
| syntax keyword jsArguments contained arguments | |||
| syntax keyword jsForAwait contained await skipwhite skipempty nextgroup=jsParenRepeat | |||
| " Matches a single keyword argument with no parens | |||
| syntax match jsArrowFuncArgs /\<\K\k*\ze\s*=>/ skipwhite contains=jsFuncArgs skipwhite skipempty nextgroup=jsArrowFunction extend | |||
| " Matches a series of arguments surrounded in parens | |||
| syntax match jsArrowFuncArgs /([^()]*)\ze\s*=>/ contains=jsFuncArgs skipempty skipwhite nextgroup=jsArrowFunction extend | |||
| exe 'syntax match jsFunction /\<function\>/ skipwhite skipempty nextgroup=jsGenerator,jsFuncName,jsFuncArgs,jsFlowFunctionGroup skipwhite '.(exists('g:javascript_conceal_function') ? 'conceal cchar='.g:javascript_conceal_function : '') | |||
| exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=jsFuncBlock,jsCommentFunction '.(exists('g:javascript_conceal_arrow_function') ? 'conceal cchar='.g:javascript_conceal_arrow_function : '') | |||
| exe 'syntax match jsArrowFunction /()\ze\s*=>/ skipwhite skipempty nextgroup=jsArrowFunction '.(exists('g:javascript_conceal_noarg_arrow_function') ? 'conceal cchar='.g:javascript_conceal_noarg_arrow_function : '') | |||
| exe 'syntax match jsArrowFunction /_\ze\s*=>/ skipwhite skipempty nextgroup=jsArrowFunction '.(exists('g:javascript_conceal_underscore_arrow_function') ? 'conceal cchar='.g:javascript_conceal_underscore_arrow_function : '') | |||
| " Classes | |||
| syntax keyword jsClassKeyword contained class | |||
| syntax keyword jsExtendsKeyword contained extends skipwhite skipempty nextgroup=@jsExpression | |||
| syntax match jsClassNoise contained /\./ | |||
| syntax match jsClassMethodType contained /\<\%([gs]et\|static\)\ze\s\+\K\k*/ skipwhite skipempty nextgroup=jsAsyncKeyword,jsFuncName,jsClassProperty | |||
| syntax region jsClassDefinition start=/\<class\>/ end=/\(\<extends\>\s\+\)\@<!{\@=/ contains=jsClassKeyword,jsExtendsKeyword,jsClassNoise,@jsExpression,jsFlowClassGroup skipwhite skipempty nextgroup=jsCommentClass,jsClassBlock,jsFlowClassGroup | |||
| syntax match jsClassProperty contained /\<\K\k*\ze\s*=/ skipwhite skipempty nextgroup=jsClassValue,jsFlowClassDef | |||
| syntax region jsClassValue contained start=/=/ end=/\_[;}]\@=/ contains=@jsExpression | |||
| syntax region jsClassPropertyComputed contained matchgroup=jsBrackets start=/\[/ end=/]/ contains=@jsExpression skipwhite skipempty nextgroup=jsFuncArgs,jsClassValue extend | |||
| syntax match jsClassFuncName contained /\<\K\k*\ze\s*(/ skipwhite skipempty nextgroup=jsFuncArgs | |||
| syntax region jsClassStringKey contained start=+\z(["']\)+ skip=+\\\%(\z1\|$\)+ end=+\z1\|$+ contains=jsSpecial,@Spell extend skipwhite skipempty nextgroup=jsFuncArgs | |||
| " Destructuring | |||
| syntax match jsDestructuringPropertyValue contained /\k\+/ | |||
| syntax match jsDestructuringProperty contained /\k\+\ze\s*=/ skipwhite skipempty nextgroup=jsDestructuringValue | |||
| syntax match jsDestructuringAssignment contained /\k\+\ze\s*:/ skipwhite skipempty nextgroup=jsDestructuringValueAssignment | |||
| syntax region jsDestructuringValue contained start=/=/ end=/[,}\]]\@=/ contains=@jsExpression extend | |||
| syntax region jsDestructuringValueAssignment contained start=/:/ end=/[,}=]\@=/ contains=jsDestructuringPropertyValue,jsDestructuringBlock,jsNoise,jsDestructuringNoise skipwhite skipempty nextgroup=jsDestructuringValue extend | |||
| syntax match jsDestructuringNoise contained /[,[\]]/ | |||
| syntax region jsDestructuringPropertyComputed contained matchgroup=jsBrackets start=/\[/ end=/]/ contains=@jsExpression skipwhite skipempty nextgroup=jsDestructuringValue,jsDestructuringNoise extend fold | |||
| " Comments | |||
| syntax keyword jsCommentTodo contained TODO FIXME XXX TBD | |||
| syntax region jsComment start=+//+ end=/$/ contains=jsCommentTodo,@Spell extend keepend | |||
| syntax region jsComment start=+/\*+ end=+\*/+ contains=jsCommentTodo,@Spell fold extend keepend | |||
| syntax region jsEnvComment start=/\%^#!/ end=/$/ display | |||
| " Specialized Comments - These are special comment regexes that are used in | |||
| " odd places that maintain the proper nextgroup functionality. It sucks we | |||
| " can't make jsComment a skippable type of group for nextgroup | |||
| syntax region jsCommentFunction contained start=+//+ end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn extend keepend | |||
| syntax region jsCommentFunction contained start=+/\*+ end=+\*/+ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn fold extend keepend | |||
| syntax region jsCommentClass contained start=+//+ end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClassGroup extend keepend | |||
| syntax region jsCommentClass contained start=+/\*+ end=+\*/+ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClassGroup fold extend keepend | |||
| syntax region jsCommentIfElse contained start=+//+ end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsIfElseBlock extend keepend | |||
| syntax region jsCommentIfElse contained start=+/\*+ end=+\*/+ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsIfElseBlock fold extend keepend | |||
| syntax region jsCommentRepeat contained start=+//+ end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsRepeatBlock extend keepend | |||
| syntax region jsCommentRepeat contained start=+/\*+ end=+\*/+ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsRepeatBlock fold extend keepend | |||
| " Decorators | |||
| syntax match jsDecorator /^\s*@/ nextgroup=jsDecoratorFunction | |||
| syntax match jsDecoratorFunction contained /\h[a-zA-Z0-9_.]*/ nextgroup=jsParenDecorator | |||
| if exists("javascript_plugin_jsdoc") | |||
| runtime extras/jsdoc.vim | |||
| " NGDoc requires JSDoc | |||
| if exists("javascript_plugin_ngdoc") | |||
| runtime extras/ngdoc.vim | |||
| endif | |||
| endif | |||
| if exists("javascript_plugin_flow") | |||
| runtime extras/flow.vim | |||
| endif | |||
| syntax cluster jsExpression contains=jsBracket,jsParen,jsObject,jsTernaryIf,jsTaggedTemplate,jsTemplateString,jsString,jsRegexpString,jsNumber,jsFloat,jsOperator,jsBooleanTrue,jsBooleanFalse,jsNull,jsFunction,jsArrowFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsFuncCall,jsUndefined,jsNan,jsPrototype,jsBuiltins,jsNoise,jsClassDefinition,jsArrowFunction,jsArrowFuncArgs,jsParensError,jsComment,jsArguments,jsThis,jsSuper,jsDo,jsForAwait,jsAsyncKeyword,jsStatement | |||
| syntax cluster jsAll contains=@jsExpression,jsStorageClass,jsConditional,jsRepeat,jsReturn,jsException,jsTry,jsNoise,jsBlockLabel | |||
| " Define the default highlighting. | |||
| " For version 5.7 and earlier: only when not done already | |||
| " For version 5.8 and later: only when an item doesn't have highlighting yet | |||
| if version >= 508 || !exists("did_javascript_syn_inits") | |||
| if version < 508 | |||
| let did_javascript_syn_inits = 1 | |||
| command -nargs=+ HiLink hi link <args> | |||
| else | |||
| command -nargs=+ HiLink hi def link <args> | |||
| endif | |||
| HiLink jsComment Comment | |||
| HiLink jsEnvComment PreProc | |||
| HiLink jsParensIfElse jsParens | |||
| HiLink jsParensRepeat jsParens | |||
| HiLink jsParensSwitch jsParens | |||
| HiLink jsParensCatch jsParens | |||
| HiLink jsCommentTodo Todo | |||
| HiLink jsString String | |||
| HiLink jsObjectKeyString String | |||
| HiLink jsTemplateString String | |||
| HiLink jsObjectStringKey String | |||
| HiLink jsClassStringKey String | |||
| HiLink jsTaggedTemplate StorageClass | |||
| HiLink jsTernaryIfOperator Operator | |||
| HiLink jsRegexpString String | |||
| HiLink jsRegexpBoundary SpecialChar | |||
| HiLink jsRegexpQuantifier SpecialChar | |||
| HiLink jsRegexpOr Conditional | |||
| HiLink jsRegexpMod SpecialChar | |||
| HiLink jsRegexpBackRef SpecialChar | |||
| HiLink jsRegexpGroup jsRegexpString | |||
| HiLink jsRegexpCharClass Character | |||
| HiLink jsCharacter Character | |||
| HiLink jsPrototype Special | |||
| HiLink jsConditional Conditional | |||
| HiLink jsBranch Conditional | |||
| HiLink jsLabel Label | |||
| HiLink jsReturn Statement | |||
| HiLink jsRepeat Repeat | |||
| HiLink jsDo Repeat | |||
| HiLink jsStatement Statement | |||
| HiLink jsException Exception | |||
| HiLink jsTry Exception | |||
| HiLink jsFinally Exception | |||
| HiLink jsCatch Exception | |||
| HiLink jsAsyncKeyword Keyword | |||
| HiLink jsForAwait Keyword | |||
| HiLink jsArrowFunction Type | |||
| HiLink jsFunction Type | |||
| HiLink jsGenerator jsFunction | |||
| HiLink jsArrowFuncArgs jsFuncArgs | |||
| HiLink jsFuncName Function | |||
| HiLink jsClassFuncName jsFuncName | |||
| HiLink jsObjectFuncName Function | |||
| HiLink jsArguments Special | |||
| HiLink jsError Error | |||
| HiLink jsParensError Error | |||
| HiLink jsOperator Operator | |||
| HiLink jsOf Operator | |||
| HiLink jsStorageClass StorageClass | |||
| HiLink jsClassKeyword Keyword | |||
| HiLink jsExtendsKeyword Keyword | |||
| HiLink jsThis Special | |||
| HiLink jsSuper Constant | |||
| HiLink jsNan Number | |||
| HiLink jsNull Type | |||
| HiLink jsUndefined Type | |||
| HiLink jsNumber Number | |||
| HiLink jsFloat Float | |||
| HiLink jsBooleanTrue Boolean | |||
| HiLink jsBooleanFalse Boolean | |||
| HiLink jsObjectColon jsNoise | |||
| HiLink jsNoise Noise | |||
| HiLink jsBrackets Noise | |||
| HiLink jsParens Noise | |||
| HiLink jsBraces Noise | |||
| HiLink jsFuncBraces Noise | |||
| HiLink jsFuncParens Noise | |||
| HiLink jsClassBraces Noise | |||
| HiLink jsClassNoise Noise | |||
| HiLink jsIfElseBraces Noise | |||
| HiLink jsTryCatchBraces Noise | |||
| HiLink jsModuleBraces Noise | |||
| HiLink jsObjectBraces Noise | |||
| HiLink jsObjectSeparator Noise | |||
| HiLink jsFinallyBraces Noise | |||
| HiLink jsRepeatBraces Noise | |||
| HiLink jsSwitchBraces Noise | |||
| HiLink jsSpecial Special | |||
| HiLink jsTemplateBraces Noise | |||
| HiLink jsGlobalObjects Constant | |||
| HiLink jsGlobalNodeObjects Constant | |||
| HiLink jsExceptions Constant | |||
| HiLink jsBuiltins Constant | |||
| HiLink jsImport Include | |||
| HiLink jsExport Include | |||
| HiLink jsExportDefault StorageClass | |||
| HiLink jsExportDefaultGroup jsExportDefault | |||
| HiLink jsModuleAs Include | |||
| HiLink jsModuleComma jsNoise | |||
| HiLink jsModuleAsterisk Noise | |||
| HiLink jsFrom Include | |||
| HiLink jsDecorator Special | |||
| HiLink jsDecoratorFunction Function | |||
| HiLink jsParensDecorator jsParens | |||
| HiLink jsFuncArgOperator jsFuncArgs | |||
| HiLink jsClassProperty jsObjectKey | |||
| HiLink jsSpreadOperator Operator | |||
| HiLink jsRestOperator Operator | |||
| HiLink jsRestExpression jsFuncArgs | |||
| HiLink jsSwitchColon Noise | |||
| HiLink jsClassMethodType Type | |||
| HiLink jsObjectMethodType Type | |||
| HiLink jsClassDefinition jsFuncName | |||
| HiLink jsBlockLabel Identifier | |||
| HiLink jsBlockLabelKey jsBlockLabel | |||
| HiLink jsDestructuringBraces Noise | |||
| HiLink jsDestructuringProperty jsFuncArgs | |||
| HiLink jsDestructuringAssignment jsObjectKey | |||
| HiLink jsDestructuringNoise Noise | |||
| HiLink jsCommentFunction jsComment | |||
| HiLink jsCommentClass jsComment | |||
| HiLink jsCommentIfElse jsComment | |||
| HiLink jsCommentRepeat jsComment | |||
| HiLink jsDomErrNo Constant | |||
| HiLink jsDomNodeConsts Constant | |||
| HiLink jsDomElemAttrs Label | |||
| HiLink jsDomElemFuncs PreProc | |||
| HiLink jsHtmlEvents Special | |||
| HiLink jsHtmlElemAttrs Label | |||
| HiLink jsHtmlElemFuncs PreProc | |||
| HiLink jsCssStyles Label | |||
| delcommand HiLink | |||
| endif | |||
| " Define the htmlJavaScript for HTML syntax html.vim | |||
| syntax cluster htmlJavaScript contains=@jsAll,jsImport,jsExport | |||
| syntax cluster javaScriptExpression contains=@jsAll | |||
| " Vim's default html.vim highlights all javascript as 'Special' | |||
| hi! def link javaScript NONE | |||
| let b:current_syntax = "javascript" | |||
| if main_syntax == 'javascript' | |||
| unlet main_syntax | |||
| endif | |||
| @ -1 +0,0 @@ | |||
| Andri Möll <andri@dot.ee> | |||
| @ -1,8 +0,0 @@ | |||
| /Makefile | |||
| /test/* | |||
| /Gemfile | |||
| /Gemfile.lock | |||
| /Guardfile | |||
| /*.zip | |||
| /node.tar.gz | |||
| tags | |||
| @ -1,7 +0,0 @@ | |||
| language: ruby | |||
| rvm: | |||
| - 1.9.3 | |||
| before_install: sudo apt-get install vim-gtk | |||
| install: bundle install --deployment --without development | |||
| script: xvfb-run make test | |||
| @ -1,57 +0,0 @@ | |||
| ## Unreleased | |||
| - Fixes `gf` on scoped modules (`require("@scope/example")`). | |||
| - Initializes Node.vim `gf` and other mappings when the `'filetype'` is set, | |||
| rather than when reading a file. | |||
| This allows you to manually set the filetype to JavaScript after opening | |||
| a file, for example, and still get Node.vim's mappings. | |||
| - Initializes Node.vim mappings for JSX (those with the `jsx` filetype) files. | |||
| - Adds `.es` to detected suffixes, so you can `gf` over `./foo` to open | |||
| `./foo.es`. | |||
| - Updates URLs to use <https://github.com/nodejs/node> instead of the previous | |||
| Joyent repo. | |||
| Thanks, [Jacky Alciné](https://jacky.wtf), for the help! | |||
| ## 0.8.1 (Apr 15, 2014) | |||
| - Updates the URL from which Node.vim downloads Node core module source files. | |||
| Uses <http://rawgit.com> which used to be named <http://rawgithub.com>. | |||
| Because of Vim Netrw's inability to handle HTTPS, it does so over HTTP. Sorry. | |||
| ## 0.8.0 (Sep 6, 2013) | |||
| - Adds `node` as a core module so you could use `:Nedit node` to open the file Node uses to bootstrap its core. | |||
| ## 0.7.0 (Aug 28, 2013) | |||
| - Adds support for opening core Node.js modules, such as `http`, `util`, etc. with `gf` or `:Nedit`. | |||
| They're shown straight from Node's online repository without you having to download everything. | |||
| ## 0.6.0 (Aug 23, 2013) | |||
| - Adds `:Nedit` command for editing modules or files relative to the Node project root. | |||
| For example: `:Nedit any-module/lib` or `:Nedit ./package`. | |||
| - Adds `:Nopen` command which behaves like `:Nedit`, but also `lcd`s to the module's directory. | |||
| - Makes `<Plug>NodeGotoFile` available for your mapping in any Node project file, but maps it to `gf` automatically only on JavaScript files. | |||
| - Maps `gf` also for JSON files for easy jumping to modules. | |||
| - Makes `:Nedit` and `:Nopen` available immediately when starting Vim in a directory of a Node project. | |||
| ## 0.5.1 (Aug 8, 2013) | |||
| - Adds `Node` autocommand. | |||
| Use it with `autocmd User Node` to customize settings for files in Node projects. | |||
| - Adds `<Plug>NodeVSplitGotoFile` for those who want `<C-w>f` to split vertically. | |||
| ## 0.5.0 (Aug 5, 2013) | |||
| - Adds `&include` pattern so Vim can recognize included/required files, e.g. for looking up keywords with `[I`. | |||
| - Cleans `&path` from `/usr/include` for JavaScript files. | |||
| - Adds a new superb `gf` handler to handle all relative and module paths, incl. support for `require(".")` to open `./index.js`. This is spot on how Node.js finds your requires. | |||
| - Adds `<Plug>NodeGotoFile` should you want to remap Node.vim's file opener. | |||
| - Opens files before directories should both, e.g. `./foo.js` and `./foo`, exist. This matches Node.js's behavior. | |||
| - Adds a full automated integration test suite to Node.vim which is freaking amazing! | |||
| ## 0.2.0 (Jul 28, 2013) | |||
| - Adds full support for navigating to module files by using `gf` on `require("any-module")`. | |||
| - Adds `.json` to `&suffixesadd` so you could use `gf` on `require("./package")` to open package.json. | |||
| ## 0.1.1 (Jul 28, 2013) | |||
| - Removes an innocent but forgotten debugging line. | |||
| ## 0.1.0 (Jul 28, 2013) | |||
| - First release to get the nodeballs rolling. | |||
| - Sets the filetype to JavaScript for files with Node's shebang (`#!`). | |||
| - Adds `.js` to `&suffixesadd` so you could use `gf` on `require("./foo")` to open `foo.js`. | |||
| @ -1,11 +0,0 @@ | |||
| source "https://rubygems.org" | |||
| group :development do | |||
| gem "guard-minitest" | |||
| gem "minitest-reporters" | |||
| end | |||
| group :test do | |||
| gem "minitest", "< 5" | |||
| gem "vimrunner", :git => "https://github.com/moll/vimrunner.git" | |||
| end | |||
| @ -1,59 +0,0 @@ | |||
| GIT | |||
| remote: https://github.com/moll/vimrunner.git | |||
| revision: 4b1ee072e52dea871a0c3370f215f54fe596a9dc | |||
| specs: | |||
| vimrunner (0.3.0) | |||
| GEM | |||
| remote: https://rubygems.org/ | |||
| specs: | |||
| ansi (1.4.3) | |||
| builder (3.2.2) | |||
| coderay (1.0.9) | |||
| ffi (1.9.0) | |||
| formatador (0.2.4) | |||
| guard (1.8.2) | |||
| formatador (>= 0.2.4) | |||
| listen (>= 1.0.0) | |||
| lumberjack (>= 1.0.2) | |||
| pry (>= 0.9.10) | |||
| thor (>= 0.14.6) | |||
| guard-minitest (1.0.1) | |||
| guard (>= 1.8) | |||
| minitest (>= 2.1) | |||
| hashie (2.0.5) | |||
| listen (1.2.2) | |||
| rb-fsevent (>= 0.9.3) | |||
| rb-inotify (>= 0.9) | |||
| rb-kqueue (>= 0.2) | |||
| lumberjack (1.0.4) | |||
| method_source (0.8.2) | |||
| minitest (4.7.5) | |||
| minitest-reporters (0.14.20) | |||
| ansi | |||
| builder | |||
| minitest (>= 2.12, < 5.0) | |||
| powerbar | |||
| powerbar (1.0.11) | |||
| ansi (~> 1.4.0) | |||
| hashie (>= 1.1.0) | |||
| pry (0.9.12.2) | |||
| coderay (~> 1.0.5) | |||
| method_source (~> 0.8) | |||
| slop (~> 3.4) | |||
| rb-fsevent (0.9.3) | |||
| rb-inotify (0.9.0) | |||
| ffi (>= 0.5.0) | |||
| rb-kqueue (0.2.0) | |||
| ffi (>= 0.5.0) | |||
| slop (3.4.6) | |||
| thor (0.18.1) | |||
| PLATFORMS | |||
| ruby | |||
| DEPENDENCIES | |||
| guard-minitest | |||
| minitest (< 5) | |||
| minitest-reporters | |||
| vimrunner! | |||
| @ -1,8 +0,0 @@ | |||
| guard :minitest, :all_on_start => false, :cli => ENV["TEST_OPTS"] do | |||
| watch(%r(^(.*)\.vim$)) {|m| "test/#{m[1]}_test.rb" } | |||
| watch(%r(^([^/]+)/[^/]+\.vim$)) {|m| "test/#{m[1]}_test.rb" } | |||
| watch(%r(^([^/]+)/[^/]+/(.*)\.vim$)) {|m| "test/#{m[1]}/#{m[2]}_test.rb" } | |||
| watch(%r(^test/(.*)\/?_test\.rb)) | |||
| watch(%r(^test/helper\.rb)) { "test" } | |||
| end | |||
| @ -1,20 +0,0 @@ | |||
| Node.vim | |||
| Copyright (C) 2013 Andri Möll | |||
| This program is free software: you can redistribute it and/or modify it under | |||
| the terms of the GNU Affero General Public License as published by the Free | |||
| Software Foundation, either version 3 of the License, or any later version. | |||
| Additional permission under the GNU Affero GPL version 3 section 7: | |||
| If you modify this Program, or any covered work, by linking or | |||
| combining it with other code, such other code is not for that reason | |||
| alone subject to any of the requirements of the GNU Affero GPL version 3. | |||
| In summary: | |||
| - You can use this program for no cost. | |||
| - You can use this program for both personal and commercial reasons. | |||
| - You do not have to share your own program's code which uses this program. | |||
| - You have to share modifications (e.g bug-fixes) you've made to this program. | |||
| For the full copy of the GNU Affero General Public License see: | |||
| http://www.gnu.org/licenses. | |||
| @ -1,40 +0,0 @@ | |||
| NAME = node | |||
| TITLE = Node.vim | |||
| VERSION = 0.8.1 | |||
| ID = 4674 | |||
| TEST_OPTS = | |||
| love: | |||
| @echo "Feel like makin' love." | |||
| test: spec | |||
| autotest: autospec | |||
| spec: $(shell find . -name "*_test.rb") | |||
| @ruby -rbundler/setup $(addprefix -r./,$^) -e "" -- $(TEST_OPTS) | |||
| autospec: | |||
| @bundle exec guard start --no-interactions | |||
| pack: | |||
| rm -rf "$(NAME)-$(VERSION).zip" | |||
| zip -r "$(NAME)-$(VERSION).zip" * -x @.packignore | |||
| publish: | |||
| open "http://www.vim.org/scripts/add_script_version.php?script_id=$(ID)" | |||
| tag: | |||
| git tag "v$(VERSION)" | |||
| node.tar.gz: | |||
| wget -c "https://github.com/nodejs/node/archive/master.tar.gz" -O node.tar.gz | |||
| list-core-modules: node.tar.gz | |||
| tar tf node.tar.gz |\ | |||
| egrep "^node[^/]*/lib/.+" |\ | |||
| xargs -n1 basename -s .js |\ | |||
| { cat; echo node; } | sort | |||
| .PHONY: love | |||
| .PHONY: spec autospec | |||
| .PHONY: pack publish tag | |||
| @ -1,105 +0,0 @@ | |||
| Node.vim | |||
| ======== | |||
| [](https://travis-ci.org/moll/vim-node) | |||
| Tools to make Vim superb for developing with Node.js. | |||
| It's the Node equivalent of [Rails.vim (vimscript #1567)](https://github.com/tpope/vim-rails) and [Rake.vim (vimscript #3669)](https://github.com/tpope/vim-rake). | |||
| This is just the first release to get the nodes rolling. If you've collected great helpers and shortcuts that help you work with Node, please share them via [email](mailto:andri@dot.ee), [Twitter](https://twitter.com/theml) or [GitHub issues](https://github.com/moll/vim-node/issues) so we could incorporate them here, too! Thanks! | |||
| ### Tour | |||
| - Use `gf` on paths or requires to open the same file Node.js would. | |||
| - Use `gf` on `require(".")` to open `./index.js` | |||
| - Use `gf` on `require("./dir")` to open `./dir/index.js` | |||
| - Use `gf` on `require("./foo")` to open `foo.js`. | |||
| - Use `gf` on `require("./package")` and have it open package.json. | |||
| - Use `gf` on `require("module")` to open the module's main file (parsed for you from `package.json`). | |||
| - Use `gf` on `require("module/lib/utils")` and open files inside the module. | |||
| - Automatically sets the filetype to JavaScript for files with Node's shebang (`#!`). | |||
| - Use `[I` etc. to look for a keyword in required files (Sets Vim's `&include`). | |||
| - Use `:Nedit` to quickly edit any module, file in a module or your project file. | |||
| - Use `:Nopen` to quickly edit any module and `lcd` to its directory. | |||
| - Lets you even open Node's core modules. They're shown straight from Node's online repository without you having to download everything. | |||
| - Node.vim itself is tested with a thorough automated integration test suite! No cowboy coding here! | |||
| Expect more to come soon and feel free to let me know what you're after! | |||
| PS. Node.vim is absolutely intended to work on Windows, but not yet tested there at all. If you could help, try it out and report issues, I'd be grateful! | |||
| Installing | |||
| ---------- | |||
| The easiest and most modular way is to download this to `~/.vim/bundle`: | |||
| ``` | |||
| mkdir -p ~/.vim/bundle/node | |||
| ``` | |||
| Using Git: | |||
| ``` | |||
| git clone https://github.com/moll/vim-node.git ~/.vim/bundle/node | |||
| ``` | |||
| Using Wget: | |||
| ``` | |||
| wget https://github.com/moll/vim-node/archive/master.tar.gz -O- | tar -xf- --strip-components 1 -C ~/.vim/bundle/node | |||
| ``` | |||
| Then prepend that directory to Vim's `&runtimepath` (or use [Pathogen](https://github.com/tpope/vim-pathogen)): | |||
| ``` | |||
| :set runtimepath^=~/.vim/bundle/node | |||
| ``` | |||
| ### Vundle | |||
| Or use [Vundle](https://github.com/gmarik/Vundle.vim): | |||
| ``` | |||
| :BundleInstall moll/vim-node | |||
| ``` | |||
| Using | |||
| ----- | |||
| Open any JavaScript file inside a Node project and you're all set. | |||
| - Use `gf` inside `require("...")` to jump to source and module files. | |||
| - Use `[I` on any keyword to look for it in the current and required files. | |||
| - Use `:Nedit module_name` to edit the main file of a module. | |||
| - Use `:Nedit module_name/lib/foo` to edit its `lib/foo.js` file. | |||
| - Use `:Nedit .` to edit your Node projects main (usually `index.js`) file. | |||
| #### Want to customize settings for files inside a Node projects? | |||
| Use the `Node` autocommand. For example: | |||
| ```vim | |||
| autocmd User Node if &filetype == "javascript" | setlocal expandtab | endif | |||
| ``` | |||
| #### Want `<C-w>f` to open the file under the cursor in a new vertical split? | |||
| `<C-w>f` by default opens it in a horizontal split. To have it open vertically, drop this in your `vimrc`: | |||
| ```vim | |||
| autocmd User Node | |||
| \ if &filetype == "javascript" | | |||
| \ nmap <buffer> <C-w>f <Plug>NodeVSplitGotoFile | | |||
| \ nmap <buffer> <C-w><C-f> <Plug>NodeVSplitGotoFile | | |||
| \ endif | |||
| ``` | |||
| License | |||
| ------- | |||
| Node.vim is released under a *Lesser GNU Affero General Public License*, which in summary means: | |||
| - You **can** use this program for **no cost**. | |||
| - You **can** use this program for **both personal and commercial reasons**. | |||
| - You **do not have to share your own program's code** which uses this program. | |||
| - You **have to share modifications** (e.g bug-fixes) you've made to this program. | |||
| For more convoluted language, see the `LICENSE` file. | |||
| About | |||
| ----- | |||
| **[Andri Möll](http://themoll.com)** authored this in SublemacslipseMate++. | |||
| [Monday Calendar](https://mondayapp.com) supported the engineering work. | |||
| If you find Node.vim needs improving or you've got a question, please don't hesitate to email me anytime at [andri@dot.ee](mailto:andri@dot.ee), tweet at [@theml](https://twitter.com/theml) or [create an issue online](https://github.com/moll/vim-node/issues). | |||
| @ -1,110 +0,0 @@ | |||
| " Vim by default sets the filetype to JavaScript for the following suffices. | |||
| " And, yes, it has .jsx there. | |||
| let node#suffixesadd = [".js", ".json", ".es", ".jsx"] | |||
| function! node#initialize(root) | |||
| let b:node_root = a:root | |||
| command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nedit | |||
| \ exe s:nedit(<q-args>, bufname("%"), "edit<bang>") | |||
| command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nopen | |||
| \ exe s:nopen(<q-args>, bufname("%"), "edit<bang>") | |||
| nnoremap <buffer><silent> <Plug>NodeGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"))<CR> | |||
| nnoremap <buffer><silent> <Plug>NodeSplitGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"), "split")<CR> | |||
| nnoremap <buffer><silent> <Plug>NodeVSplitGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"), "vsplit")<CR> | |||
| nnoremap <buffer><silent> <Plug>NodeTabGotoFile | |||
| \ :call <SID>edit(expand("<cfile>"), bufname("%"), "tab split")<CR> | |||
| silent doautocmd User Node | |||
| endfunction | |||
| function! node#javascript() | |||
| " This might be called multiple times if multiple filetypes match. | |||
| if exists("b:node_javascript") && b:node_javascript | return | endif | |||
| let b:node_javascript = 1 | |||
| setlocal path-=/usr/include | |||
| let &l:suffixesadd .= "," . join(g:node#suffixesadd, ",") | |||
| let &l:include = '\<require(\(["'']\)\zs[^\1]\+\ze\1' | |||
| let &l:includeexpr = "node#lib#find(v:fname, bufname('%'))" | |||
| " @ is used for scopes, but isn't a default filename character on | |||
| " non-Windows sytems. | |||
| setlocal isfname+=@-@ | |||
| if !hasmapto("<Plug>NodeGotoFile") | |||
| " Split gotofiles don't take a count for the new window's width, but for | |||
| " opening the nth file. Though Node.vim doesn't support counts atm. | |||
| nmap <buffer> gf <Plug>NodeGotoFile | |||
| nmap <buffer> <C-w>f <Plug>NodeSplitGotoFile | |||
| nmap <buffer> <C-w><C-f> <Plug>NodeSplitGotoFile | |||
| nmap <buffer> <C-w>gf <Plug>NodeTabGotoFile | |||
| endif | |||
| endfunction | |||
| function! s:edit(name, from, ...) | |||
| if empty(a:name) | return | endif | |||
| let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h") | |||
| let command = a:0 == 1 ? a:1 : "edit" | |||
| " If just a plain filename with no directory part, check if it exists: | |||
| if a:name !~# '^\v(/|\./|\.\./)' && filereadable(dir . "/" . a:name) | |||
| let path = dir . "/" . a:name | |||
| else | |||
| let path = node#lib#find(a:name, dir) | |||
| end | |||
| if empty(path) | |||
| return s:error("E447: Can't find file \"" . a:name . "\" in path") | |||
| endif | |||
| exe command . " " . fnameescape(path) | |||
| endfunction | |||
| function! s:nedit(name, from, ...) | |||
| let command = a:0 == 1 ? a:1 : "edit" | |||
| call s:edit(a:name, b:node_root, command) | |||
| endfunction | |||
| function! s:nopen(name, from, ...) | |||
| let command = a:0 == 1 ? a:1 : "edit" | |||
| call s:nedit(a:name, a:from, command) | |||
| if exists("b:node_root") | exe "lcd " . fnameescape(b:node_root) | endif | |||
| endfunction | |||
| function! s:complete(arg, cmd, cursor) | |||
| let matches = node#lib#glob(s:dirname(a:arg)) | |||
| " Show private modules (_*) only if explicitly asked: | |||
| if a:arg[0] != "_" | call filter(matches, "v:val[0] != '_'") | endif | |||
| let filter = "stridx(v:val, a:arg) == 0" | |||
| let ignorecase = 0 | |||
| let ignorecase = ignorecase || exists("&fileignorecase") && &fileignorecase | |||
| let ignorecase = ignorecase || exists("&wildignorecase") && &wildignorecase | |||
| if ignorecase | let filter = "stridx(tolower(v:val),tolower(a:arg)) == 0" | en | |||
| return filter(matches, filter) | |||
| endfunction | |||
| function! s:dirname(path) | |||
| let dirname = fnamemodify(a:path, ":h") | |||
| if dirname == "." | return "" | endif | |||
| " To not change the amount of final consecutive slashes, using this | |||
| " dirname/basename trick: | |||
| let basename = fnamemodify(a:path, ":t") | |||
| return a:path[0 : 0 - len(basename) - 1] | |||
| endfunction | |||
| " Using the built-in :echoerr prints a stacktrace, which isn't that nice. | |||
| function! s:error(msg) | |||
| echohl ErrorMsg | |||
| echomsg a:msg | |||
| echohl NONE | |||
| let v:errmsg = a:msg | |||
| endfunction | |||
| @ -1,151 +0,0 @@ | |||
| let s:ABSPATH = '^/' | |||
| let s:RELPATH = '\v^\.\.?(/|$)' | |||
| let s:MODULE = '\v^(/|\.\.?(/|$))@!' | |||
| " Damn Netrw can't handle HTTPS at all. It's 2013! Insecure bastard! | |||
| let s:CORE_URL_PREFIX = "http://rawgit.com/nodejs/node" | |||
| let s:CORE_MODULES = ["_debugger", "_http_agent", "_http_client", | |||
| \ "_http_common", "_http_incoming", "_http_outgoing", "_http_server", | |||
| \ "_linklist", "_stream_duplex", "_stream_passthrough", "_stream_readable", | |||
| \ "_stream_transform", "_stream_writable", "_tls_legacy", "_tls_wrap", | |||
| \ "assert", "buffer", "child_process", "cluster", "console", "constants", | |||
| \ "crypto", "dgram", "dns", "domain", "events", "freelist", "fs", "http", | |||
| \ "https", "module", "net", "node", "os", "path", "punycode", "querystring", | |||
| \ "readline", "repl", "smalloc", "stream", "string_decoder", "sys", | |||
| \ "timers", "tls", "tty", "url", "util", "vm", "zlib"] | |||
| function! node#lib#find(name, from) | |||
| if index(s:CORE_MODULES, a:name) != -1 | |||
| let l:version = node#lib#version() | |||
| let l:version = empty(l:version) ? "master" : "v" . l:version | |||
| let l:dir = a:name == "node" ? "src" : "lib" | |||
| return s:CORE_URL_PREFIX ."/". l:version ."/". l:dir ."/". a:name .".js" | |||
| endif | |||
| return s:resolve(s:absolutize(a:name, a:from)) | |||
| endfunction | |||
| function! node#lib#version() | |||
| if exists("b:node_version") | return b:node_version | endif | |||
| if !executable("node") | let b:node_version = "" | return | endif | |||
| let b:node_version = matchstr(system("node --version"), '^v\?\zs[0-9.]\+') | |||
| return b:node_version | |||
| endfunction | |||
| function! s:absolutize(name, from) | |||
| if a:name =~# s:ABSPATH | |||
| return a:name | |||
| elseif a:name =~# s:RELPATH | |||
| let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h") | |||
| return dir . "/" . a:name | |||
| else | |||
| return b:node_root . "/node_modules/" . a:name | |||
| endif | |||
| endfunction | |||
| function! s:resolve(path) | |||
| " Node checks for files *before* directories, so see if the path does not | |||
| " end with a slash or dots and try to match it as a file. | |||
| if a:path !~# '\v/(\.\.?/?)?$' | |||
| let path_with_suffix = s:resolveSuffix(a:path) | |||
| if !empty(path_with_suffix) | return path_with_suffix | endif | |||
| endif | |||
| if isdirectory(a:path) | return s:resolveFromDirectory(a:path) | endif | |||
| endfunction | |||
| function! s:resolveFromDirectory(path) | |||
| " Node.js checks for package.json in every directory, not just the | |||
| " module's parent. According to: | |||
| " http://nodejs.org/api/modules.html#modules_all_together | |||
| if filereadable(a:path . "/package.json") | |||
| " Turns out, even though Node says it does not support directories in | |||
| " main, it does. | |||
| " NOTE: If package.json's main is empty or refers to a non-existent file, | |||
| " ./index.js is still tried. | |||
| let main = s:mainFromPackage(a:path . "/package.json") | |||
| if !empty(main) && main != "" | |||
| let path = s:resolve(a:path . "/" . main) | |||
| if !empty(path) | return path | endif | |||
| endif | |||
| endif | |||
| " We need to check for ./index.js's existence here rather than leave it to | |||
| " the caller, because otherwise we can't distinguish if this ./index was | |||
| " from the directory defaulting to ./index.js or it was the package.json | |||
| " which referred to ./index, which in itself could mean both ./index.js and | |||
| " ./index/index.js. | |||
| return s:resolveSuffix(a:path . "/index") | |||
| endfunction | |||
| function! s:mainFromPackage(path) | |||
| for line in readfile(a:path) | |||
| if line !~# '"main"\s*:' | continue | endif | |||
| return matchstr(line, '"main"\s*:\s*"\zs[^"]\+\ze"') | |||
| endfor | |||
| endfunction | |||
| function! s:resolveSuffix(path) | |||
| for suffix in s:uniq([""] + g:node#suffixesadd + split(&l:suffixesadd, ",")) | |||
| let path = a:path . suffix | |||
| if filereadable(path) | return path | endif | |||
| endfor | |||
| endfunction | |||
| let s:GLOB_WILDIGNORE = 1 | |||
| function! node#lib#glob(name) | |||
| let matches = [] | |||
| if empty(a:name) | |||
| let matches += s:CORE_MODULES | |||
| endif | |||
| if empty(a:name) || a:name =~# s:MODULE | |||
| let root = b:node_root . "/node_modules" | |||
| let matches += s:glob(empty(a:name) ? root : root . "/" . a:name, root) | |||
| endif | |||
| if a:name =~# s:ABSPATH | |||
| let matches += s:glob(a:name, 0) | |||
| endif | |||
| if empty(a:name) || a:name =~# s:RELPATH | |||
| let root = b:node_root | |||
| let relatives = s:glob(empty(a:name) ? root : root . "/" . a:name, root) | |||
| "call map(relatives, "substitute(v:val, '^\./\./', './', '')") | |||
| if empty(a:name) | call map(relatives, "'./' . v:val") | endif | |||
| call filter(relatives, "v:val !~# '^\\.//*node_modules/$'") | |||
| let matches += relatives | |||
| endif | |||
| return matches | |||
| endfunction | |||
| function! s:glob(path, stripPrefix) | |||
| " Remove a single trailing slash because we're adding one with the glob. | |||
| let path = substitute(a:path, '/$', "", "") | |||
| " Glob() got the ability to return a list only in Vim 7.3.465. Using split | |||
| " for compatibility. | |||
| let list = split(glob(fnameescape(path)."/*", s:GLOB_WILDIGNORE), "\n") | |||
| " Add slashes to directories, like /bin/ls. | |||
| call map(list, "v:val . (isdirectory(v:val) ? '/' : '')") | |||
| if !empty(a:stripPrefix) | |||
| " Counting and removing bytes intentionally as there's no substr function | |||
| " that takes character count, only bytes. | |||
| let prefix_length = len(a:stripPrefix) + 1 | |||
| return map(list, "strpart(v:val, prefix_length)") | |||
| endif | |||
| return list | |||
| endfunction | |||
| function! s:uniq(list) | |||
| let list = reverse(copy(a:list)) | |||
| return reverse(filter(list, "index(list, v:val, v:key + 1) == -1")) | |||
| endfunction | |||
| @ -1,8 +0,0 @@ | |||
| function! s:isNode() | |||
| let shebang = getline(1) | |||
| if shebang =~# '^#!.*/bin/env\s\+node\>' | return 1 | en | |||
| if shebang =~# '^#!.*/bin/node\>' | return 1 | en | |||
| return 0 | |||
| endfunction | |||
| au BufRead,BufNewFile * if !did_filetype() && s:isNode() | setf javascript | en | |||
| @ -1,47 +0,0 @@ | |||
| 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 | |||
| @ -1,466 +0,0 @@ | |||
| require_relative "../helper" | |||
| require "json" | |||
| describe "Lib" do | |||
| include WithTemporaryDirectory | |||
| before do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| end | |||
| def set_node_version(version) | |||
| executable = File.join(@dir, "node") | |||
| touch executable, <<-end.strip | |||
| #!/bin/sh | |||
| [ $# != 1 -o "$1" != --version ] && exit 1 | |||
| echo "v#{version}" | |||
| end | |||
| File.chmod 0755, executable | |||
| $vim.command(%(let $PATH = "#@dir:" . $PATH)) | |||
| end | |||
| describe "node#lib#find" do | |||
| def find(name) | |||
| path = $vim.echo(%(node#lib#find("#{name}", expand("%")))) | |||
| File.exists?(path) ? File.realpath(path) : path | |||
| end | |||
| it "must return ./README before ./README.js" do | |||
| target = touch File.join(@dir, "README") | |||
| touch File.join(@dir, "README.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./README").must_equal target | |||
| end | |||
| it "must return ./README.txt relative to file" do | |||
| target = touch File.join(@dir, "lib", "README.txt") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("./README.txt").must_equal target | |||
| end | |||
| it "must return ../README.txt" do | |||
| target = touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("../README.txt").must_equal target | |||
| end | |||
| it "must return /.../README.txt" do | |||
| target = touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir/README.txt").must_equal target | |||
| end | |||
| it "must return ./other.js given ./other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.jsx given ./other" do | |||
| target = touch File.join(@dir, "other.jsx") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.es given ./other" do | |||
| target = touch File.join(@dir, "other.es") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.js given ./other relative to file" do | |||
| target = touch File.join(@dir, "lib", "other.js") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ./other.js before ./other/index.js given ./other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| touch File.join(@dir, "other", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./other").must_equal target | |||
| end | |||
| it "must return ../other.js given ../other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("../other").must_equal target | |||
| end | |||
| it "must return /.../other.js given /.../other" do | |||
| target = touch File.join(@dir, "other.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir/other").must_equal target | |||
| end | |||
| it "must return ./package.json given ./package" do | |||
| target = touch File.join(@dir, "package.json") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./package").must_equal target | |||
| end | |||
| it "must return ./index.js given ." do | |||
| target = touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| find(".").must_equal target | |||
| end | |||
| it "must return ./index.js given ./" do | |||
| target = touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| find("./").must_equal target | |||
| end | |||
| it "must not find ./index/index.js given ./" do | |||
| touch File.join(@dir, "index", "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.echo(%(empty(node#lib#find("./", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must not find ./.js given ./" do | |||
| touch File.join(@dir, ".js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.echo(%(empty(node#lib#find("./", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must return ../index.js given .." do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "other.js") | |||
| find("..").must_equal target | |||
| end | |||
| it "must return ../index.js given ../" do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "other.js") | |||
| find("../").must_equal target | |||
| end | |||
| it "must return /.../index.js given /..." do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir").must_equal target | |||
| end | |||
| it "must return /.../index.js given /.../" do | |||
| target = touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "index.js") | |||
| find("#@dir/").must_equal target | |||
| end | |||
| it "must return ./lib/index.js given ./lib" do | |||
| target = touch File.join(@dir, "lib", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./lib/other.js given ./lib with main" do | |||
| target = touch File.join(@dir, "lib", "other.js") | |||
| touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "other") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./lib/index.js given ./lib with empty main" do | |||
| target = touch File.join(@dir, "lib", "index.js") | |||
| touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./lib/index.js given ./lib with non-existent main" do | |||
| target = touch File.join(@dir, "lib", "index.js") | |||
| touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "new") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("./lib").must_equal target | |||
| end | |||
| it "must return ./other.js before ./other/index.js given . with main" do | |||
| touch File.join(@dir, "package.json"), JSON.dump(:main => "other") | |||
| target = touch File.join(@dir, "other.js") | |||
| touch File.join(@dir, "other", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find(".").must_equal target | |||
| end | |||
| it "must return node_modules/foo/index.js given foo" do | |||
| index = File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch index | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal index | |||
| end | |||
| it "must return node_modules/foo/other.js given foo/other" do | |||
| other = File.join(@dir, "node_modules", "foo", "other.js") | |||
| touch other | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo/other").must_equal other | |||
| end | |||
| it "must return node_modules/foo/other.js given foo/other.js" do | |||
| other = File.join(@dir, "node_modules", "foo", "other.js") | |||
| touch other | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo/other.js").must_equal other | |||
| end | |||
| # When package.json refers to a regular file. | |||
| it "must return node_modules/foo/other.js given foo with main" do | |||
| mod = File.join(@dir, "node_modules", "foo") | |||
| touch File.join(mod, "package.json"), JSON.dump(:main => "./other.js") | |||
| target = touch File.join(mod, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal target | |||
| end | |||
| # When package.json refers to a directory. | |||
| it "must return node_modules/foo/lib/index.js given foo with main as ./lib" do | |||
| mod = File.join(@dir, "node_modules", "foo") | |||
| touch File.join(mod, "package.json"), JSON.dump(:main => "./lib") | |||
| target = touch File.join(mod, "lib/index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal target | |||
| end | |||
| it "must return node_modules/foo/lib/index.js given foo with main as lib" do | |||
| mod = File.join(@dir, "node_modules", "foo") | |||
| touch File.join(mod, "package.json"), JSON.dump(:main => "lib") | |||
| target = touch File.join(mod, "lib/index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("foo").must_equal target | |||
| end | |||
| it "must return node_modules/@scope/foo/index.js given @scope/foo" do | |||
| target = File.join(@dir, "node_modules", "@scope", "foo", "index.js") | |||
| touch target | |||
| $vim.edit File.join(@dir, "index.js") | |||
| find("@scope/foo").must_equal target | |||
| end | |||
| it "must return empty when looking for nothing" do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo(%(empty(node#lib#find("", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must return empty when nothing found" do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo(%(empty(node#lib#find("new", expand("%"))))).must_equal "1" | |||
| end | |||
| it "must return URL for core module for current Node version" do | |||
| set_node_version "0.13.37" | |||
| $vim.edit File.join(@dir, "index.js") | |||
| url = "http://rawgit.com/nodejs/node/v0.13.37/lib/assert.js" | |||
| find("assert").must_equal url | |||
| end | |||
| it "must return URL for core module on master if no Node version" do | |||
| touch File.join(@dir, "node"), "#!/bin/sh\nexit 1" | |||
| File.chmod 0755, File.join(@dir, "node") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let $PATH = "#@dir:" . $PATH)) | |||
| url = "http://rawgit.com/nodejs/node/master/lib/assert.js" | |||
| find("assert").must_equal url | |||
| end | |||
| it "must return URL for node.js for current Node version" do | |||
| set_node_version "0.13.37" | |||
| $vim.edit File.join(@dir, "index.js") | |||
| url = "http://rawgit.com/nodejs/node/v0.13.37/src/node.js" | |||
| find("node").must_equal url | |||
| end | |||
| it "must return URL for node.js on master if no Node version" do | |||
| touch File.join(@dir, "node"), "#!/bin/sh\nexit 1" | |||
| File.chmod 0755, File.join(@dir, "node") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let $PATH = "#@dir:" . $PATH)) | |||
| url = "http://rawgit.com/nodejs/node/master/src/node.js" | |||
| find("node").must_equal url | |||
| end | |||
| end | |||
| describe "node#lib#glob" do | |||
| require "json" | |||
| before do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| end | |||
| def glob(arg = "") | |||
| # Because of possible locale and filesystem case-sensitiveness | |||
| # differences, sort the output explicitly to be resistant. | |||
| JSON.parse($vim.echo(%(node#lib#glob("#{arg}"))).gsub("'", '"')).sort | |||
| end | |||
| describe "given nothing" do | |||
| it "must return files and directories" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| files = %w[./README.txt ./index.js ./test/] | |||
| glob.must_equal (CORE_MODULES + files).sort | |||
| end | |||
| it "must return modules and core modules" do | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "require-guard") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "export") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul") | |||
| glob.must_equal (CORE_MODULES + %w[export/ require-guard/ soul/]).sort | |||
| end | |||
| it "must return core modules without slashes" do | |||
| glob.must_equal CORE_MODULES | |||
| glob.wont_equal /\// | |||
| end | |||
| # Even though node.js is the bootstrapper file in src/. | |||
| it "must return \"node\" as one of those core modules" do | |||
| glob.must_include "node" | |||
| end | |||
| it "must return files, directories and modules" do | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "export") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul") | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| files = %w[./README.txt ./index.js ./test/ export/ soul/] | |||
| glob.must_equal (CORE_MODULES + files).sort | |||
| end | |||
| it "must not return the node_modules directory" do | |||
| FileUtils.mkpath File.join(@dir, "node_modules") | |||
| glob.must_equal CORE_MODULES | |||
| end | |||
| end | |||
| describe "given absolute path" do | |||
| it "must return files and directories given /" do | |||
| files = Dir.entries("/") | |||
| files.reject! {|f| f =~ /^\./ } | |||
| files.sort! | |||
| files.map! {|f| "/" + f } | |||
| files.map! {|f| File.directory?(f) ? f + "/" : f } | |||
| glob("/").must_equal files | |||
| end | |||
| it "must return files and directories given /.../" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/] | |||
| glob(@dir).must_equal files | |||
| end | |||
| it "must return files and directories given /.../test" do | |||
| touch File.join(@dir, "test", "index_test.js") | |||
| touch File.join(@dir, "test", "helpers.js") | |||
| files = %W[#@dir/test/helpers.js #@dir/test/index_test.js] | |||
| glob(File.join(@dir, "test")).must_equal files | |||
| end | |||
| it "must not return modules along with files" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul") | |||
| files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/] | |||
| glob(@dir).must_equal files | |||
| end | |||
| end | |||
| describe "given relative path" do | |||
| it "must return files and directories given ." do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob(".").must_equal %W[./README ./index.js ./test/] | |||
| end | |||
| it "must return files and directories given ./" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob("./").must_equal %W[./README ./index.js ./test/] | |||
| end | |||
| it "must return files and directories given .//" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob(".//").must_equal %W[.//README.txt .//index.js .//test/] | |||
| end | |||
| it "must return files and directories given .///" do | |||
| touch File.join(@dir, "index.js") | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "test") | |||
| glob(".///").must_equal %W[.///README.txt .///index.js .///test/] | |||
| end | |||
| it "must return files and directories given ./test" do | |||
| touch File.join(@dir, "test", "test.js") | |||
| touch File.join(@dir, "test", "helpers.js") | |||
| glob("./test/").must_equal %W[./test/helpers.js ./test/test.js] | |||
| end | |||
| end | |||
| describe "given module name" do | |||
| it "must return files and directories given soul" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "README") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul").must_equal %w[soul/README soul/index.js soul/test/] | |||
| end | |||
| it "must return files and directories given soul/" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul/").must_equal %w[soul/index.js soul/test/] | |||
| end | |||
| it "must return files and directories given soul//" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul//").must_equal %w[soul//index.js soul//test/] | |||
| end | |||
| it "must return files and directories given soul///" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test") | |||
| glob("soul///").must_equal %w[soul///index.js soul///test/] | |||
| end | |||
| it "must return files and directories given soul/test" do | |||
| touch File.join(@dir, "node_modules", "soul", "test", "test.js") | |||
| touch File.join(@dir, "node_modules", "soul", "test", "helpers.js") | |||
| glob("soul/test").must_equal %w[soul/test/helpers.js soul/test/test.js] | |||
| end | |||
| end | |||
| end | |||
| describe "node#lib#version" do | |||
| it "should return current Node's version" do | |||
| set_node_version "0.13.37" | |||
| $vim.echo("node#lib#version()").must_equal "0.13.37" | |||
| end | |||
| end | |||
| end | |||
| @ -1,538 +0,0 @@ | |||
| require_relative "./helper" | |||
| require "json" | |||
| describe "Autoloaded" do | |||
| include WithTemporaryDirectory | |||
| before do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| end | |||
| after do | |||
| $vim.command("windo wincmd c") | |||
| end | |||
| describe "Autocommand" do | |||
| it "must fire user autcommand \"Node\"" do | |||
| $vim.command "au User Node let node_autocommand = 1337" | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.echo(%(g:node_autocommand)).must_equal "1337" | |||
| end | |||
| end | |||
| describe "Goto file" do | |||
| it "must define plug mapping in non-JavaScript files" do | |||
| $vim.edit File.join(@dir, "README") | |||
| $vim.echo(%(maparg("<Plug>NodeGotoFile", "n"))).wont_equal "" | |||
| end | |||
| it "must not be mapped in non-JavaScript files" do | |||
| $vim.edit File.join(@dir, "README") | |||
| $vim.echo(%(hasmapto("<Plug>NodeGotoFile"))).must_equal "0" | |||
| end | |||
| it "must edit README.txt" do | |||
| touch File.join(@dir, "index.js"), %(// Please read README.txt) | |||
| touch File.join(@dir, "README.txt") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$gf" | |||
| $vim.echo(%(bufname("%"))).must_equal File.join(@dir, "README.txt") | |||
| end | |||
| it "must edit README before README.js" do | |||
| touch File.join(@dir, "index.js"), "// Please read README" | |||
| touch File.join(@dir, "README") | |||
| touch File.join(@dir, "README.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "README") | |||
| end | |||
| it "must edit ./README.txt relative to file" do | |||
| touch File.join(@dir, "foo", "index.js"), %(// Please read ./README.txt) | |||
| touch File.join(@dir, "foo", "README.txt") | |||
| $vim.edit File.join(@dir, "foo", "index.js") | |||
| $vim.feedkeys "$gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "foo", "README.txt") | |||
| end | |||
| it "must edit /.../README.txt" do | |||
| touch File.join(@dir, "index.js"), %(// Read #@dir/lib/README.txt) | |||
| touch File.join(@dir, "lib", "README.txt") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "lib", "README.txt") | |||
| end | |||
| it "must edit ./other.js relative to file" do | |||
| touch File.join(@dir, "foo", "index.js"), %(require("./other")) | |||
| touch File.join(@dir, "foo", "other.js") | |||
| $vim.edit File.join(@dir, "foo", "index.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "foo", "other.js") | |||
| end | |||
| it "must edit ./index.js given ." do | |||
| touch File.join(@dir, "other.js"), %(require(".")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./index.js given ./" do | |||
| touch File.join(@dir, "other.js"), %(require("./")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ../index.js given .." do | |||
| touch File.join(@dir, "foo", "other.js"), %(require("..")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "foo", "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ../index.js given ../" do | |||
| touch File.join(@dir, "foo", "other.js"), %(require("../")) | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "foo", "other.js") | |||
| $vim.feedkeys "f.gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./node_modules/foo/index.js given foo" do | |||
| touch File.join(@dir, "index.js"), %(require("foo")) | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must edit ./node_modules/@scope/foo/index.js given @scope/foo" do | |||
| touch File.join(@dir, "index.js"), %(require("@scope/foo")) | |||
| target = File.join(@dir, "node_modules", "@scope", "foo", "index.js") | |||
| touch target | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must not show an error when searching for nothing" do | |||
| touch File.join(@dir, "index.js"), %("") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let v:errmsg = "")) | |||
| $vim.feedkeys "gf" | |||
| error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "") | |||
| error.must_equal "" | |||
| end | |||
| it "must show error when searching for a non-existent file" do | |||
| touch File.join(@dir, "index.js"), %(require("new")) | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command(%(let v:errmsg = "")) | |||
| $vim.feedkeys "$hhgf" | |||
| error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "") | |||
| error.must_equal %(E447: Can't find file "new" in path) | |||
| end | |||
| it "must find when filetype is JavaScript and file exists" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.js"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype is JavaScript and file new" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.insert %(require("foo")) | |||
| $vim.normal | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype is JSON" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| # NOTE: Use an extensionless file and set ft manually to not have | |||
| # filetype.vim set its filetype to JavaScript automatically. | |||
| $vim.command("au BufReadPre package set ft=json") | |||
| touch File.join(@dir, "package"), %({"dependencies": {"foo": "1.x"}}) | |||
| $vim.edit File.join(@dir, "package") | |||
| $vim.echo("&filetype").must_equal "json" | |||
| $vim.feedkeys "/foo\\<CR>gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal target | |||
| end | |||
| it "must find when filetype set to JavaScript after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype javascript") | |||
| $vim.echo("&filetype").must_equal "javascript" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype set to JSX after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype jsx") | |||
| $vim.echo("&filetype").must_equal "jsx" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| it "must find when filetype set to JavaScript and Foo after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype javascript.foo") | |||
| $vim.echo("&filetype").must_equal "javascript.foo" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| # Ensure the autocommand detects both orderings. | |||
| it "must find when filetype set to Foo and JavaScript after open" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| touch File.join(@dir, "index.react"), %(require("foo")) | |||
| $vim.edit File.join(@dir, "index.react") | |||
| $vim.echo("&filetype").must_equal "" | |||
| $vim.command("setfiletype foo.javascript") | |||
| $vim.echo("&filetype").must_equal "foo.javascript" | |||
| $vim.feedkeys "$hhgf" | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| end | |||
| describe "Goto file with split" do | |||
| it "must edit file in a new split" do | |||
| touch File.join(@dir, "index.js"), %(require("./other")) | |||
| touch File.join(@dir, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "f.\\<C-w>f" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "other.js") | |||
| $vim.echo(%(winnr("$"))).must_equal "2" | |||
| end | |||
| end | |||
| describe "Goto file with tab" do | |||
| it "must edit file in a new tab" do | |||
| touch File.join(@dir, "index.js"), %(require("./other")) | |||
| touch File.join(@dir, "other.js") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.feedkeys "f.\\<C-w>gf" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "other.js") | |||
| $vim.echo(%(tabpagenr("$"))).must_equal "2" | |||
| end | |||
| end | |||
| describe "Include file search pattern" do | |||
| it "must find matches given a require" do | |||
| touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "") | |||
| var awesome = require("foo") | |||
| awesome() | |||
| end | |||
| definition = %(module.exports = function awesome() { return 1337 }) | |||
| touch File.join(@dir, "node_modules", "foo", "index.js"), definition | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command("normal G[i").must_equal definition | |||
| end | |||
| it "must find matches given a relative require" do | |||
| touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "") | |||
| var awesome = require("./other") | |||
| awesome() | |||
| end | |||
| definition = %(module.exports = function awesome() { return 1337 }) | |||
| touch File.join(@dir, "other.js"), definition | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.command("normal G[i").must_equal definition | |||
| end | |||
| it "must find matches given a relative require in another directory" do | |||
| touch File.join(@dir, "foo", "index.js"), <<-end.gsub(/^\s+/, "") | |||
| var awesome = require("./other") | |||
| awesome() | |||
| end | |||
| definition = %(module.exports = function awesome() { return 1337 }) | |||
| touch File.join(@dir, "foo", "other.js"), definition | |||
| $vim.edit File.join(@dir, "foo", "index.js") | |||
| $vim.command("normal G[i").must_equal definition | |||
| end | |||
| end | |||
| describe ":Nedit" do | |||
| # NOTE: Test from a non-JavaScript file everywhere to make sure there are | |||
| # no dependencies on JavaScript specific settings. | |||
| FULL_COMMAND_MATCH = "2" | |||
| it "must be available in non-JavaScript files" do | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH | |||
| end | |||
| it "must be available in JavaScript files" do | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH | |||
| end | |||
| it "must edit ./README.txt" do | |||
| touch File.join(@dir, "README.txt") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit ./README.txt" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "README.txt") | |||
| end | |||
| it "must edit ./README.txt relative to node_root" do | |||
| touch File.join(@dir, "README.txt") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") | |||
| $vim.command "Nedit ./README.txt" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "README.txt") | |||
| end | |||
| it "must edit /.../README.txt" do | |||
| touch File.join(@dir, "lib", "README.txt") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit #@dir/lib/README.txt" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "lib", "README.txt") | |||
| end | |||
| it "must edit ./other.js relative to node_root" do | |||
| touch File.join(@dir, "other.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") | |||
| $vim.command "Nedit ./other" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "other.js") | |||
| end | |||
| it "must edit ./index.js given ." do | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit ." | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./index.js given . relative to node_root" do | |||
| touch File.join(@dir, "index.js") | |||
| Dir.mkdir File.join(@dir, "lib") | |||
| $vim.edit File.join(@dir, "lib", "CHANGELOG.txt") | |||
| $vim.command "Nedit ." | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit ./index.js given ./" do | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "CHANGELOG.txt") | |||
| $vim.command "Nedit ./" | |||
| bufname = File.realpath($vim.echo(%(bufname("%")))) | |||
| bufname.must_equal File.join(@dir, "index.js") | |||
| end | |||
| it "must edit /node_modules/foo/index.js given foo" do | |||
| target = touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.command("Nedit foo") | |||
| $vim.echo(%(bufname("%"))).must_equal target | |||
| end | |||
| describe "completion" do | |||
| after do | |||
| $vim.command("set wildignorecase&") | |||
| $vim.command("set fileignorecase&") | |||
| end | |||
| def complete(cmd) | |||
| cmdline = $vim.command(%(silent! normal! :#{cmd}e)) | |||
| cmdline.sub(/^:\w+\s+/, "") | |||
| end | |||
| public_core_modules = CORE_MODULES.select {|m| m[0] != "_" } | |||
| private_core_modules = CORE_MODULES.select {|m| m[0] == "_" } | |||
| it "must return files, directories, modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| Dir.mkdir File.join(@dir, "node_modules", "require-guard") | |||
| Dir.mkdir File.join(@dir, "node_modules", "export") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soul") | |||
| touch File.join(@dir, "index.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| files = %w[export/ require-guard/ soul/ ./index.js ./package.json] | |||
| all = public_core_modules + files | |||
| complete("Nedit ").split.sort.must_equal all.sort | |||
| end | |||
| it "must return only public core modules" do | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| modules = public_core_modules + ["./package.json"] | |||
| complete("Nedit ").must_equal modules.join(" ") | |||
| end | |||
| it "must return private core modules if explicitly asked" do | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit _").must_equal private_core_modules.join(" ") | |||
| end | |||
| it "must return only matching modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| Dir.mkdir File.join(@dir, "node_modules", "export") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soul") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soulstash") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| modules = "smalloc stream string_decoder sys soul/ soulstash/" | |||
| complete("Nedit s").must_equal modules | |||
| end | |||
| it "must not return modules with matching bit in the middle" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soul") | |||
| Dir.mkdir File.join(@dir, "node_modules", "soulstash") | |||
| Dir.mkdir File.join(@dir, "node_modules", "asoul") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit sou").must_equal "soul/ soulstash/" | |||
| end | |||
| it "must return files and directories in module's directory" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "test", "test.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul/").must_equal "soul/index.js soul/test/" | |||
| end | |||
| it "must return files and directories given a double slash" do | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "test", "test.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul//").must_equal "soul//index.js soul//test/" | |||
| end | |||
| it "must return files case-insensitively given &fileignorecase" do | |||
| skip if $vim.echo(%(exists("&fileignorecase"))) != "1" | |||
| $vim.command("set fileignorecase") | |||
| $vim.command("set nowildignorecase") | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "CHANGELOG") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul/chan").must_equal "soul/CHANGELOG" | |||
| end | |||
| it "must return files case-insensitively given only &wildignorecase" do | |||
| skip if $vim.echo(%(exists("&wildignorecase"))) != "1" | |||
| $vim.command("set nofileignorecase") | |||
| $vim.command("set wildignorecase") | |||
| touch File.join(@dir, "node_modules", "soul", "index.js") | |||
| touch File.join(@dir, "node_modules", "soul", "CHANGELOG") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| complete("Nedit soul/chan").must_equal "soul/CHANGELOG" | |||
| end | |||
| end | |||
| end | |||
| describe ":Nopen" do | |||
| it "must edit and lcd to module's directory" do | |||
| touch File.join(@dir, "node_modules", "foo", "package.json") | |||
| touch File.join(@dir, "node_modules", "foo", "index.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.command("vsplit") | |||
| $vim.command("Nopen foo") | |||
| $vim.echo(%(bufname("%"))).must_equal "index.js" | |||
| $vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo") | |||
| $vim.command("wincmd p") | |||
| $vim.command("pwd").must_equal Dir.pwd | |||
| end | |||
| it "must edit and lcd to module's root directory" do | |||
| touch File.join(@dir, "node_modules", "foo", "package.json") | |||
| utils = touch File.join(@dir, "node_modules", "foo", "lib", "utils.js") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.command("vsplit") | |||
| $vim.command("Nopen foo/lib/utils") | |||
| $vim.echo(%(bufname("%"))).must_equal "lib/utils.js" | |||
| $vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo") | |||
| $vim.command("wincmd p") | |||
| $vim.command("pwd").must_equal Dir.pwd | |||
| end | |||
| end | |||
| end | |||
| @ -1,45 +0,0 @@ | |||
| require_relative "./helper" | |||
| describe "Ftdetect" do | |||
| [ | |||
| "#!/usr/bin/env node", | |||
| "#!/usr/bin/env node --harmony-generators", | |||
| "#!/usr/local/bin/env node", | |||
| "#!/usr/local/bin/env node --harmony-generators", | |||
| "#!/usr/bin/node", | |||
| "#!/usr/bin/node --harmony-generators", | |||
| "#!/usr/local/bin/node", | |||
| "#!/usr/local/bin/node --harmony-generators", | |||
| ].each do |shebang| | |||
| it %(must detect a file with "#{shebang}" shebang as JavaScript) do | |||
| file = Tempfile.new("bang") | |||
| file.write shebang + $/ | |||
| file.close | |||
| $vim.edit file.path | |||
| $vim.echo("&ft").must_equal "javascript" | |||
| end | |||
| end | |||
| [ | |||
| "#!/usr/bin/env noder", | |||
| "#!/usr/bin/noder", | |||
| ].each do |shebang| | |||
| it %(must not detect a file with "#{shebang}" shebang as JavaScript) do | |||
| file = Tempfile.new("bang") | |||
| file.write shebang + $/ | |||
| file.close | |||
| $vim.edit file.path | |||
| $vim.echo("&ft").wont_equal "javascript" | |||
| end | |||
| end | |||
| it "must not detect a .c file as JavaScript even with Node's shebang" do | |||
| file = Tempfile.new(%w[tea .c]) | |||
| file.write "#!/usr/bin/node" + $/ | |||
| file.close | |||
| $vim.edit file.path | |||
| $vim.echo("&ft").wont_equal "javascript" | |||
| end | |||
| end | |||
| @ -1,54 +0,0 @@ | |||
| require "minitest/autorun" | |||
| require "vimrunner" | |||
| require "fileutils" | |||
| require "tempfile" | |||
| MiniTest::Unit::TestCase.define_singleton_method(:test_order) do :alpha end | |||
| begin | |||
| require "minitest/reporters" | |||
| MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new | |||
| rescue LoadError | |||
| end | |||
| $vimrc = File.expand_path("../vimrc", __FILE__) | |||
| $vim = Vimrunner::Server.new(:vimrc => $vimrc).start | |||
| Minitest::Unit.after_tests { $vim.kill } | |||
| module WithTemporaryDirectory | |||
| def self.included(base) | |||
| require "tmpdir" | |||
| end | |||
| def setup | |||
| super | |||
| # Mac has the temporary directory symlinked, so need File.realpath to | |||
| # match the paths that Vim returns. | |||
| @dir = File.realpath(Dir.mktmpdir) | |||
| end | |||
| def teardown | |||
| FileUtils.remove_entry_secure @dir | |||
| super | |||
| end | |||
| end | |||
| def touch(path, contents = nil) | |||
| FileUtils.mkpath File.dirname(path) | |||
| if contents.nil? || contents.empty? | |||
| FileUtils.touch(path) | |||
| else | |||
| File.open(path, "w") {|f| f.write contents } | |||
| end | |||
| path | |||
| end | |||
| CORE_MODULES = %w[_debugger _http_agent _http_client _http_common | |||
| _http_incoming _http_outgoing _http_server _linklist _stream_duplex | |||
| _stream_passthrough _stream_readable _stream_transform _stream_writable | |||
| _tls_legacy _tls_wrap assert buffer child_process cluster console | |||
| constants crypto dgram dns domain events freelist fs http https module | |||
| net node os path punycode querystring readline repl smalloc stream | |||
| string_decoder sys timers tls tty url util vm zlib] | |||
| @ -1,85 +0,0 @@ | |||
| require_relative "./helper" | |||
| describe "Plugin" do | |||
| include WithTemporaryDirectory | |||
| describe "b:node_root" do | |||
| it "must be set when in same directory with package.json" do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set when in same directory with node_modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| $vim.edit File.join(@dir, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set when ancestor directory has package.json" do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| nested = File.join(@dir, "lib", "awesomeness") | |||
| FileUtils.mkdir_p nested | |||
| $vim.edit File.join(nested, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set when ancestor directory has node_modules" do | |||
| Dir.mkdir File.join(@dir, "node_modules") | |||
| nested = File.join(@dir, "lib", "awesomeness") | |||
| FileUtils.mkdir_p nested | |||
| $vim.edit File.join(nested, "index.js") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set also for other filetypes" do | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| $vim.edit File.join(@dir, "README.txt") | |||
| $vim.echo("b:node_root").must_equal @dir | |||
| end | |||
| it "must be set in nested Node projects" do | |||
| nested = File.join(@dir, "node_modules", "require-guard") | |||
| FileUtils.mkdir_p nested | |||
| FileUtils.touch File.join(nested, "package.json") | |||
| test = File.join(nested, "test") | |||
| FileUtils.mkdir_p test | |||
| $vim.edit File.join(test, "index_test.js") | |||
| $vim.echo("b:node_root").must_equal nested | |||
| end | |||
| it "must not be set when no ancestor has one" do | |||
| $vim.edit File.join(@dir, "index_test.js") | |||
| $vim.echo(%(exists("b:node_root"))).must_equal "0" | |||
| end | |||
| it "must be set from file, not working directory" do | |||
| $vim.command "cd #{@dir}" | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| nested = File.join(@dir, "node_modules", "require-guard") | |||
| FileUtils.mkdir_p nested | |||
| FileUtils.touch File.join(nested, "package.json") | |||
| $vim.edit File.join(nested, "index_test.js") | |||
| $vim.echo("b:node_root").must_equal nested | |||
| end | |||
| it "must detect directory as Node's when opening Vim" do | |||
| begin | |||
| Dir.chdir @dir | |||
| FileUtils.touch File.join(@dir, "package.json") | |||
| vim = Vimrunner::Server.new(:vimrc => $vimrc).start | |||
| vim.command("pwd").must_equal @dir | |||
| vim.echo("b:node_root").must_equal @dir | |||
| ensure | |||
| vim.kill if vim | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @ -1,14 +0,0 @@ | |||
| set nocompatible | |||
| set noswapfile | |||
| set nobackup | |||
| set hidden | |||
| set runtimepath-=~/.vim | |||
| set runtimepath-=~/.vim/after | |||
| let &runtimepath = expand("<sfile>:p:h:h") . "," . &runtimepath | |||
| filetype plugin indent on | |||
| syntax on | |||
| set columns=80 lines=24 | |||
| winpos 1337 0 | |||
| @ -0,0 +1,6 @@ | |||
| *.swp | |||
| # debug files | |||
| /after/autoload/nodejs-doc-all.json | |||
| /after/autoload/nodejs-doc.vim.js | |||