 {Emitter, CompositeDisposable} = require 'atom'
-getEditorState = null
 _ = require 'underscore-plus'
 
+cachedTags = null # global cache for tags
+TagGenerator = null
+
+# Utils
 requireFrom = (pack, path) ->
   packPath = atom.packages.resolvePackagePath(pack)
   require "#{packPath}/lib/#{path}"

getActivePackage = (pack) ->
  atom.packages.getActivePackage(pack)

getFileView = ->
  pack = getActivePackage('symbols-view')
  pack.mainModule.fileView

module.exports =
  activate: ->

  deactivate: ->

  subscribe: (args...) ->
    @subscriptions.add args...

        @emitter.on 'did-generate-tags', fn

      getCachedTags: ->
        cachedTags

      generateTags: (fn) ->
        filePath = @editor.getPath()
        scopeName = @editor.getGrammar().scopeName
        cache = @getCachedTags()
        new TagGenerator(filePath, scopeName).generate().done (tags) ->
          # console.log "generate for #{filePath}"
          cache[filePath] = tags
          fn(tags)

