     @registerHelperCommands()
     @provider.init(this)
     @initServers()
+    @disposables.push atom.project.onDidChangePaths (paths) =>
+      @destroyServer(paths)
+      @checkPaths(paths)
+      @setActiveServerAndClient()
 
   init: ->
-    @setActiveServerAndClient()
     @initialised = true
     @registerEvents()
     @registerCommands()

    return true

  registerEvents: ->
    @disposables.push atom.project.onDidChangePaths (paths) =>
      @checkPaths(paths)
    @disposables.push atom.commands.add 'atom-text-editor', 'tern:references': (event) =>
      if !@reference
        Reference = require './atom-ternjs-reference'


  startServer: (dir) ->
    Server = require './atom-ternjs-server' if !Server
    return if @getServerForProject(dir)
    idxServer = @servers.push(new Server(dir)) - 1
    @servers[idxServer].start (port) =>
      client = @getClientForProject(dir)
      if !client
        Client = require './atom-ternjs-client' if !Client
        clientIdx = @clients.push(new Client(this, dir)) - 1
        @clients[clientIdx].port = port
      else
        client.port = port
      @init() if @servers.length is @clients.length and !@initialised
      @setActiveServerAndClient()

  setActiveServerAndClient: (URI) ->
    if !URI
