├── .gitignore ├── README.md └── after ├── autoload ├── nodejs-doc.vim ├── nodejscomplete.vim └── update-nodejs-doc.js ├── ftplugin └── javascript.vim └── test └── a.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.swp 3 | 4 | # debug files 5 | /after/autoload/nodejs-doc-all.json 6 | /after/autoload/nodejs-doc.vim.js 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vim-nodejs-complete 2 | =================== 3 | 4 | Nodejs `'omnifunc'` function of vim 5 | 6 | Support node's builtin module's method&property completion(`ctrl-x ctrl-o`) in `js` file with preview. 7 | 8 | 9 | ## Install 10 | Download the [tarball](https://github.com/myhere/vim-nodejs-complete/zipball/master) and extract to your vimfiles(`~/.vim` or `~/vimfiles`) folder. 11 | 12 | Completion require `:filetype plugin on`, please make sure it's on. 13 | 14 | ## Settings 15 | All the settings is optional. 16 | 17 | ```viml 18 | let g:nodejs_complete_config = { 19 | \ 'js_compl_fn': 'jscomplete#CompleteJS', 20 | \ 'max_node_compl_len': 15 21 | \} 22 | ``` 23 | 24 | ### js_compl_fn 25 | * `String` function name, called to complete javascript 26 | * default to `javascriptcomplete#CompleteJS` 27 | * if you want to integrate with [jscomplete](https://github.com/teramako/jscomplete-vim), set it to `jscomplete#CompleteJS`, make sure it's installed. 28 | 29 | ### max_node_compl_len 30 | * `Number`, length of nodejs complete items. set to 0 if unlimited 31 | 32 | 33 | ## Example 34 | 35 | ```js 36 | var fs = req 37 | // then hit ctrl-x_ctrl-o you'll get: 38 | var fs = require( 39 | // and then hit ctrl-x_ctrl-o again you'll get module name completion 40 | 41 | var fs = require('f 42 | // then hit ctrl-x_ctrl-o 43 | 44 | fs. 45 | // then hit ctrl-x_ctrl-o 46 | 47 | proc 48 | // then hit ctrl-x_ctrl-o 49 | 50 | process.ex 51 | // then hit ctrl-x_ctrl-o 52 | ``` 53 | 54 | 55 | ## Tip 56 | 1. Close the method preview window 57 | 58 | `ctrl-w_ctrl-z` or `:pc`. 59 | 60 | If you want close it automatically, put the code(from [spf13-vim](https://github.com/spf13/spf13-vim/blob/3.0/.vimrc)) below in your `.vimrc` file. 61 | 62 | ```vim 63 | " automatically open and close the popup menu / preview window 64 | au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif 65 | ``` 66 | 67 | 2. About vim's complete 68 | 69 | Vim supports several kinds of completion, `:h ins-completion` for help. 70 | 71 | 3. Completion of module in `node_modules` will cache result of every `js` file 72 | 73 | If you modified module in `node_modules` directory, use code below to clear the cache. 74 | 75 | ```vim 76 | :unlet b:npm_module_names 77 | ``` 78 | 79 | 80 | ## Feedback 81 | [feedback or advice or feature-request](https://github.com/myhere/vim-nodejs-complete/issues) 82 | 83 | -------------------------------------------------------------------------------- /after/autoload/nodejs-doc.vim: -------------------------------------------------------------------------------- 1 | " this file is auto created by "c:\Documents and Settings\zhanglin\.vim\bundle\vim-nodejs-complete\after\autoload\update-nodejs-doc.js", please do not edit it yourself! 2 | let g:nodejs_complete_data = {"globals":{"console":{"props":[{"word":"assert","info":"console.assert(expression, [message])","kind":"f"},{"word":"dir","info":"console.dir(obj)","kind":"f"},{"word":"error","info":"console.error([data], [...])","kind":"f"},{"word":"info","info":"console.info([data], [...])","kind":"f"},{"word":"log","info":"console.log([data], [...])","kind":"f"},{"word":"time","info":"console.time(label)","kind":"f"},{"word":"timeEnd","info":"console.timeEnd(label)","kind":"f"},{"word":"trace","info":"console.trace(label)","kind":"f"},{"word":"warn","info":"console.warn([data], [...])","kind":"f"}],"classes":{}},"process":{"props":[{"word":"abort","info":"process.abort()","kind":"f"},{"word":"arch","kind":"m","info":" "},{"word":"argv","kind":"m","info":" "},{"word":"chdir","info":"process.chdir(directory)","kind":"f"},{"word":"config","kind":"m","info":" "},{"word":"cwd","info":"process.cwd()","kind":"f"},{"word":"env","kind":"m","info":" "},{"word":"execPath","kind":"m","info":" "},{"word":"exit","info":"process.exit([code])","kind":"f"},{"word":"getgid","info":"process.getgid()","kind":"f"},{"word":"getuid","info":"process.getuid()","kind":"f"},{"word":"hrtime","info":"process.hrtime()","kind":"f"},{"word":"kill","info":"process.kill(pid, [signal])","kind":"f"},{"word":"memoryUsage","info":"process.memoryUsage()","kind":"f"},{"word":"nextTick","info":"process.nextTick(callback)","kind":"f"},{"word":"pid","kind":"m","info":" "},{"word":"platform","kind":"m","info":" "},{"word":"setgid","info":"process.setgid(id)","kind":"f"},{"word":"setuid","info":"process.setuid(id)","kind":"f"},{"word":"stderr","kind":"m","info":" "},{"word":"stdin","kind":"m","info":" "},{"word":"stdout","kind":"m","info":" "},{"word":"title","kind":"m","info":" "},{"word":"umask","info":"process.umask([mask])","kind":"f"},{"word":"uptime","info":"process.uptime()","kind":"f"},{"word":"version","kind":"m","info":" "},{"word":"versions","kind":"m","info":" "}],"classes":{}},"require":{"props":[{"word":"cache","kind":"m","info":" "},{"word":"extensions","kind":"m","info":" "},{"word":"resolve","info":"require.resolve()","kind":"f"}],"classes":{}},"Buffer":{"props":[],"classes":{".self":[{"word":"copy","info":"buf.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])","kind":"f"},{"word":"fill","info":"buf.fill(value, [offset], [end])","kind":"f"},{"word":"length","kind":"m","info":" "},{"word":"readDoubleBE","info":"buf.readDoubleBE(offset, [noAssert])","kind":"f"},{"word":"readDoubleLE","info":"buf.readDoubleLE(offset, [noAssert])","kind":"f"},{"word":"readFloatBE","info":"buf.readFloatBE(offset, [noAssert])","kind":"f"},{"word":"readFloatLE","info":"buf.readFloatLE(offset, [noAssert])","kind":"f"},{"word":"readInt16BE","info":"buf.readInt16BE(offset, [noAssert])","kind":"f"},{"word":"readInt16LE","info":"buf.readInt16LE(offset, [noAssert])","kind":"f"},{"word":"readInt32BE","info":"buf.readInt32BE(offset, [noAssert])","kind":"f"},{"word":"readInt32LE","info":"buf.readInt32LE(offset, [noAssert])","kind":"f"},{"word":"readInt8","info":"buf.readInt8(offset, [noAssert])","kind":"f"},{"word":"readUInt16BE","info":"buf.readUInt16BE(offset, [noAssert])","kind":"f"},{"word":"readUInt16LE","info":"buf.readUInt16LE(offset, [noAssert])","kind":"f"},{"word":"readUInt32BE","info":"buf.readUInt32BE(offset, [noAssert])","kind":"f"},{"word":"readUInt32LE","info":"buf.readUInt32LE(offset, [noAssert])","kind":"f"},{"word":"readUInt8","info":"buf.readUInt8(offset, [noAssert])","kind":"f"},{"word":"slice","info":"buf.slice([start], [end])","kind":"f"},{"word":"toString","info":"buf.toString([encoding], [start], [end])","kind":"f"},{"word":"write","info":"buf.write(string, [offset], [length], [encoding])","kind":"f"},{"word":"writeDoubleBE","info":"buf.writeDoubleBE(value, offset, [noAssert])","kind":"f"},{"word":"writeDoubleLE","info":"buf.writeDoubleLE(value, offset, [noAssert])","kind":"f"},{"word":"writeFloatBE","info":"buf.writeFloatBE(value, offset, [noAssert])","kind":"f"},{"word":"writeFloatLE","info":"buf.writeFloatLE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt16BE","info":"buf.writeInt16BE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt16LE","info":"buf.writeInt16LE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt32BE","info":"buf.writeInt32BE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt32LE","info":"buf.writeInt32LE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt8","info":"buf.writeInt8(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt16BE","info":"buf.writeUInt16BE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt16LE","info":"buf.writeUInt16LE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt32BE","info":"buf.writeUInt32BE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt32LE","info":"buf.writeUInt32LE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt8","info":"buf.writeUInt8(value, offset, [noAssert])","kind":"f"}]}}},"modules":{"assert":{"props":[{"word":"deepEqual","info":"assert.deepEqual(actual, expected, [message])","kind":"f"},{"word":"doesNotThrow","info":"assert.doesNotThrow(block, [error], [message])","kind":"f"},{"word":"equal","info":"assert.equal(actual, expected, [message])","kind":"f"},{"word":"fail","info":"assert.fail(actual, expected, message, operator)","kind":"f"},{"word":"ifError","info":"assert.ifError(value)","kind":"f"},{"word":"notDeepEqual","info":"assert.notDeepEqual(actual, expected, [message])","kind":"f"},{"word":"notEqual","info":"assert.notEqual(actual, expected, [message])","kind":"f"},{"word":"notStrictEqual","info":"assert.notStrictEqual(actual, expected, [message])","kind":"f"},{"word":"ok","info":"assert(value, message), assert.ok(value, [message])","kind":"f"},{"word":"strictEqual","info":"assert.strictEqual(actual, expected, [message])","kind":"f"},{"word":"throws","info":"assert.throws(block, [error], [message])","kind":"f"}],"classes":{}},"buffer":{"props":[{"word":"Buffer","kind":"f","info":" "},{"word":"INSPECT_MAX_BYTES","kind":"m","info":" "},{"word":"SlowBuffer","kind":"f","info":" "}],"classes":{"Buffer":[{"word":"copy","info":"buf.copy(targetBuffer, [targetStart], [sourceStart], [sourceEnd])","kind":"f"},{"word":"fill","info":"buf.fill(value, [offset], [end])","kind":"f"},{"word":"length","kind":"m","info":" "},{"word":"readDoubleBE","info":"buf.readDoubleBE(offset, [noAssert])","kind":"f"},{"word":"readDoubleLE","info":"buf.readDoubleLE(offset, [noAssert])","kind":"f"},{"word":"readFloatBE","info":"buf.readFloatBE(offset, [noAssert])","kind":"f"},{"word":"readFloatLE","info":"buf.readFloatLE(offset, [noAssert])","kind":"f"},{"word":"readInt16BE","info":"buf.readInt16BE(offset, [noAssert])","kind":"f"},{"word":"readInt16LE","info":"buf.readInt16LE(offset, [noAssert])","kind":"f"},{"word":"readInt32BE","info":"buf.readInt32BE(offset, [noAssert])","kind":"f"},{"word":"readInt32LE","info":"buf.readInt32LE(offset, [noAssert])","kind":"f"},{"word":"readInt8","info":"buf.readInt8(offset, [noAssert])","kind":"f"},{"word":"readUInt16BE","info":"buf.readUInt16BE(offset, [noAssert])","kind":"f"},{"word":"readUInt16LE","info":"buf.readUInt16LE(offset, [noAssert])","kind":"f"},{"word":"readUInt32BE","info":"buf.readUInt32BE(offset, [noAssert])","kind":"f"},{"word":"readUInt32LE","info":"buf.readUInt32LE(offset, [noAssert])","kind":"f"},{"word":"readUInt8","info":"buf.readUInt8(offset, [noAssert])","kind":"f"},{"word":"slice","info":"buf.slice([start], [end])","kind":"f"},{"word":"toString","info":"buf.toString([encoding], [start], [end])","kind":"f"},{"word":"write","info":"buf.write(string, [offset], [length], [encoding])","kind":"f"},{"word":"writeDoubleBE","info":"buf.writeDoubleBE(value, offset, [noAssert])","kind":"f"},{"word":"writeDoubleLE","info":"buf.writeDoubleLE(value, offset, [noAssert])","kind":"f"},{"word":"writeFloatBE","info":"buf.writeFloatBE(value, offset, [noAssert])","kind":"f"},{"word":"writeFloatLE","info":"buf.writeFloatLE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt16BE","info":"buf.writeInt16BE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt16LE","info":"buf.writeInt16LE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt32BE","info":"buf.writeInt32BE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt32LE","info":"buf.writeInt32LE(value, offset, [noAssert])","kind":"f"},{"word":"writeInt8","info":"buf.writeInt8(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt16BE","info":"buf.writeUInt16BE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt16LE","info":"buf.writeUInt16LE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt32BE","info":"buf.writeUInt32BE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt32LE","info":"buf.writeUInt32LE(value, offset, [noAssert])","kind":"f"},{"word":"writeUInt8","info":"buf.writeUInt8(value, offset, [noAssert])","kind":"f"}],"SlowBuffer":[]}},"child_process":{"props":[{"word":"ChildProcess","kind":"f","info":" "},{"word":"exec","info":"child_process.exec(command, [options], callback)","kind":"f"},{"word":"execFile","info":"child_process.execFile(file, args, options, callback)","kind":"f"},{"word":"fork","info":"child\\_process.fork(modulePath, [args], [options])","kind":"f"},{"word":"spawn","info":"child_process.spawn(command, [args], [options])","kind":"f"}],"classes":{"ChildProcess":[{"word":"disconnect","info":"child.disconnect()","kind":"f"},{"word":"kill","info":"child.kill([signal])","kind":"f"},{"word":"pid","kind":"m","info":" "},{"word":"send","info":"child.send(message, [sendHandle])","kind":"f"},{"word":"stderr","kind":"m","info":" "},{"word":"stdin","kind":"m","info":" "},{"word":"stdout","kind":"m","info":" "}]}},"cluster":{"props":[{"word":"disconnect","info":"cluster.disconnect([callback])","kind":"f"},{"word":"fork","info":"cluster.fork([env])","kind":"f"},{"word":"isMaster","kind":"m","info":" "},{"word":"isWorker","kind":"m","info":" "},{"word":"settings","kind":"m","info":" "},{"word":"setupMaster","info":"cluster.setupMaster([settings])","kind":"f"},{"word":"worker","kind":"m","info":" "},{"word":"Worker","kind":"f","info":" "},{"word":"workers","kind":"m","info":" "}],"classes":{"Worker":[{"word":"destroy","info":"worker.destroy()","kind":"f"},{"word":"disconnect","info":"worker.disconnect()","kind":"f"},{"word":"id","kind":"m","info":" "},{"word":"process","kind":"m","info":" "},{"word":"send","info":"worker.send(message, [sendHandle])","kind":"f"},{"word":"suicide","kind":"m","info":" "}]}},"crypto":{"props":[{"word":"Cipher","kind":"f","info":" "},{"word":"createCipher","info":"crypto.createCipher(algorithm, password)","kind":"f"},{"word":"createCipheriv","info":"crypto.createCipheriv(algorithm, key, iv)","kind":"f"},{"word":"createCredentials","info":"crypto.createCredentials(details)","kind":"f"},{"word":"createDecipher","info":"crypto.createDecipher(algorithm, password)","kind":"f"},{"word":"createDecipheriv","info":"crypto.createDecipheriv(algorithm, key, iv)","kind":"f"},{"word":"createDiffieHellman","info":"crypto.createDiffieHellman(prime, [encoding])","kind":"f"},{"word":"createDiffieHellman","info":"crypto.createDiffieHellman(prime_length)","kind":"f"},{"word":"createHash","info":"crypto.createHash(algorithm)","kind":"f"},{"word":"createHmac","info":"crypto.createHmac(algorithm, key)","kind":"f"},{"word":"createSign","info":"crypto.createSign(algorithm)","kind":"f"},{"word":"createVerify","info":"crypto.createVerify(algorithm)","kind":"f"},{"word":"Decipher","kind":"f","info":" "},{"word":"DiffieHellman","kind":"f","info":" "},{"word":"getDiffieHellman","info":"crypto.getDiffieHellman(group_name)","kind":"f"},{"word":"Hash","kind":"f","info":" "},{"word":"Hmac","kind":"f","info":" "},{"word":"pbkdf2","info":"crypto.pbkdf2(password, salt, iterations, keylen, callback)","kind":"f"},{"word":"randomBytes","info":"crypto.randomBytes(size, [callback])","kind":"f"},{"word":"Signer","kind":"f","info":" "},{"word":"Verify","kind":"f","info":" "}],"classes":{"Hash":[{"word":"digest","info":"hash.digest([encoding])","kind":"f"},{"word":"update","info":"hash.update(data, [input_encoding])","kind":"f"}],"Hmac":[{"word":"digest","info":"hmac.digest([encoding])","kind":"f"},{"word":"update","info":"hmac.update(data)","kind":"f"}],"Cipher":[{"word":"final","info":"cipher.final([output_encoding])","kind":"f"},{"word":"setAutoPadding","info":"cipher.setAutoPadding(auto_padding=true)","kind":"f"},{"word":"update","info":"cipher.update(data, [input_encoding], [output_encoding])","kind":"f"}],"Decipher":[{"word":"final","info":"decipher.final([output_encoding])","kind":"f"},{"word":"setAutoPadding","info":"decipher.setAutoPadding(auto_padding=true)","kind":"f"},{"word":"update","info":"decipher.update(data, [input_encoding], [output_encoding])","kind":"f"}],"Signer":[{"word":"sign","info":"signer.sign(private_key, [output_format])","kind":"f"},{"word":"update","info":"signer.update(data)","kind":"f"}],"Verify":[{"word":"update","info":"verifier.update(data)","kind":"f"},{"word":"verify","info":"verifier.verify(object, signature, [signature_format])","kind":"f"}],"DiffieHellman":[{"word":"computeSecret","info":"diffieHellman.computeSecret(other_public_key, [input_encoding], [output_encoding])","kind":"f"},{"word":"generateKeys","info":"diffieHellman.generateKeys([encoding])","kind":"f"},{"word":"getGenerator","info":"diffieHellman.getGenerator([encoding])","kind":"f"},{"word":"getPrime","info":"diffieHellman.getPrime([encoding])","kind":"f"},{"word":"getPrivateKey","info":"diffieHellman.getPrivateKey([encoding])","kind":"f"},{"word":"getPublicKey","info":"diffieHellman.getPublicKey([encoding])","kind":"f"},{"word":"setPrivateKey","info":"diffieHellman.setPrivateKey(public_key, [encoding])","kind":"f"},{"word":"setPublicKey","info":"diffieHellman.setPublicKey(public_key, [encoding])","kind":"f"}]}},"dgram":{"props":[{"word":"createSocket","info":"dgram.createSocket(type, [callback])","kind":"f"},{"word":"Socket","kind":"f","info":" "}],"classes":{"Socket":[{"word":"addMembership","info":"dgram.addMembership(multicastAddress, [multicastInterface])","kind":"f"},{"word":"address","info":"dgram.address()","kind":"f"},{"word":"bind","info":"dgram.bind(port, [address])","kind":"f"},{"word":"close","info":"dgram.close()","kind":"f"},{"word":"dropMembership","info":"dgram.dropMembership(multicastAddress, [multicastInterface])","kind":"f"},{"word":"send","info":"dgram.send(buf, offset, length, port, address, [callback])","kind":"f"},{"word":"setBroadcast","info":"dgram.setBroadcast(flag)","kind":"f"},{"word":"setMulticastLoopback","info":"dgram.setMulticastLoopback(flag)","kind":"f"},{"word":"setMulticastTTL","info":"dgram.setMulticastTTL(ttl)","kind":"f"},{"word":"setTTL","info":"dgram.setTTL(ttl)","kind":"f"}]}},"dns":{"props":[{"word":"lookup","info":"dns.lookup(domain, [family], callback)","kind":"f"},{"word":"resolve","info":"dns.resolve(domain, [rrtype], callback)","kind":"f"},{"word":"resolve4","info":"dns.resolve4(domain, callback)","kind":"f"},{"word":"resolve6","info":"dns.resolve6(domain, callback)","kind":"f"},{"word":"resolveCname","info":"dns.resolveCname(domain, callback)","kind":"f"},{"word":"resolveMx","info":"dns.resolveMx(domain, callback)","kind":"f"},{"word":"resolveNs","info":"dns.resolveNs(domain, callback)","kind":"f"},{"word":"resolveSrv","info":"dns.resolveSrv(domain, callback)","kind":"f"},{"word":"resolveTxt","info":"dns.resolveTxt(domain, callback)","kind":"f"},{"word":"reverse","info":"dns.reverse(ip, callback)","kind":"f"}],"classes":{}},"domain":{"props":[{"word":"create","info":"domain.create()","kind":"f"},{"word":"Domain","kind":"f","info":" "}],"classes":{"Domain":[{"word":"add","info":"domain.add(emitter)","kind":"f"},{"word":"bind","info":"domain.bind(callback)","kind":"f"},{"word":"dispose","info":"domain.dispose()","kind":"f"},{"word":"intercept","info":"domain.intercept(callback)","kind":"f"},{"word":"members","kind":"m","info":" "},{"word":"remove","info":"domain.remove(emitter)","kind":"f"},{"word":"run","info":"domain.run(fn)","kind":"f"}]}},"events":{"props":[{"word":"EventEmitter","kind":"f","info":" "}],"classes":{"EventEmitter":[{"word":"addListener","info":"emitter.addListener(event, listener)","kind":"f"},{"word":"emit","info":"emitter.emit(event, [arg1], [arg2], [...])","kind":"f"},{"word":"listeners","info":"emitter.listeners(event)","kind":"f"},{"word":"on","info":"emitter.on(event, listener)","kind":"f"},{"word":"once","info":"emitter.once(event, listener)","kind":"f"},{"word":"removeAllListeners","info":"emitter.removeAllListeners([event])","kind":"f"},{"word":"removeListener","info":"emitter.removeListener(event, listener)","kind":"f"},{"word":"setMaxListeners","info":"emitter.setMaxListeners(n)","kind":"f"}]}},"fs":{"props":[{"word":"appendFile","info":"fs.appendFile(filename, data, encoding='utf8', [callback])","kind":"f"},{"word":"appendFileSync","info":"fs.appendFileSync(filename, data, encoding='utf8')","kind":"f"},{"word":"chmod","info":"fs.chmod(path, mode, [callback])","kind":"f"},{"word":"chmodSync","info":"fs.chmodSync(path, mode)","kind":"f"},{"word":"chown","info":"fs.chown(path, uid, gid, [callback])","kind":"f"},{"word":"chownSync","info":"fs.chownSync(path, uid, gid)","kind":"f"},{"word":"close","info":"fs.close(fd, [callback])","kind":"f"},{"word":"closeSync","info":"fs.closeSync(fd)","kind":"f"},{"word":"createReadStream","info":"fs.createReadStream(path, [options])","kind":"f"},{"word":"createWriteStream","info":"fs.createWriteStream(path, [options])","kind":"f"},{"word":"exists","info":"fs.exists(path, [callback])","kind":"f"},{"word":"existsSync","info":"fs.existsSync(path)","kind":"f"},{"word":"fchmod","info":"fs.fchmod(fd, mode, [callback])","kind":"f"},{"word":"fchmodSync","info":"fs.fchmodSync(fd, mode)","kind":"f"},{"word":"fchown","info":"fs.fchown(fd, uid, gid, [callback])","kind":"f"},{"word":"fchownSync","info":"fs.fchownSync(fd, uid, gid)","kind":"f"},{"word":"fstat","info":"fs.fstat(fd, [callback])","kind":"f"},{"word":"fstatSync","info":"fs.fstatSync(fd)","kind":"f"},{"word":"FSWatcher","kind":"f","info":" "},{"word":"fsync","info":"fs.fsync(fd, [callback])","kind":"f"},{"word":"fsyncSync","info":"fs.fsyncSync(fd)","kind":"f"},{"word":"futimes","info":"fs.futimes(fd, atime, mtime, [callback])","kind":"f"},{"word":"futimesSync","info":"fs.futimesSync(fd, atime, mtime)","kind":"f"},{"word":"lchmod","info":"fs.lchmod(path, mode, [callback])","kind":"f"},{"word":"lchmodSync","info":"fs.lchmodSync(path, mode)","kind":"f"},{"word":"lchown","info":"fs.lchown(path, uid, gid, [callback])","kind":"f"},{"word":"lchownSync","info":"fs.lchownSync(path, uid, gid)","kind":"f"},{"word":"link","info":"fs.link(srcpath, dstpath, [callback])","kind":"f"},{"word":"linkSync","info":"fs.linkSync(srcpath, dstpath)","kind":"f"},{"word":"lstat","info":"fs.lstat(path, [callback])","kind":"f"},{"word":"lstatSync","info":"fs.lstatSync(path)","kind":"f"},{"word":"mkdir","info":"fs.mkdir(path, [mode], [callback])","kind":"f"},{"word":"mkdirSync","info":"fs.mkdirSync(path, [mode])","kind":"f"},{"word":"open","info":"fs.open(path, flags, [mode], [callback])","kind":"f"},{"word":"openSync","info":"fs.openSync(path, flags, [mode])","kind":"f"},{"word":"read","info":"fs.read(fd, buffer, offset, length, position, [callback])","kind":"f"},{"word":"readdir","info":"fs.readdir(path, [callback])","kind":"f"},{"word":"readdirSync","info":"fs.readdirSync(path)","kind":"f"},{"word":"readFile","info":"fs.readFile(filename, [encoding], [callback])","kind":"f"},{"word":"readFileSync","info":"fs.readFileSync(filename, [encoding])","kind":"f"},{"word":"readlink","info":"fs.readlink(path, [callback])","kind":"f"},{"word":"readlinkSync","info":"fs.readlinkSync(path)","kind":"f"},{"word":"ReadStream","kind":"f","info":" "},{"word":"readSync","info":"fs.readSync(fd, buffer, offset, length, position)","kind":"f"},{"word":"realpath","info":"fs.realpath(path, [cache], callback)","kind":"f"},{"word":"realpathSync","info":"fs.realpathSync(path, [cache])","kind":"f"},{"word":"rename","info":"fs.rename(oldPath, newPath, [callback])","kind":"f"},{"word":"renameSync","info":"fs.renameSync(oldPath, newPath)","kind":"f"},{"word":"rmdir","info":"fs.rmdir(path, [callback])","kind":"f"},{"word":"rmdirSync","info":"fs.rmdirSync(path)","kind":"f"},{"word":"stat","info":"fs.stat(path, [callback])","kind":"f"},{"word":"Stats","kind":"f","info":" "},{"word":"statSync","info":"fs.statSync(path)","kind":"f"},{"word":"symlink","info":"fs.symlink(srcpath, dstpath, [type], [callback])","kind":"f"},{"word":"symlinkSync","info":"fs.symlinkSync(srcpath, dstpath, [type])","kind":"f"},{"word":"truncate","info":"fs.truncate(fd, len, [callback])","kind":"f"},{"word":"truncateSync","info":"fs.truncateSync(fd, len)","kind":"f"},{"word":"unlink","info":"fs.unlink(path, [callback])","kind":"f"},{"word":"unlinkSync","info":"fs.unlinkSync(path)","kind":"f"},{"word":"unwatchFile","info":"fs.unwatchFile(filename, [listener])","kind":"f"},{"word":"utimes","info":"fs.utimes(path, atime, mtime, [callback])","kind":"f"},{"word":"utimesSync","info":"fs.utimesSync(path, atime, mtime)","kind":"f"},{"word":"watch","info":"fs.watch(filename, [options], [listener])","kind":"f"},{"word":"watchFile","info":"fs.watchFile(filename, [options], listener)","kind":"f"},{"word":"write","info":"fs.write(fd, buffer, offset, length, position, [callback])","kind":"f"},{"word":"writeFile","info":"fs.writeFile(filename, data, [encoding], [callback])","kind":"f"},{"word":"writeFileSync","info":"fs.writeFileSync(filename, data, [encoding])","kind":"f"},{"word":"WriteStream","kind":"m","info":" "},{"word":"writeSync","info":"fs.writeSync(fd, buffer, offset, length, position)","kind":"f"}],"classes":{"Stats":[],"ReadStream":[],"FSWatcher":[{"word":"close","info":"watcher.close()","kind":"f"}]}},"http":{"props":[{"word":"Agent","kind":"f","info":" "},{"word":"ClientRequest","kind":"f","info":" "},{"word":"ClientResponse","kind":"m","info":" "},{"word":"createClient","info":"http.createClient([port], [host])","kind":"f"},{"word":"createServer","info":"http.createServer([requestListener])","kind":"f"},{"word":"get","info":"http.get(options, callback)","kind":"f"},{"word":"globalAgent","kind":"m","info":" "},{"word":"request","info":"http.request(options, callback)","kind":"f"},{"word":"Server","kind":"f","info":" "},{"word":"ServerRequest","kind":"f","info":" "},{"word":"ServerResponse","kind":"f","info":" "},{"word":"STATUS_CODES","kind":"m","info":" "}],"classes":{"Server":[{"word":"close","info":"server.close([callback])","kind":"f"},{"word":"listen","info":"server.listen(port, [hostname], [backlog], [callback])","kind":"f"},{"word":"listen","info":"server.listen(path, [callback])","kind":"f"},{"word":"listen","info":"server.listen(handle, [callback])","kind":"f"},{"word":"maxHeadersCount","kind":"m","info":" "}],"ServerRequest":[{"word":"connection","kind":"m","info":" "},{"word":"headers","kind":"m","info":" "},{"word":"httpVersion","kind":"m","info":" "},{"word":"method","kind":"m","info":" "},{"word":"pause","info":"request.pause()","kind":"f"},{"word":"resume","info":"request.resume()","kind":"f"},{"word":"setEncoding","info":"request.setEncoding([encoding])","kind":"f"},{"word":"trailers","kind":"m","info":" "},{"word":"url","kind":"m","info":" "}],"ServerResponse":[{"word":"addTrailers","info":"response.addTrailers(headers)","kind":"f"},{"word":"end","info":"response.end([data], [encoding])","kind":"f"},{"word":"getHeader","info":"response.getHeader(name)","kind":"f"},{"word":"removeHeader","info":"response.removeHeader(name)","kind":"f"},{"word":"sendDate","kind":"m","info":" "},{"word":"setHeader","info":"response.setHeader(name, value)","kind":"f"},{"word":"statusCode","kind":"m","info":" "},{"word":"write","info":"response.write(chunk, [encoding])","kind":"f"},{"word":"writeContinue","info":"response.writeContinue()","kind":"f"},{"word":"writeHead","info":"response.writeHead(statusCode, [reasonPhrase], [headers])","kind":"f"}],"Agent":[{"word":"maxSockets","kind":"m","info":" "},{"word":"requests","kind":"m","info":" "},{"word":"sockets","kind":"m","info":" "}],"ClientRequest":[{"word":"abort","info":"request.abort()","kind":"f"},{"word":"end","info":"request.end([data], [encoding])","kind":"f"},{"word":"setNoDelay","info":"request.setNoDelay([noDelay])","kind":"f"},{"word":"setSocketKeepAlive","info":"request.setSocketKeepAlive([enable], [initialDelay])","kind":"f"},{"word":"setTimeout","info":"request.setTimeout(timeout, [callback])","kind":"f"},{"word":"write","info":"request.write(chunk, [encoding])","kind":"f"}]}},"https":{"props":[{"word":"Agent","kind":"f","info":" "},{"word":"createServer","info":"https.createServer(options, [requestListener])","kind":"f"},{"word":"get","info":"https.get(options, callback)","kind":"f"},{"word":"globalAgent","kind":"m","info":" "},{"word":"request","info":"https.request(options, callback)","kind":"f"},{"word":"Server","kind":"f","info":" "}],"classes":{"Server":[],"Agent":[]}},"net":{"props":[{"word":"connect","info":"net.connect(port, [host], [connectListener])","kind":"f"},{"word":"connect","info":"net.connect(path, [connectListener])","kind":"f"},{"word":"connect","info":"net.connect(options, [connectionListener])","kind":"f"},{"word":"createConnection","info":"net.createConnection(path, [connectListener])","kind":"f"},{"word":"createConnection","info":"net.createConnection(options, [connectionListener])","kind":"f"},{"word":"createConnection","info":"net.createConnection(port, [host], [connectListener])","kind":"f"},{"word":"createServer","info":"net.createServer([options], [connectionListener])","kind":"f"},{"word":"isIP","info":"net.isIP(input)","kind":"f"},{"word":"isIPv4","info":"net.isIPv4(input)","kind":"f"},{"word":"isIPv6","info":"net.isIPv6(input)","kind":"f"},{"word":"Server","kind":"f","info":" "},{"word":"Socket","kind":"f","info":" "}],"classes":{"Server":[{"word":"address","info":"server.address()","kind":"f"},{"word":"close","info":"server.close([callback])","kind":"f"},{"word":"connections","kind":"m","info":" "},{"word":"listen","info":"server.listen(port, [host], [backlog], [callback])","kind":"f"},{"word":"listen","info":"server.listen(path, [callback])","kind":"f"},{"word":"listen","info":"server.listen(handle, [callback])","kind":"f"},{"word":"maxConnections","kind":"m","info":" "}],"Socket":[{"word":"address","info":"socket.address()","kind":"f"},{"word":"bufferSize","kind":"m","info":" "},{"word":"bytesRead","kind":"m","info":" "},{"word":"bytesWritten","kind":"m","info":" "},{"word":"connect","info":"socket.connect(port, [host], [connectListener])","kind":"f"},{"word":"connect","info":"socket.connect(path, [connectListener])","kind":"f"},{"word":"destroy","info":"socket.destroy()","kind":"f"},{"word":"end","info":"socket.end([data], [encoding])","kind":"f"},{"word":"pause","info":"socket.pause()","kind":"f"},{"word":"remoteAddress","kind":"m","info":" "},{"word":"remotePort","kind":"m","info":" "},{"word":"resume","info":"socket.resume()","kind":"f"},{"word":"setEncoding","info":"socket.setEncoding([encoding])","kind":"f"},{"word":"setKeepAlive","info":"socket.setKeepAlive([enable], [initialDelay])","kind":"f"},{"word":"setNoDelay","info":"socket.setNoDelay([noDelay])","kind":"f"},{"word":"setTimeout","info":"socket.setTimeout(timeout, [callback])","kind":"f"},{"word":"Socket","info":"new net.Socket([options])","kind":"f"},{"word":"write","info":"socket.write(data, [encoding], [callback])","kind":"f"}]}},"os":{"props":[{"word":"arch","info":"os.arch()","kind":"f"},{"word":"cpus","info":"os.cpus()","kind":"f"},{"word":"EOL","kind":"m","info":" "},{"word":"freemem","info":"os.freemem()","kind":"f"},{"word":"hostname","info":"os.hostname()","kind":"f"},{"word":"loadavg","info":"os.loadavg()","kind":"f"},{"word":"networkInterfaces","info":"os.networkInterfaces()","kind":"f"},{"word":"platform","info":"os.platform()","kind":"f"},{"word":"release","info":"os.release()","kind":"f"},{"word":"tmpDir","info":"os.tmpDir()","kind":"f"},{"word":"totalmem","info":"os.totalmem()","kind":"f"},{"word":"type","info":"os.type()","kind":"f"},{"word":"uptime","info":"os.uptime()","kind":"f"}],"classes":{}},"path":{"props":[{"word":"basename","info":"path.basename(p, [ext])","kind":"f"},{"word":"dirname","info":"path.dirname(p)","kind":"f"},{"word":"extname","info":"path.extname(p)","kind":"f"},{"word":"join","info":"path.join([path1], [path2], [...])","kind":"f"},{"word":"normalize","info":"path.normalize(p)","kind":"f"},{"word":"relative","info":"path.relative(from, to)","kind":"f"},{"word":"resolve","info":"path.resolve([from ...], to)","kind":"f"},{"word":"sep","kind":"m","info":" "}],"classes":{}},"punycode":{"props":[{"word":"decode","info":"punycode.decode(string)","kind":"f"},{"word":"encode","info":"punycode.encode(string)","kind":"f"},{"word":"toASCII","info":"punycode.toASCII(domain)","kind":"f"},{"word":"toUnicode","info":"punycode.toUnicode(domain)","kind":"f"},{"word":"ucs2","kind":"m","info":" "},{"word":"version","kind":"m","info":" "}],"classes":{}},"querystring":{"props":[{"word":"escape","kind":"m","info":" "},{"word":"parse","info":"querystring.parse(str, [sep], [eq], [options])","kind":"f"},{"word":"stringify","info":"querystring.stringify(obj, [sep], [eq])","kind":"f"},{"word":"unescape","kind":"m","info":" "}],"classes":{}},"readline":{"props":[{"word":"createInterface","info":"readline.createInterface(options)","kind":"f"},{"word":"Interface","kind":"f","info":" "}],"classes":{"Interface":[{"word":"close","info":"rl.close()","kind":"f"},{"word":"pause","info":"rl.pause()","kind":"f"},{"word":"prompt","info":"rl.prompt([preserveCursor])","kind":"f"},{"word":"question","info":"rl.question(query, callback)","kind":"f"},{"word":"resume","info":"rl.resume()","kind":"f"},{"word":"setPrompt","info":"rl.setPrompt(prompt, length)","kind":"f"},{"word":"write","info":"rl.write(data, [key])","kind":"f"}]}},"repl":{"props":[{"word":"start","info":"repl.start(options)","kind":"f"}],"classes":{}},"stream":{"props":[],"classes":{"Readable Stream":[{"word":"destroy","info":"stream.destroy()","kind":"f"},{"word":"pause","info":"stream.pause()","kind":"f"},{"word":"pipe","info":"stream.pipe(destination, [options])","kind":"f"},{"word":"readable","kind":"m","info":" "},{"word":"resume","info":"stream.resume()","kind":"f"},{"word":"setEncoding","info":"stream.setEncoding([encoding])","kind":"f"}],"Writable Stream":[{"word":"destroy","info":"stream.destroy()","kind":"f"},{"word":"destroySoon","info":"stream.destroySoon()","kind":"f"},{"word":"end","info":"stream.end()","kind":"f"},{"word":"end","info":"stream.end(string, encoding)","kind":"f"},{"word":"end","info":"stream.end(buffer)","kind":"f"},{"word":"writable","kind":"m","info":" "},{"word":"write","info":"stream.write(string, [encoding])","kind":"f"},{"word":"write","info":"stream.write(buffer)","kind":"f"}]}},"stringdecoder":{"props":[{"word":"StringDecoder","kind":"f","info":" "}],"classes":{"StringDecoder":[{"word":"write","info":"StringDecoder.write(buffer)","kind":"f"}]}},"timers":{"props":[{"word":"clearInterval","info":"clearInterval(intervalId)","kind":"f"},{"word":"clearTimeout","info":"clearTimeout(timeoutId)","kind":"f"},{"word":"setInterval","info":"setInterval(callback, delay, [arg], [...])","kind":"f"},{"word":"setTimeout","info":"setTimeout(callback, delay, [arg], [...])","kind":"f"}],"classes":{}},"tls":{"props":[{"word":"CleartextStream","kind":"f","info":" "},{"word":"connect","info":"tls.connect(options, [callback])","kind":"f"},{"word":"connect","info":"tls.connect(port, [host], [options], [callback])","kind":"f"},{"word":"createSecurePair","info":"tls.createSecurePair([credentials], [isServer], [requestCert], [rejectUnauthorized])","kind":"f"},{"word":"createServer","info":"tls.createServer(options, [secureConnectionListener])","kind":"f"},{"word":"SecurePair","kind":"f","info":" "},{"word":"Server","kind":"f","info":" "}],"classes":{"SecurePair":[],"Server":[{"word":"addContext","info":"server.addContext(hostname, credentials)","kind":"f"},{"word":"address","info":"server.address()","kind":"f"},{"word":"close","info":"server.close()","kind":"f"},{"word":"connections","kind":"m","info":" "},{"word":"listen","info":"server.listen(port, [host], [callback])","kind":"f"},{"word":"maxConnections","kind":"m","info":" "}],"CleartextStream":[{"word":"address","info":"cleartextStream.address()","kind":"f"},{"word":"authorizationError","kind":"m","info":" "},{"word":"authorized","kind":"m","info":" "},{"word":"getCipher","info":"cleartextStream.getCipher()","kind":"f"},{"word":"getPeerCertificate","info":"cleartextStream.getPeerCertificate()","kind":"f"},{"word":"remoteAddress","kind":"m","info":" "},{"word":"remotePort","kind":"m","info":" "}]}},"tty":{"props":[{"word":"isatty","info":"tty.isatty(fd)","kind":"f"},{"word":"ReadStream","kind":"f","info":" "},{"word":"setRawMode","info":"tty.setRawMode(mode)","kind":"f"}],"classes":{"ReadStream":[{"word":"isRaw","kind":"m","info":" "},{"word":"setRawMode","info":"rs.setRawMode(mode)","kind":"f"}]}},"url":{"props":[{"word":"format","info":"url.format(urlObj)","kind":"f"},{"word":"parse","info":"url.parse(urlStr, [parseQueryString], [slashesDenoteHost])","kind":"f"},{"word":"resolve","info":"url.resolve(from, to)","kind":"f"}],"classes":{}},"util":{"props":[{"word":"debug","info":"util.debug(string)","kind":"f"},{"word":"error","info":"util.error([...])","kind":"f"},{"word":"format","info":"util.format(format, [...])","kind":"f"},{"word":"inherits","info":"util.inherits(constructor, superConstructor)","kind":"f"},{"word":"inspect","info":"util.inspect(object, [showHidden], [depth], [colors])","kind":"f"},{"word":"isArray","info":"util.isArray(object)","kind":"f"},{"word":"isDate","info":"util.isDate(object)","kind":"f"},{"word":"isError","info":"util.isError(object)","kind":"f"},{"word":"isRegExp","info":"util.isRegExp(object)","kind":"f"},{"word":"log","info":"util.log(string)","kind":"f"},{"word":"print","info":"util.print([...])","kind":"f"},{"word":"pump","info":"util.pump(readableStream, writableStream, [callback])","kind":"f"},{"word":"puts","info":"util.puts([...])","kind":"f"}],"classes":{}},"vm":{"props":[{"word":"createContext","info":"vm.createContext([initSandbox])","kind":"f"},{"word":"createScript","info":"vm.createScript(code, [filename])","kind":"f"},{"word":"runInContext","info":"vm.runInContext(code, context, [filename])","kind":"f"},{"word":"runInNewContext","info":"vm.runInNewContext(code, [sandbox], [filename])","kind":"f"},{"word":"runInThisContext","info":"vm.runInThisContext(code, [filename])","kind":"f"},{"word":"Script","kind":"f","info":" "}],"classes":{"Script":[{"word":"runInNewContext","info":"script.runInNewContext([sandbox])","kind":"f"},{"word":"runInThisContext","info":"script.runInThisContext()","kind":"f"}]}},"zlib":{"props":[{"word":"createDeflate","info":"zlib.createDeflate([options])","kind":"f"},{"word":"createDeflateRaw","info":"zlib.createDeflateRaw([options])","kind":"f"},{"word":"createGunzip","info":"zlib.createGunzip([options])","kind":"f"},{"word":"createGzip","info":"zlib.createGzip([options])","kind":"f"},{"word":"createInflate","info":"zlib.createInflate([options])","kind":"f"},{"word":"createInflateRaw","info":"zlib.createInflateRaw([options])","kind":"f"},{"word":"createUnzip","info":"zlib.createUnzip([options])","kind":"f"},{"word":"deflate","info":"zlib.deflate(buf, callback)","kind":"f"},{"word":"Deflate","kind":"f","info":" "},{"word":"deflateRaw","info":"zlib.deflateRaw(buf, callback)","kind":"f"},{"word":"DeflateRaw","kind":"f","info":" "},{"word":"gunzip","info":"zlib.gunzip(buf, callback)","kind":"f"},{"word":"Gunzip","kind":"f","info":" "},{"word":"Gzip","kind":"f","info":" "},{"word":"gzip","info":"zlib.gzip(buf, callback)","kind":"f"},{"word":"inflate","info":"zlib.inflate(buf, callback)","kind":"f"},{"word":"Inflate","kind":"f","info":" "},{"word":"inflateRaw","info":"zlib.inflateRaw(buf, callback)","kind":"f"},{"word":"InflateRaw","kind":"f","info":" "},{"word":"unzip","info":"zlib.unzip(buf, callback)","kind":"f"},{"word":"Unzip","kind":"f","info":" "}],"classes":{"Gzip":[],"Gunzip":[],"Deflate":[],"Inflate":[],"DeflateRaw":[],"InflateRaw":[],"Unzip":[]}}},"vars":[{"word":"__dirname","kind":"v","info":" "},{"word":"__filename","kind":"v","info":" "},{"word":"Buffer","kind":"v","info":" "},{"word":"clearInterval","info":"clearInterval(t)","kind":"f"},{"word":"console","kind":"v","info":" "},{"word":"console","kind":"v","info":" "},{"word":"exports","kind":"v","info":" "},{"word":"global","kind":"v","info":" "},{"word":"module","kind":"v","info":" "},{"word":"process","kind":"v","info":" "},{"word":"process","kind":"v","info":" "},{"word":"require","info":"require()","kind":"f"}]} -------------------------------------------------------------------------------- /after/autoload/nodejscomplete.vim: -------------------------------------------------------------------------------- 1 | " Vim completion script 2 | " Language: Javascript(node) 3 | " Maintainer: Lin Zhang ( myhere.2009 AT gmail DOT com ) 4 | " Last Change: 2012-8-18 1:32:00 5 | 6 | " save current dir 7 | let s:nodejs_doc_file = expand(':p:h') . '/nodejs-doc.vim' 8 | 9 | let s:js_varname_reg = '[$a-zA-Z_][$a-zA-Z0-9_]*' 10 | 11 | let s:js_obj_declare_type = { 12 | \ 'global': 0, 13 | \ 'require': 1, 14 | \ 'constructor': 2 15 | \ } 16 | 17 | " settings 18 | " default setting 19 | let s:nodejs_complete_config = { 20 | \ 'js_compl_fn': 'javascriptcomplete#CompleteJS', 21 | \ 'max_node_compl_len': 15 22 | \} 23 | if exists('g:nodejs_complete_config') && type(g:nodejs_complete_config) == type({}) 24 | let g:nodejs_complete_config = extend(s:nodejs_complete_config, g:nodejs_complete_config) 25 | else 26 | let g:nodejs_complete_config = s:nodejs_complete_config 27 | endif 28 | unlet s:nodejs_complete_config 29 | 30 | function! nodejscomplete#CompleteJS(findstart, base)"{{{ 31 | if a:findstart 32 | try 33 | let JS_compl_fn = function(g:nodejs_complete_config.js_compl_fn) 34 | let start = call(JS_compl_fn, [a:findstart, a:base]) 35 | catch /.*/ 36 | echo '!!!!!!!!!!function [' . g:nodejs_complete_config.js_compl_fn . '] is not exists!' 37 | endtry 38 | 39 | "Decho 'start: ' . start 40 | " str[start: end] end 为负数时从末尾截取 41 | if start - 1 < 0 42 | let b:nodecompl_context = '' 43 | else 44 | let line = getline('.') 45 | let b:nodecompl_context = line[:start-1] 46 | endif 47 | return start 48 | else 49 | let posi = getpos('.') 50 | let result = s:getNodeComplete(a:base, b:nodecompl_context) 51 | " the function above will move the cursor 52 | " so we restore the cursor position 53 | " JS_compl_fn below may rely on the cursor position 54 | call setpos('.', posi) 55 | 56 | "Decho 'nodecomplete: ' . string(result) 57 | unlet b:nodecompl_context 58 | 59 | let nodejs_compl = result.complete 60 | " limit nodejs complete count 61 | if g:nodejs_complete_config.max_node_compl_len != 0 62 | let nodejs_compl = nodejs_compl[0 : g:nodejs_complete_config.max_node_compl_len - 1] 63 | endif 64 | 65 | if result.continue 66 | try 67 | let JS_compl_fn = function(g:nodejs_complete_config.js_compl_fn) 68 | let js_compl = call(JS_compl_fn, [a:findstart, a:base]) 69 | catch /.*/ 70 | echo '!!!!!!!!!!function [' . g:nodejs_complete_config.js_compl_fn . '] is not exists!' 71 | endtry 72 | 73 | "Decho 'js_compl: ' . string(js_compl) 74 | 75 | return nodejs_compl + js_compl 76 | else 77 | return nodejs_compl 78 | endif 79 | endif 80 | endfunction"}}} 81 | 82 | " get complete 83 | function! s:getNodeComplete(base, context)"{{{ 84 | "Decho 'base: ' . a:base 85 | "Decho 'context: ' . a:context 86 | 87 | " TODO: 排除 module.property.h 情况 88 | let mod_reg = '\(' . s:js_varname_reg . '\)\s*\(\.\|\[\s*["'']\?\)\s*$' 89 | let matched = matchlist(a:context, mod_reg) 90 | "Decho 'mod_reg: ' . mod_reg 91 | 92 | " 模块属性补全 93 | if len(matched) > 0 94 | let var_name = matched[1] 95 | let operator = matched[2] 96 | let position = [line('.'), len(a:context) - len(matched[0])] 97 | "Decho 'var_name: ' . var_name . ' ; operator: ' . operator 98 | let declare_info = s:getObjDeclareInfo(var_name, position) 99 | "Decho 'mod_info: ' . string(declare_info) . '; compl_prefix: ' . a:base 100 | 101 | let compl_list = s:getObjectComplete(declare_info.type, declare_info.value, 102 | \ a:base, operator) 103 | 104 | let ret = { 105 | \ 'complete': compl_list 106 | \ } 107 | if len(compl_list) == 0 108 | let ret.continue = 1 109 | else 110 | let ret.continue = 0 111 | endif 112 | " 全局补全 113 | else 114 | "Decho 'var complete' 115 | let ret = { 116 | \ 'continue': 1, 117 | \ 'complete': s:getVariableComplete(a:context, a:base) 118 | \ } 119 | endif 120 | 121 | return ret 122 | endfunction"}}} 123 | 124 | function! s:getObjDeclareInfo(var_name, position)"{{{ 125 | let position = s:fixPosition(a:position) 126 | "Decho 'position: ' . string(position) 127 | 128 | if position[0] <= 0 129 | return { 130 | \ 'type': s:js_obj_declare_type.global, 131 | \ 'value': a:var_name 132 | \} 133 | endif 134 | 135 | let decl_stmt_prefix_reg = '\<' . a:var_name . '\_s*=\_s*' 136 | " search backward, don't move the cursor, don't wrap 137 | call cursor(position[0], position[1]) 138 | let begin_position = searchpos(decl_stmt_prefix_reg, 'bnW') 139 | if begin_position[0] == 0 140 | return { 141 | \ 'type': s:js_obj_declare_type.global, 142 | \ 'value': a:var_name 143 | \} 144 | endif 145 | 146 | " make sure it's not in comments... 147 | if !s:isDeclaration(begin_position) 148 | return s:getObjDeclareInfo(a:var_name, begin_position) 149 | endif 150 | 151 | let lines = s:getLinesInRange(begin_position, position) 152 | "Decho 'lines: ' . string(lines) 153 | let code = join(lines, "\n") 154 | 155 | " require 156 | let require_stmt_reg = decl_stmt_prefix_reg . 157 | \ 'require\_s*(\_s*\([''"]\)\zs[^)''"]\+\ze\1\_s*)' 158 | let matched = matchstr(code, require_stmt_reg) 159 | if len(matched) 160 | return { 161 | \ 'type': s:js_obj_declare_type.require, 162 | \ 'value': matched 163 | \} 164 | endif 165 | 166 | " new 167 | let new_stmt_reg = decl_stmt_prefix_reg . 168 | \ 'new\_s\+\zs' . s:js_varname_reg . '\%(\_s*\.\_s*' . 169 | \ s:js_varname_reg . '\)*\ze' 170 | let matched = matchstr(code, new_stmt_reg) 171 | if len(matched) 172 | let parts = split(matched, '\.') 173 | return { 174 | \ 'type': s:js_obj_declare_type.constructor, 175 | \ 'value': [s:getObjDeclareInfo(parts[0], begin_position), join(parts[1:], '.')] 176 | \} 177 | endif 178 | 179 | " new 180 | " var emitter = new (require('events')).EventEmitter; 181 | let new_stmt_reg = decl_stmt_prefix_reg . 182 | \ 'new\_s\+' . 183 | \ '(\_s*require\_s*(\([''"]\)\(' . s:js_varname_reg . '\)\1\_s*)\_s*)' . 184 | \ '\_s*' . 185 | \ '\(\%(\.' . s:js_varname_reg . '\)\+\)' 186 | 187 | let matchedList = matchlist(code, new_stmt_reg) 188 | if (len(matchedList)) 189 | "Decho 'new stmt: ' . string(matchedList) 190 | let props = [matchedList[3][1:]] + matchedList[4:] 191 | "Decho 'props: ' . string(props) 192 | return { 193 | \ 'type': s:js_obj_declare_type.constructor, 194 | \ 'value': [ 195 | \ { 196 | \ 'type': s:js_obj_declare_type.require, 197 | \ 'value': matchedList[2] 198 | \ }, 199 | \ join(props, '') 200 | \ ] 201 | \} 202 | endif 203 | 204 | 205 | " assign 206 | let assign_stmt_reg = decl_stmt_prefix_reg . '\zs' . s:js_varname_reg . '\ze' 207 | let matched = matchstr(code, assign_stmt_reg) 208 | if len(matched) 209 | return s:getObjDeclareInfo(a:var_name, begin_position) 210 | endif 211 | 212 | " continure to search backward 213 | return s:getObjDeclareInfo(a:var_name, begin_position) 214 | endfunction"}}} 215 | 216 | function! s:isDeclaration(position)"{{{ 217 | let [line_num, col_num] = a:position 218 | " syntaxName @see: $VIMRUNTIME/syntax/javascript.vim 219 | let syntaxName = synIDattr(synID(line_num, col_num, 0), 'name') 220 | if syntaxName =~ '^javaScript\%(Comment\|LineComment\|String\|RegexpString\)' 221 | return 0 222 | else 223 | return 1 224 | endif 225 | endfunction"}}} 226 | 227 | " only complete nodejs's module info 228 | function! s:getObjectComplete(type, mod_name, prop_name, operator)"{{{ 229 | " new 230 | if a:type == s:js_obj_declare_type.constructor 231 | let list = s:getConstructedObjectComplete(a:mod_name) 232 | " require and global 233 | else 234 | let list = s:getNodeDocList(a:type, a:mod_name, 'props') 235 | endif 236 | 237 | if !len(list) 238 | return list 239 | else 240 | " no prop_name suplied 241 | if (len(a:prop_name) == 0) 242 | let ret = list 243 | else 244 | let ret = s:smartFilter(list, 'v:val["word"]', a:prop_name) 245 | endif 246 | 247 | let [prefix, suffix] = ['', ''] 248 | let matched = matchlist(a:operator, '\[\s*\(["'']\)\?') 249 | "Decho 'operator_matched: ' . string(matched) 250 | if len(matched) 251 | if len(matched[1]) 252 | let [prefix, suffix] = ['', matched[1] . ']'] 253 | else 254 | let [prefix, suffix] = ['''', ''']'] 255 | endif 256 | endif 257 | 258 | for item in ret 259 | let item.word = prefix . item.word . suffix 260 | endfor 261 | call s:addFunctionParen(ret) 262 | 263 | return ret 264 | endif 265 | endfunction"}}} 266 | 267 | function! s:getVariableComplete(context, var_name)"{{{ 268 | "Decho 'var_name: ' . a:var_name 269 | 270 | " complete require's arguments 271 | let matched = matchlist(a:context, 'require\s*(\s*\%(\([''"]\)\(\.\{1,2}.*\)\=\)\=$') 272 | if (len(matched) > 0) 273 | "Decho 'require complete: ' . string(matched) 274 | 275 | if (len(matched[2]) > 0) " complete -> require('./ 276 | let mod_names = s:getModuleInCurrentDir(a:context, a:var_name, matched) 277 | else 278 | let mod_names = s:getModuleNames() 279 | 280 | if (len(matched[1]) == 0) " complete -> require( 281 | call map(mod_names, '"''" . v:val . "'')"') 282 | elseif (len(a:var_name) == 0) " complete -> require(' 283 | call map(mod_names, 'v:val . "' . escape(matched[1], '"') . ')"') 284 | else " complete -> require('ti 285 | let mod_names = filter(mod_names, 'v:val =~# "^' . a:var_name . '"') 286 | call map(mod_names, 'v:val . "' . escape(matched[1], '"') . ')"') 287 | endif 288 | endif 289 | 290 | return mod_names 291 | endif 292 | 293 | " complete global variables 294 | let vars = [] 295 | if (len(a:var_name) == 0) 296 | return vars 297 | endif 298 | 299 | call s:loadNodeDocData() 300 | 301 | if (has_key(g:nodejs_complete_data, 'vars')) 302 | let vars = deepcopy(g:nodejs_complete_data.vars) 303 | endif 304 | 305 | let ret = s:smartFilter(vars, 'v:val["word"]', a:var_name) 306 | 307 | call s:addFunctionParen(ret) 308 | 309 | return ret 310 | endfunction"}}} 311 | 312 | function! s:getModuleInCurrentDir(context, var_name, matched)"{{{ 313 | let mod_names = [] 314 | let path = a:matched[2] . a:var_name 315 | 316 | " typed as require('.. 317 | " complete as require('../ 318 | " cause the latter one is more common 319 | let compl_prefix = '' 320 | if (path =~# '\.\.$') 321 | let compl_prefix = '/' 322 | let path = path . compl_prefix 323 | endif 324 | 325 | "Decho 'path: ' . path 326 | 327 | let current_dir = expand('%:p:h') 328 | let glob_path = current_dir . '/' . path . '*' 329 | let files = s:fuzglob(glob_path) 330 | "Decho 'glob: ' . glob_path 331 | "Decho 'current dir files: ' . string(files) 332 | for file in files 333 | " not '.' and '..' 334 | if ((isdirectory(file) ) || file =~? '\.json$\|\.js$') 335 | let mod_file = file 336 | " directory 337 | if (file !~? '\.json$\|\.js$') 338 | let mod_file = mod_file . '/' 339 | endif 340 | 341 | " get complete word 342 | let mod_file = substitute(mod_file, '\', '/', 'g') 343 | let start = len(glob_path) - 1 " substract character '*' 344 | let compl_infix = strpart(mod_file, start) 345 | "Decho 'idx: ' . start 346 | "Decho 'compl_infix: ' . compl_infix 347 | "Decho 'relative file: ' . mod_file 348 | 349 | let mod_name = compl_prefix . a:var_name . compl_infix 350 | " file module, not a directory 351 | if (compl_infix !~# '/$') 352 | let mod_name = mod_name . a:matched[1] . ')' 353 | endif 354 | 355 | "Decho 'mod_name: ' . mod_name 356 | call add(mod_names, mod_name) 357 | endif 358 | endfor 359 | 360 | "Decho 'relative path: ' . path 361 | 362 | return mod_names 363 | endfunction"}}} 364 | 365 | function! s:getModuleNames()"{{{ 366 | call s:loadNodeDocData() 367 | 368 | let mod_names = [] 369 | 370 | " build-in module name 371 | if (has_key(g:nodejs_complete_data, 'modules')) 372 | let mod_names = keys(g:nodejs_complete_data.modules) 373 | endif 374 | 375 | 376 | " find module in 'module_dir' folder 377 | if (!exists('b:npm_module_names')) 378 | let current_dir = expand('%:p:h') 379 | 380 | let b:npm_module_names = s:getModuleNamesInNode_modulesFolder(current_dir) 381 | endif 382 | 383 | let mod_names = mod_names + b:npm_module_names 384 | 385 | return sort(mod_names) 386 | endfunction"}}} 387 | 388 | function! s:getModuleNamesInNode_modulesFolder(current_dir)"{{{ 389 | " ensure platform coincidence 390 | let base_dir = substitute(a:current_dir, '\', '/', 'g') 391 | "Decho 'base_dir: ' . base_dir 392 | 393 | let ret = [] 394 | 395 | let parts = split(base_dir, '/', 1) 396 | "Decho 'parts: ' . string(parts) 397 | let idx = 0 398 | let len = len(parts) 399 | let sub_parts = [] 400 | while idx < len 401 | let sub_parts = add(sub_parts, parts[idx]) 402 | let module_dir = join(sub_parts, '/') . '/node_modules' 403 | "Decho 'directory: ' . module_dir 404 | 405 | if (isdirectory(module_dir)) 406 | let files = s:fuzglob(module_dir . '/*') 407 | "Decho 'node_module files: ' . string(files) 408 | for file in files 409 | if (isdirectory(file) || file =~? '\.json$\|\.js$') 410 | let mod_name = matchstr(file, '[^/\\]\+$') 411 | let ret = add(ret, mod_name) 412 | endif 413 | endfor 414 | endif 415 | 416 | let idx = idx + 1 417 | endwhile 418 | 419 | "Decho 'npm modules: ' . string(ret) 420 | 421 | return ret 422 | endfunction"}}} 423 | 424 | function! s:getConstructedObjectComplete(constructor_info)"{{{ 425 | "Decho 'getConstructedObjectComplete, constructor_info: ' . string(a:constructor_info) 426 | 427 | let ret = [] 428 | 429 | let [declare_info, class_name] = a:constructor_info 430 | let mod_name = declare_info.value 431 | " global 432 | if declare_info.type == s:js_obj_declare_type.global 433 | " Buffer 434 | if class_name == '' 435 | let class_name = '.self' 436 | endif 437 | " global.Buffer 438 | if mod_name == 'global' 439 | let mod_name = class_name 440 | let class_name = '.self' 441 | endif 442 | endif 443 | 444 | " global or require 445 | if declare_info.type == s:js_obj_declare_type.global || 446 | \ declare_info.type == s:js_obj_declare_type.require 447 | 448 | let ret = s:getNodeDocList(declare_info.type, mod_name, 'classes', class_name) 449 | endif 450 | 451 | return ret 452 | endfunction"}}} 453 | 454 | function! s:addFunctionParen(compl_list)"{{{ 455 | for item in a:compl_list 456 | if type(item) == 4 457 | if item.kind == 'f' 458 | let item.word = item.word . '(' 459 | endif 460 | endif 461 | endfor 462 | 463 | return a:compl_list 464 | endfunction"}}} 465 | 466 | function! s:loadNodeDocData()"{{{ 467 | " load node module data 468 | if (!exists('g:nodejs_complete_data')) 469 | " load data from external file 470 | let filename = s:nodejs_doc_file 471 | "Decho 'filename: ' . filename 472 | if (filereadable(filename)) 473 | execute 'so ' . filename 474 | "Decho string(g:nodejs_complete_data) 475 | else 476 | "Decho 'not readable: ' . filename 477 | endif 478 | endif 479 | endfunction"}}} 480 | 481 | " get infomation from g:nodejs_complete_data 482 | " @param mod_type {Enum} 483 | " @param mod_name {String} 484 | " @param type {Enum} 'props' | 'classes' 485 | " @param {String} if type == 'classes', then it exists and is class_name 486 | " else do not exist 487 | function! s:getNodeDocList(mod_type, mod_name, type, ...)"{{{ 488 | call s:loadNodeDocData() 489 | 490 | if a:mod_type == s:js_obj_declare_type.require 491 | let type = 'modules' 492 | else 493 | let type = 'globals' 494 | endif 495 | 496 | if (has_key(g:nodejs_complete_data[type], a:mod_name)) 497 | let mod = g:nodejs_complete_data[type][a:mod_name] 498 | else 499 | let mod = {} 500 | endif 501 | 502 | " class 503 | if a:0 != 0 504 | let class_name = a:1 505 | if (has_key(mod, a:type)) 506 | let classes = mod[a:type] 507 | else 508 | let classes = {} 509 | endif 510 | 511 | if (has_key(classes, a:1)) 512 | let ret = classes[class_name] 513 | else 514 | let ret = [] 515 | endif 516 | " property 517 | else 518 | if (has_key(mod, a:type)) 519 | let ret = mod[a:type] 520 | else 521 | let ret = [] 522 | endif 523 | endif 524 | 525 | return deepcopy(ret) 526 | endfunction"}}} 527 | 528 | " copied from FuzzyFinder/autoload/fuf.vim 529 | " returns list of paths. 530 | " An argument for glob() is normalized in order to avoid a bug on Windows. 531 | function! s:fuzglob(expr)"{{{ 532 | " Substitutes "\", because on Windows, "**\" doesn't include ".\", 533 | " but "**/" include "./". I don't know why. 534 | return split(glob(substitute(a:expr, '\', '/', 'g')), "\n") 535 | endfunction"}}} 536 | 537 | " when x <= 0, return [0, 0] 538 | " when y <= 0, move to previous line end 539 | function! s:fixPosition(position)"{{{ 540 | let [x, y] = a:position 541 | 542 | if x <= 0 543 | return [0, 0] 544 | endif 545 | 546 | if y <= 0 547 | let x -= 1 548 | let y = len(getline(x)) 549 | 550 | return s:fixPosition([x, y]) 551 | endif 552 | 553 | return [x, y] 554 | endfunction"}}} 555 | 556 | " return a List contains every line 557 | function! s:getLinesInRange(begin_position, end_position)"{{{ 558 | let [begin_x, begin_y] = a:begin_position 559 | let [end_x, end_y] = a:end_position 560 | 561 | let lines = [] 562 | if begin_x == end_x 563 | let line = getline(begin_x) 564 | call add(lines, line[begin_y - 1 : end_y - 1]) 565 | else 566 | let line = getline(begin_x) 567 | call add(lines, line[begin_y - 1 :]) 568 | 569 | let x = begin_x + 1 570 | while x < end_x 571 | let line = getline(x) 572 | call add(lines, line) 573 | let x += 1 574 | endwhile 575 | 576 | let line = getline(end_x) 577 | call add(lines, line[: end_y - 1]) 578 | endif 579 | 580 | return lines 581 | endfunction"}}} 582 | 583 | " filter items with exact match at first 584 | function! s:smartFilter(items, str, keyword)"{{{ 585 | let items = filter(a:items, a:str . ' =~ "' . a:keyword . '"') 586 | let [exact_ret, fuzzy_ret] = [[], []] 587 | for item in items 588 | if item.word =~ '^' . a:keyword 589 | call add(exact_ret, item) 590 | else 591 | call add(fuzzy_ret, item) 592 | endif 593 | endfor 594 | 595 | return exact_ret + fuzzy_ret 596 | endfunction"}}} 597 | 598 | " 599 | " use plugin Decho(https://github.com/vim-scripts/Decho) for debug 600 | " 601 | " turn off debug mode 602 | " :%s;^\(\s*\)\(Decho\);\1"\2;g | :w | so % 603 | " 604 | " turn on debug mode 605 | " :%s;^\(\s*\)"\(Decho\);\1\2;g | :w | so % 606 | " 607 | 608 | 609 | " vim:set foldmethod=marker: 610 | -------------------------------------------------------------------------------- /after/autoload/update-nodejs-doc.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * @author: Lin Zhang ( myhere.2009 AT gmail DOT com ) 5 | * @fileoverview: This script for auto-generate nodejs-doc.vim 6 | */ 7 | 8 | var util = require('util'), 9 | fs = require('fs'), 10 | path = require('path'), 11 | os = require('os'), 12 | emitter = new (require('events')).EventEmitter(); 13 | 14 | init(); 15 | 16 | function init() { 17 | initEvents(); 18 | 19 | initLoading(); 20 | 21 | getNodejsDoc(); 22 | } 23 | 24 | function initEvents() { 25 | // uncatched exception 26 | process.on('uncaughtException', function(err) { 27 | clearLoading(); 28 | 29 | console.error('Error: ' + err.stack); 30 | }); 31 | 32 | emitter.on('vimscript/done', function(message) { 33 | clearLoading(); 34 | console.log(message); 35 | console.log('Done!'); 36 | }); 37 | } 38 | 39 | function initLoading() { 40 | var chars = [ 41 | '-', 42 | '\\', 43 | '|', 44 | '/' 45 | ]; 46 | 47 | var index = 0, 48 | total = chars.length; 49 | 50 | initLoading.timer = setInterval(function() { 51 | index = ++index % total; 52 | 53 | var c = chars[index]; 54 | 55 | // clear console 56 | // @see: https://groups.google.com/forum/?fromgroups#!topic/nodejs/i-oqYFVty5I 57 | process.stdout.write('\033[2J\033[0;0H'); 58 | console.log('please wait:'); 59 | console.log(c); 60 | }, 200); 61 | } 62 | function clearLoading() { 63 | clearInterval(initLoading.timer); 64 | } 65 | 66 | function getNodejsDoc() { 67 | var http = require('http'); 68 | 69 | var req = http.get('http://nodejs.org/api/all.json', function(res){ 70 | var chunks = []; 71 | 72 | res.on('data', function(chunk) { 73 | chunks.push(chunk); 74 | }); 75 | 76 | res.on('end', function() { 77 | var buf = Buffer.concat(chunks), 78 | body = buf.toString('utf-8'); 79 | 80 | extract2VimScript(body); 81 | }); 82 | }).on('error', function(e) { 83 | console.error('problem with request: ' + e.message); 84 | }); 85 | } 86 | 87 | function extract2VimScript(body) { 88 | // for debug 89 | fs.writeFile('./nodejs-doc-all.json', body); 90 | var json = JSON.parse(body), 91 | vimObject; 92 | 93 | var _globals = sortModuleByName(mergeObject(getModsInfo(json.globals), 94 | getModsInfo(json.vars))), 95 | _modules = sortModuleByName(getModsInfo(json.modules)), 96 | _vars = (getVarInfo(json.vars)) 97 | .concat(getVarInfo(json.globals)) 98 | .sort(sortCompleteWord); 99 | 100 | _globals = copyGlobals(_globals, _modules); 101 | 102 | vimObject = { 103 | 'globals': _globals, 104 | 'modules': _modules, 105 | 'vars': _vars 106 | }; 107 | 108 | 109 | var filename = path.join(__dirname, 'nodejs-doc.vim'), 110 | comment = '" this file is auto created by "' + __filename + '", please do not edit it yourself!', 111 | content = 'let g:nodejs_complete_data = ' + JSON.stringify(vimObject), 112 | 113 | content = comment + os.EOL + content; 114 | 115 | fs.writeFile(filename, content, function(err) { 116 | emitter.emit('vimscript/done', 'write file to "' + filename + '" complete.'); 117 | }); 118 | 119 | // for debug 120 | fs.writeFileSync(filename + '.js', JSON.stringify(vimObject, null, 2)); 121 | } 122 | 123 | function getModsInfo(mods) { 124 | var ret = {}; 125 | if (!util.isArray(mods)) { 126 | return ret; 127 | } 128 | 129 | 130 | mods.forEach(function(mod) { 131 | var mod_name = getModName(mod), 132 | mod_props = getModProps(mod); 133 | 134 | // class 135 | var mod_classes = {}; 136 | var classes = mod.classes || []; 137 | classes.forEach(function(cls) { 138 | var names = getClassName(cls, mod_name); 139 | var cls_name = names.cls_name, 140 | _mod_name = names.mod_name; 141 | if (_mod_name && mod_name != _mod_name) { 142 | mod_name = names.mod_name; 143 | } 144 | 145 | mod_classes[cls_name] = getModProps(cls); 146 | }); 147 | 148 | if (mod_props.length == 0 && classes.length == 0) { 149 | } else { 150 | ret[mod_name] = { 151 | props: mod_props, 152 | classes: mod_classes 153 | } 154 | } 155 | }); 156 | 157 | return ret; 158 | } 159 | 160 | function getModProps(mod) { 161 | var is_legal_property_name = function(name) { 162 | name += ''; 163 | name = name.trim(); 164 | 165 | return (/^[$a-zA-Z_][$a-zA-Z0-9_]*$/i).test(name); 166 | }; 167 | 168 | var props = []; 169 | // properties 170 | var properties = mod.properties || []; 171 | properties.forEach(function(property) { 172 | var name = property.name; 173 | if (is_legal_property_name(name)) { 174 | var item = {}; 175 | item.word = name; 176 | item.kind = 'm'; 177 | item.info = ' '; 178 | 179 | props.push(item); 180 | } else { 181 | console.log('illegal name: ' + name); 182 | } 183 | }); 184 | 185 | // methods 186 | var methods = mod.methods || []; 187 | methods.forEach(function(method) { 188 | var name = method.name; 189 | if (is_legal_property_name(name)) { 190 | var item = {}; 191 | if (method.type == 'method') { 192 | item.word = name; 193 | item.info = method.textRaw; 194 | item.kind = 'f'; 195 | 196 | props.push(item); 197 | } 198 | } else { 199 | console.log('illegal name: ' + name); 200 | } 201 | }); 202 | 203 | // classes 204 | var classes = mod.classes || []; 205 | classes.forEach(function(cls) { 206 | var mod_name = getModName(mod); 207 | var names = getClassName(cls, mod_name); 208 | var name = names.cls_name; 209 | if (is_legal_property_name(name)) { 210 | var item = {}; 211 | item.word = names.cls_name; 212 | item.kind = 'f'; 213 | item.info = ' '; 214 | 215 | props.push(item); 216 | } else { 217 | console.log('illegal name: ' + name); 218 | } 219 | }); 220 | 221 | props = props.sort(sortCompleteWord); 222 | 223 | return props; 224 | } 225 | 226 | function getModName(mod) { 227 | // module name 228 | var mod_name = mod.name; 229 | // invalid module name like 'tls_(ssl)' 230 | // then guess the module name from textRaw 'TLS (SSL)' 231 | if ((/[^_a-z\d\$]/i).test(mod_name)) { 232 | var textRaw = mod.textRaw; 233 | var matched = textRaw.match(/^[_a-z\d\$]+/i); 234 | if (matched) { 235 | var mod_name_len = matched[0].length; 236 | mod_name = mod_name.substr(0, mod_name_len); 237 | } 238 | } 239 | 240 | return mod_name; 241 | } 242 | 243 | function getClassName(cls, mod_name) { 244 | var str = cls.name; 245 | var names = str.split('.'); 246 | 247 | var _mod_name = names[0], 248 | cls_name; 249 | 250 | if (names.length == 1) { 251 | cls_name = _mod_name; 252 | } 253 | else { 254 | // 修正 mod_name; events.EventEmitter 255 | if (_mod_name.toLowerCase() == mod_name.toLowerCase()) { 256 | mod_name = _mod_name; 257 | } 258 | cls_name = names.slice(1).join('.'); 259 | } 260 | 261 | return { 262 | mod_name: mod_name, 263 | cls_name: cls_name 264 | }; 265 | } 266 | 267 | function getVarInfo(vars) { 268 | var ret = []; 269 | if (!util.isArray(vars)) { 270 | return ret; 271 | } 272 | 273 | vars.forEach(function(_var) { 274 | // if var is a function 275 | if ((/\([^\(\)]*\)\s*$/).test(_var.textRaw)) { 276 | ret.push({ 277 | word: _var.name, 278 | info: _var.textRaw, 279 | kind: 'f' 280 | }); 281 | } else { 282 | ret.push({ 283 | word: _var.name, 284 | kind: 'v', 285 | info: ' ' 286 | }); 287 | } 288 | }); 289 | 290 | // sort 291 | ret = ret.sort(sortCompleteWord); 292 | 293 | return ret; 294 | } 295 | 296 | function copyGlobals(globals, modules) { 297 | var _Buffer = modules.buffer.classes.Buffer; 298 | 299 | globals.Buffer = { 300 | props: [], 301 | classes: { 302 | '.self': _Buffer 303 | } 304 | }; 305 | 306 | return globals; 307 | } 308 | 309 | 310 | // helpers 311 | /** 312 | * @param {Object} 313 | */ 314 | function sortModuleByName(mods) { 315 | var keys = Object.keys(mods); 316 | // sort 317 | keys.sort(); 318 | 319 | var ret = {}; 320 | keys.forEach(function(k) { 321 | ret[k] = mods[k]; 322 | }); 323 | 324 | return ret; 325 | } 326 | 327 | /** 328 | * @param {Object} 329 | * @param {Object} 330 | */ 331 | function sortCompleteWord(a, b) { 332 | var a_w = a.word.toLowerCase(), 333 | b_w = b.word.toLowerCase(); 334 | 335 | return a_w < b_w ? -1 : (a_w > b_w ? 1 : 0); 336 | } 337 | 338 | /** 339 | * @desc merge Object 340 | * @arguemnts: {Object} 341 | * 342 | * @return: return the new merged Object 343 | */ 344 | function mergeObject() { 345 | var ret = {}, 346 | args = Array.prototype.slice.call(arguments); 347 | 348 | args.forEach(function(obj) { 349 | for (var p in obj) { 350 | if (obj.hasOwnProperty(p)) { 351 | ret[p] = obj[p]; 352 | } 353 | } 354 | }); 355 | 356 | return ret; 357 | } 358 | -------------------------------------------------------------------------------- /after/ftplugin/javascript.vim: -------------------------------------------------------------------------------- 1 | if exists('&ofu') 2 | setlocal omnifunc=nodejscomplete#CompleteJS 3 | endif 4 | -------------------------------------------------------------------------------- /after/test/a.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | 3 | 4 | fs 5 | fs. 6 | fs.read 7 | fs[ 8 | fs[" 9 | fs['chmodSync']( 10 | 11 | 12 | 13 | var a = {hello: 'world'}, 14 | b = require('path'), 15 | // b = new A, 16 | // b = a; 17 | 18 | 19 | b. 20 | 21 | 22 | var emitter = new (require('events')).EventEmitter; 23 | emitter. 24 | 25 | var events = require('events'); 26 | var emitter = new events.EventEmitter(); 27 | var buffer = new Buffer; 28 | // var buffer = new global.Buffer; 29 | var tester = new A.B.C(); 30 | 31 | emitter. 32 | buffer. 33 | tester. 34 | events. 35 | 36 | 37 | cons 38 | 39 | 40 | 41 | { 42 | "globals": { 43 | "Buffer": { 44 | "classes": [ 45 | { 46 | ".self": [ 47 | { 48 | "word": "write", 49 | "info": "buf.write(string, [offset], [length], [encoding])", 50 | "kind": "f" 51 | } 52 | ] 53 | } 54 | ], 55 | "protos": [ 56 | ] 57 | } 58 | }, 59 | "modules": { 60 | "events" { 61 | "classes": [ 62 | ], 63 | "protos": [ 64 | ] 65 | } 66 | }, 67 | "vars": [ 68 | { 69 | "word": "__dirname", 70 | "kind": "v" 71 | } 72 | ] 73 | } 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | --------------------------------------------------------------------------------