     @disposables = []
 
   startServer: ->
-    return unless !@server?.process
-    return unless atom.project.getDirectories()[0]
+    return unless !@server?.process and atom.project.getDirectories()[0]
     @server = new TernServer()
     @server.start (port) =>
       if !@client

  client: null
  documentationView: null
  currentProviderIdx: 0

  # autocomplete
  autocompletePlus = null


  registerEvents: ->
    @disposables.push atom.workspace.onDidOpen (e) =>
      return unless e.item and @isValidEditor(e.item)
      @startServer()
    @disposables.push atom.workspace.onDidChangeActivePaneItem =>
      @setCurrentProvider()

  isValidEditor: (editor) ->
    return false if editor.mini
    return false if !editor.getGrammar
    return false if editor.getGrammar().name not in @grammars
    return true

  setCurrentProvider: ->
    @activeTextEditor = atom.workspace.getActiveTextEditor()
    return unless @activeTextEditor
    for provider, idx in @providers
      provider.isActive = false
      if provider.editor.id is @activeTextEditor.id
        @currentProviderIdx = idx
        provider.isActive = true
        break

  registerEditors: ->
    @editorSubscription = atom.workspace.observeTextEditors (editor) =>
      return unless @isValidEditor(editor)
      @registerEditor(editor)
      @setCurrentProvider()

