 fs = require "fs"
 
-BibtexProvider = require "./provider"
+ReferenceProvider = require "./provider"
 
 module.exports =
   config:
-    bibtex:
+    references:
       type: 'array'
       default: []
       items:

  activate: (state) ->
    reload = false
    if state
      bibtexFiles = atom.config.get "autocomplete-bibtex.bibtex"
      if not Array.isArray(bibtexFiles)
        bibtexFiles = [bibtexFiles]
      # reload everything if any files changed
      for file in bibtexFiles
        stats = fs.statSync(file)
        if stats.isFile()
          if state.saveTime < stats.mtime.getTime()

    # Need to distinguish between the Autocomplete provider and the
    # containing class (which holds the serialize fn)
    if state and reload is false
      @referenceProvider = atom.deserializers.deserialize(state.provider)
      #deserializer produces "undefined" if it fails, so double check
      if not @referenceProvider
        @referenceProvider = new ReferenceProvider()
    else
      @referenceProvider = new ReferenceProvider()

    @provider = @referenceProvider.provider

  deactivate: ->
    @provider.registration.dispose()

  serialize: ->
    state = {
      provider: @referenceProvider.serialize()
      saveTime: new Date().getTime()
    }
    return state
