Skip to content

Commit

Permalink
tweak findVar output;use colSpans in vim binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Claus Reinke committed Jun 18, 2012
1 parent c83b724 commit 9d80dfd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
9 changes: 7 additions & 2 deletions estr.js
Expand Up @@ -104,10 +104,10 @@ switch (process.argv.shift()) {
console.log(scope.type,scope.loc);

console.log('binding occurrence: ');
console.log(file,binding[1],binding[0].loc.start);
console.log(file+' '+binding[1]+' '+locColSpan(binding[0].loc));
console.log('other occurrences: ');
binding[0].occurrences.forEach(function(o){
console.log(file,o.name,o.loc.start)
console.log(file+' '+o.name+' '+locColSpan(o.loc))
});

} else if (results[0].parseError) {
Expand Down Expand Up @@ -215,6 +215,11 @@ function processJSfiles(paths,action) {
return results;
}

function locColSpan(loc) {
return '{ line: '+loc.start.line
+', column: '+loc.start.column+'-'+loc.end.column+'}'
}

function exitCode(code) {
process.on('exit',function(){process.exit(1)});
}
4 changes: 2 additions & 2 deletions tests/out/findVar.stdout
@@ -1,6 +1,6 @@
binding scope:
FunctionDeclaration { start: { line: 3, column: 0 }, end: { line: 33, column: 1 } }
binding occurrence:
sample.js VariableDeclarator { line: 15, column: 6 }
sample.js VariableDeclarator { line: 15, column: 6-7}
other occurrences:
sample.js z { line: 6, column: 20 }
sample.js z { line: 6, column: 20-21}
13 changes: 12 additions & 1 deletion vimfiles/ftplugin/javascript-estr.vim
Expand Up @@ -35,8 +35,19 @@ function! FindVar()
let output = system("node ".s:estr." ".command)
let occurrences = substitute(output,".*binding occurrence","binding occurrence","")
let s:efm = &efm
set efm=%-Ibinding\ occurrence:\ ,%-Iother\ occurrences:\ ,%f\ %.%#\ {\ line:\ %l\\,\ column:\ %c\ %.%#
set efm=%-Ibinding\ occurrence:\ ,%-Iother\ occurrences:\ ,%f\ %.%#\ {\ line:\ %l\\,\ column:\ %c-%m
lexpr occurrences
let loclist = getloclist(0)
let pattern = []
for loc in loclist
let loc.col = loc.col+1
let loc.text = substitute(loc.text,'\(%d+\)}','\1','')+1
let pattern += ["\\%".(loc.lnum)."l\\%>".(loc.col-1)."c\\i\\+\\%<".(loc.text+1)."c"]
endfor
set hlsearch
let @/ = join(pattern,'\|')
call search(@/)
call setloclist(0,loclist)
let &efm = s:efm
endfunction

Expand Down

0 comments on commit 9d80dfd

Please sign in to comment.