 CP = require('child_process')
+{Range} = require 'atom'
 module.exports=
 class SuggestionBuilder
   typeScope: 'meta.function.type-declaration.haskell'
   sourceScope: 'source.haskell'
   moduleScope: 'support.other.module.haskell'
+  preprocessorScope: 'meta.preprocessor.haskell'
 
   constructor: (@options,@info) ->
     @editor = @options.editor

        .then(@getType)
    else if @isIn(@moduleScope)
      console.log('moduleScope')
      @info.moduleList
        .filter (line) =>
          line.startsWith @replaceModuleName(@prefix)
        .map (mod) =>
          word: mod
          label: 'module'
          prefix: @prefix
    #should be last as least sepcialized
    else if @isIn(@sourceScope)
      console.log('sourceScope')

          label: @trim label
          prefix: @prefix
        }

  getModule: (prefix) =>
    @info.moduleList
      .filter (line) ->
        line.startsWith prefix
      .map (mod) ->
        word: mod
        label: 'preprocessor'
        prefix: prefix

  getPreprocessor: (prefix) =>
    (if prefix[0]=='-' then @info.ghcFlags
    else @info.langOpts)
      .filter (line) ->
        line.startsWith prefix
      .map (mod) ->
        word: mod
        label: 'preprocessor'
        prefix: prefix

  isIn: (scope) ->
    @scopes.some (s) -> s==scope

  genSpaceSearch: =>
    r = new Range @options.cursor.getCurrentLineBufferRange().start,
      @options.position
    new Promise (resolve) =>
      @editor.backwardsScanInBufferRange /[^\s]+/, r, ({matchText,stop})->
        resolve(matchText)
        stop()

  getSuggestions: =>
    if @isIn(@typeScope)
