Skip to content

Instantly share code, notes, and snippets.

@sidd
Created December 10, 2017 20:26
Show Gist options
  • Save sidd/e325a942832478ecef189cb5e1ae9fee to your computer and use it in GitHub Desktop.
Save sidd/e325a942832478ecef189cb5e1ae9fee to your computer and use it in GitHub Desktop.
Wrap jsctags in a dependency-free ctags-like executable (be sure to chmod +x jsctags.js)
#!/usr/bin/env node
const cp = require('child_process');
function getarg(arg) {
const filter = new RegExp(`^-{1,2}${arg}=*(.*)`);
const matches = process
.argv
.map(str => str.match(filter))
const argdef = matches.findIndex(Boolean);
const match = matches[argdef];
if (Array.isArray(match)) {
if (match[1]) {
return match[1];
} else if (process.argv[argdef + 1]) {
return process.argv[argdef + 1];
}
}
}
const argv = {
fileList: getarg('L'),
outputFile: getarg('f'),
append: getarg('append'),
exclude: getarg('exclude'),
};
let files = '';
if (argv.fileList) {
files = cp.execSync(`cat ${argv.fileList}`, { encoding: 'utf8' });
} else if (argv.append) {
files = argv.append;
} else {
let cmd = 'find . -type f -iregex ".*\.jsx?$"';
if (argv.exclude) {
cmd += ` -not -path "*${argv.exclude}*"`;
}
files = cp.execSync(cmd, { encoding: 'utf8' })
.split('\n')
.join(' ');
}
cp.exec(`jsctags ${files} -f | sort > ${argv.outputFile}`)
@sidd
Copy link
Author

sidd commented Dec 10, 2017

This implements a subset of the Ctags CLI API, enough to be compatible with vim-gutentags

Make sure to chmod +x jsctags.js

In your .vimrc, add:

let g:gutentags_ctags_executable="/path/to/jsctags.js"

No performance issues in an 81KLOC codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment