Skip to content

Commit

Permalink
Add excmd argument to allow number format tags file
Browse files Browse the repository at this point in the history
  • Loading branch information
othree committed Mar 17, 2019
1 parent e006d8b commit 833b76e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 13 additions & 3 deletions bin/jsctags
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ const fs = require('fs');

const jsctags = require('../');

const EXCMDS = ['number', 'pattern'];

const options = {
excmd: 'pattern'
};

if (argv.excmd && EXCMDS.indexOf(argv.excmd) >= 0) {
options.excmd = argv.excmd;
}

const dir = (function () {
if (argv.dir) {
return path.resolve(argv.dir);
Expand Down Expand Up @@ -54,8 +64,8 @@ const file = (function () {
});
})();

const outputTags = function (tags) {
const ctags = flatten(jsctags.ctags(tags));
const outputTags = function (tags, options) {
const ctags = flatten(jsctags.ctags(tags, options));
console.log(ctags.join(''));
};

Expand All @@ -81,7 +91,7 @@ const onResults = function (err, results) {

tags.tagfile = results.tagfile;

fn(tags);
fn(tags, options);
};

const parse = function (ctx, fn) {
Expand Down
12 changes: 9 additions & 3 deletions src/ctags.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ const SPECIAL_FIELDS = {
parent: true
};

const convert = function (tags) {
const convert = function (tags, options) {
return tags.map(tag => {
if (isArray(tag)) {
return convert(tag);
return convert(tag, options);
}

const buf = [tag.name, '\t', tags.tagfile, '\t'];
buf.push(tag.addr === undefined ? '//' : tag.addr);

if (options.excmd === 'number') {
buf.push(tag.lineno === undefined ? '//' : tag.lineno);
} else {
buf.push(tag.addr === undefined ? '//' : tag.addr);
}

const tagfields = [];

Object.keys(tag).forEach(key => {
Expand Down

0 comments on commit 833b76e

Please sign in to comment.