Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Add a debug option, and one for finders. Close #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgiles committed Jul 27, 2014
1 parent c33274a commit 8ab4f7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 12 additions & 0 deletions closure.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ var TypeManager = require('./lib/typemanager');


var typeManager;
var debug;


tern.registerPlugin('closure', function(server, options) {
if (options.hasOwnProperty('debug')) {
debug = options.debug;
} else {
debug = server.options.debug;
}
var finder = null;
if (options.finder) {
if (!options.finder.hasOwnProperty('debug')) {
options.finder.debug = debug;
}
var Finder;
try {
Finder = require('./lib/finder/' + options.finder.name);
Expand Down Expand Up @@ -133,6 +142,9 @@ function postParse(ast, text) {
* @param {!infer.Scope} scope
*/
function postInfer(ast, scope) {
if (debug) {
console.log('closure: postInfer ' + infer.cx().curOrigin);
}
walk.simple(ast, {
VariableDeclaration: function(node, scope) {
interpretComments(node, node._closureComment,
Expand Down
20 changes: 14 additions & 6 deletions lib/finder/grep.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var PROVIDE_RE = /^(.+\.js):goog\.provide\(['"](\S+)['"]\);/;
* A simple class for mapping class names to origin files which pre-populates a
* map of names to files by delegating to grep.
* @param {string} projectDir The Tern project directory.
* @param {{dirs: Array.<string>}} options
* @param {{name: string, debug: boolean, dirs: Array.<string>}} options
* @constructor
*/
var GrepFileFinder = function(projectDir, options) {
Expand All @@ -44,20 +44,22 @@ var GrepFileFinder = function(projectDir, options) {
/** @private {string} The project dir. */
this.projectDir_ = projectDir;

this.prepopulate_(options);
/** @private {{name: string, debug: boolean, dirs: Array.<string>}} */
this.options_ = options;

this.prepopulate_();
};
module.exports = GrepFileFinder;


/**
* Pre-populates the internal file map.
* @param {{dirs: Array.<string>}} options
* @private
*/
GrepFileFinder.prototype.prepopulate_ = function(options) {
GrepFileFinder.prototype.prepopulate_ = function() {
var dirs;
if (options.dirs) {
dirs = options.dirs;
if (this.options_.dirs) {
dirs = this.options_.dirs;
} else {
dirs = ['.'];
}
Expand All @@ -74,12 +76,18 @@ GrepFileFinder.prototype.prepopulate_ = function(options) {
*/
GrepFileFinder.prototype.searchDir_ = function(dir) {
// TODO: Track when done prepopulating, defer calls that come in before done.
if (this.options_.debug) {
console.log('grep: searching ' + dir);
}
var search = spawn('grep', ['-R', '--include=*.js', '^goog.provide(', dir]);
search.stdout.setEncoding('utf8');
carrier.carry(search.stdout, function(line) {
var match = line.match(PROVIDE_RE);
if (!match) {
// TODO: Deal with line-wrapped goog.provide statements #7.
if (this.options_.debug) {
console.log('grep: Failed to match line ' + line);
}
return;
}
var name = match[2];
Expand Down

0 comments on commit 8ab4f7f

Please sign in to comment.