IdrisController = require './idris-controller'
{CompositeDisposable} = require 'atom'

module.exports =
  active: false
  statusbar: null

  config:
    pathToIdris:
      type: 'string'
      default: 'idris'
      description: 'Path to the idris executable'

  activate: ->
    @disposables = new CompositeDisposable

    @active = @initIdris()
    if not @isActive()
      @disposables.add myself=atom.workspace.onDidOpen (event) =>
        item = event.item
        @active = @initIdris()
        if @isActive()
          myself.dispose()

  initIdris: () ->
    if @isActive()
      true
    else
      idrisFileOpened = atom.workspace.getTextEditors().some @isIdrisFile
      if idrisFileOpened
        @controller = new IdrisController
        if @statusbar
          @controller.attachStatusIndicator @statusbar
        subscription = atom.commands.add 'atom-text-editor[data-grammar~="idris"]', @controller.getCommands()
        @subscriptions = new CompositeDisposable
        @subscriptions.add subscription
        true
      else
        false

  isActive: ->
    @active

  isIdrisFile: (editor) ->
    editor.getGrammar?()?.scopeName == 'source.idris'

  deactivate: ->
    @subscriptions.dispose()
    this.controller.destroy()

  consumeStatusBar: (statusbar) ->
    @statusbar = statusbar
    @controller?.attachStatusIndicator statusbar

IdrisController = require './idris-controller'
{CompositeDisposable} = require 'atom'

module.exports =
  config:
    pathToIdris:
      type: 'string'
      default: 'idris'
      description: 'Path to the idris executable'

  activate: ->
    @controller = new IdrisController

    subscription = atom.commands.add 'atom-text-editor[data-grammar~="idris"]', @controller.getCommands()
    @subscriptions = new CompositeDisposable
    @subscriptions.add subscription

  deactivate: ->
    @subscriptions.dispose()
    this.controller.destroy()

  consumeStatusBar: (statusBar) ->
    @controller.attachStatusIndicator statusBar

Revert "only start the idris compiler when there is an idris file opened"
Revert "only start the idris compiler when there is an idris file opened"

This reverts commit 89c0032aca1593cc851a65e7836ea8f539258a11.

Conflicts:
	lib/language-idris.coffee
