diff --git a/src/extensions/outline-view/outline-view.coffee b/src/extensions/outline-view/outline-view.coffee index c732447ae..cafd5825b 100644 --- a/src/extensions/outline-view/outline-view.coffee +++ b/src/extensions/outline-view/outline-view.coffee @@ -2,7 +2,7 @@ SelectList = require 'select-list' _ = require 'underscore' Editor = require 'editor' -ChildProcess = require 'child-process' +TagGenerator = require 'outline-view/tag-generator' module.exports = class OutlineView extends SelectList @@ -34,50 +34,12 @@ class OutlineView extends SelectList else @populate() - parsePrefix: (section = "") -> - if section.indexOf('class:') is 0 - section.substring(6) - else if section.indexOf('namespace:') is 0 - section.substring(10) - else if section.indexOf('file:') is 0 - section.substring(5) - else if section.indexOf('signature:') is 0 - section.substring(10) - else - section - - parseTagLine: (line) -> - sections = line.split('\t') - return null if sections.length < 4 - - label = sections[0] - line = parseInt(sections[2]) - 1 - if prefix = @parsePrefix(sections[4]) - label = "#{prefix}::#{label}" - if signature = @parsePrefix(sections[5]) - label = "#{label}#{signature}" - - tag = - row: line - column: 0 - name: label - - return tag - populate: -> tags = [] - options = - bufferLines: true - stdout: (data) => - lines = data.split('\n') - for line in lines - tag = @parseTagLine(line) - tags.push(tag) if tag - + callback = (tag) -> + tags.push tag path = @rootView.getActiveEditor().getPath() - command = "ctags --fields=+KS -nf - #{path}" - deferred = ChildProcess.exec command, options - deferred.done => + new TagGenerator(path, callback).generate().done => if tags.length > 0 @setArray(tags) @attach() diff --git a/src/extensions/outline-view/tag-generator.coffee b/src/extensions/outline-view/tag-generator.coffee new file mode 100644 index 000000000..3b87f65fc --- /dev/null +++ b/src/extensions/outline-view/tag-generator.coffee @@ -0,0 +1,47 @@ +ChildProcess = require 'child-process' + +module.exports = +class TagGenerator + + constructor: (@path, @callback) -> + + parsePrefix: (section = "") -> + if section.indexOf('class:') is 0 + section.substring(6) + else if section.indexOf('namespace:') is 0 + section.substring(10) + else if section.indexOf('file:') is 0 + section.substring(5) + else if section.indexOf('signature:') is 0 + section.substring(10) + else + section + + parseTagLine: (line) -> + sections = line.split('\t') + return null if sections.length < 4 + + label = sections[0] + line = parseInt(sections[2]) - 1 + if prefix = @parsePrefix(sections[4]) + label = "#{prefix}::#{label}" + if signature = @parsePrefix(sections[5]) + label = "#{label}#{signature}" + + tag = + row: line + column: 0 + name: label + + return tag + + generate: -> + options = + bufferLines: true + stdout: (data) => + lines = data.split('\n') + for line in lines + tag = @parseTagLine(line) + @callback(tag) if tag + command = "ctags --fields=+KS -nf - #{@path}" + ChildProcess.exec(command, options)