                 return null
 
 
-
-        ###
-        # Current refactoring ends here for Container
-        ###
+           
+
+            ###
+            errors = @get_errors_from_query @codemirror.getValue()
+
+            # Check if we are in a string or in the middle of a word, if we are in a string, we just show the description
+            is_in_string = @is_in_string query_before_cursor
+            if is_in_string.boolean is true
+                @hide_suggestion()
+                last_function_for_description = @extract_last_function_for_description
+                    is_string: true
+                    char_used: is_in_string.char_used
+                    query: query_before_cursor
+                if last_function_for_description isnt ''
+                    @add_description last_function_for_description
+                return ''
+            
+            # We do not suggest things if in the middle of a word
+            index_next_character = 0
+            while query_after_cursor[index_next_character]?
+                if /\s/.test(query_after_cursor[index_next_character]) is false
+                    next_non_white_character = query_after_cursor[index_next_character]
+                    break
+                index_next_character++
+            if next_non_white_character? and next_non_white_character isnt '.' and next_non_white_character isnt ',' and next_non_white_character isnt ')' and next_non_white_character isnt ';'
+                @hide_suggestion()
+                last_function_for_description = @extract_last_function_for_description(query_before_cursor)
+                if last_function_for_description isnt ''
+                    @add_description last_function_for_description
+                return ''
+
+            # Extract the current query (the inner query)
+            slice_index = @extract_query_first_part query_before_cursor
+            query = query_before_cursor.slice slice_index
+            
+            # Store data to reconstruct when a suggestion is selected
+            @query_first_part = query_before_cursor.slice 0, slice_index
+            @query_last_part = query_after_cursor
+
+            # Get the last completed function for description and suggestion
+            last_function = @extract_last_function(query)
+            just_description = false # Boolean to know if we want to display just the description and not the suggestions
+            # Hack in case a new parenthesis is opened. Ex: r.table('foo').filter( // We want to describe filter, not suggest r(
+            if /^\s*$/.test(query) is true or last_function is '' # We have an empty cursor
+                last_function_full = @extract_last_function_for_description(query_before_cursor)
+                if last_function_full isnt ''
+                    last_function = last_function_full
+                    just_description = true
+
+            # Hack because last_function returns 'r' if the query is 'r'. and r isn't a function
+            if last_function is query and last_function is 'r'
+                last_function = ''
+
+            if @map_state[last_function]? and @suggestions[@map_state[last_function]]?
+                if not @suggestions[@map_state[last_function]]? or @suggestions[@map_state[last_function]].length is 0 or just_description is true
+                    @hide_suggestion()
+                    last_function_for_description = @extract_last_function_for_description(query_before_cursor)
+
+                    if last_function_for_description isnt ''
+                        @add_description last_function_for_description
+                else
+                    could_append = @append_suggestion(query, @suggestions[@map_state[last_function]])
+                    if could_append is false # We couldn't find any suggestion that matched. We are probably at the end of a function (closing parenthesis)
+                        last_function_for_description = @extract_last_function_for_description(query_before_cursor)
+
+                        if last_function_for_description isnt ''
+                            @add_description last_function_for_description
+            else
+                @hide_suggestion()
+                last_function_for_description = @extract_last_function_for_description(query_before_cursor)
+
+                if last_function_for_description isnt ''
+                    @add_description last_function_for_description
+            ###
+            return false
+
+        # Check if the end of the query is in the middle of a string. 
+        is_in_string: (query) ->
+            is_string = false
+            char_used = ''
+            
+            for char, i in query
+                if is_string is false
+                    if char is '"' or char is '\''
+                        is_string = true
+                        char_used = char
+
+
+                else
+                    if char is char_used and query[i-1] isnt '\\' # It's safe to get query[i-1] because is_string cannot be true for the first char
+                        is_string = false
+
+            boolean: is_string
+            char_used: char_used
+        # Hipsters stuff
+        
+        #Highlight suggestion. Method called when the user hit tab or mouseover
+        highlight_suggestion: (id) =>
+            @.$('.suggestion_name_li').removeClass 'suggestion_name_li_hl'
+            @.$('.suggestion_name_li').eq(id).addClass 'suggestion_name_li_hl'
+            @.$('.suggestion_description').html @description_template @extend_description @current_suggestions[id]
+            @show_suggestion_description()
+
+        # Show the description of the suggestion
+        show_suggestion_description: =>
+            margin = (parseInt(@.$('.CodeMirror-cursor').css('top').replace('px', ''))+@line_height)+'px'
+            @.$('.suggestion_full_container').css 'margin-top', margin
+            @.$('.arrow').css 'margin-top', margin
+
+            @.$('.suggestion_description').show()
+            @.$('.arrow').show()
+
+        # Write the suggestion
+        write_suggestion: (args) =>
+            suggestion_to_write = args.suggestion_to_write
+            saved_cursor = args.saved_cursor
+            @codemirror.setValue @query_first_part + @current_completed_query + suggestion_to_write + @query_last_part
+    
+            # We want look for the position of the cursor on the current line.
+            start_line_index = (@query_first_part + @current_completed_query).lastIndexOf('\n')
+            start_line_index++ # Set to 0 if not found else move after \n
+
+            position = (@query_first_part + @current_completed_query + suggestion_to_write).length - start_line_index
+            @codemirror.setCursor position
+                line: saved_cursor.line
+                ch: position
+
+            # Let's save the new query
+            @__proto__.saved_data._query = @codemirror.getValue()
+
+        # Select the suggestion highlighted
+        select_suggestion: (event) =>
+            saved_cursor = @codemirror.getCursor()
+
+            suggestion_to_write = @.$(event.target).html()
+            @write_suggestion suggestion_to_write
+
+            # Give back focus to code mirror
+            @codemirror.focus()
+            @hide_suggestion()
+
+            @handle_keypress() # We can have a description to show or even suggestions (like after r or row)
+
+
 
         show_or_hide_arrow: =>
             if @.$('.suggestion_name_list').css('display') is 'none' and @.$('.suggestion_description').css('display') is 'none'

            

            # We could perform better, but that would make the code harder to read, so let's not work too hard
            @parse_query
                query_before_cursor: query_before_cursor
                query_after_cursor: query_after_cursor

            ###
            errors = @get_errors_from_query @codemirror.getValue()


            # Check if we are in a string or in the middle of a word, if we are in a string, we just show the description
            is_in_string = @is_in_string query_before_cursor
            if is_in_string.boolean is true
                @hide_suggestion()
                last_function_for_description = @extract_last_function_for_description
                    is_string: true
                    char_used: is_in_string.char_used
                    query: query_before_cursor
                if last_function_for_description isnt ''
                    @add_description last_function_for_description
                return ''
            
            # We do not suggest things if in the middle of a word
            index_next_character = 0
            while query_after_cursor[index_next_character]?
                if /\s/.test(query_after_cursor[index_next_character]) is false
                    next_non_white_character = query_after_cursor[index_next_character]
                    break
                index_next_character++
            if next_non_white_character? and next_non_white_character isnt '.' and next_non_white_character isnt ',' and next_non_white_character isnt ')' and next_non_white_character isnt ';'
                @hide_suggestion()
                last_function_for_description = @extract_last_function_for_description(query_before_cursor)
                if last_function_for_description isnt ''
                    @add_description last_function_for_description
                return ''

            # Extract the current query (the inner query)
            slice_index = @extract_query_first_part query_before_cursor
            query = query_before_cursor.slice slice_index
            
            # Store data to reconstruct when a suggestion is selected
            @query_first_part = query_before_cursor.slice 0, slice_index
            @query_last_part = query_after_cursor

            # Get the last completed function for description and suggestion
            last_function = @extract_last_function(query)
            just_description = false # Boolean to know if we want to display just the description and not the suggestions
            # Hack in case a new parenthesis is opened. Ex: r.table('foo').filter( // We want to describe filter, not suggest r(
            if /^\s*$/.test(query) is true or last_function is '' # We have an empty cursor
                last_function_full = @extract_last_function_for_description(query_before_cursor)
                if last_function_full isnt ''
                    last_function = last_function_full
                    just_description = true

            # Hack because last_function returns 'r' if the query is 'r'. and r isn't a function
            if last_function is query and last_function is 'r'
                last_function = ''

            if @map_state[last_function]? and @suggestions[@map_state[last_function]]?
                if not @suggestions[@map_state[last_function]]? or @suggestions[@map_state[last_function]].length is 0 or just_description is true
                    @hide_suggestion()
                    last_function_for_description = @extract_last_function_for_description(query_before_cursor)

                    if last_function_for_description isnt ''
                        @add_description last_function_for_description
                else
                    could_append = @append_suggestion(query, @suggestions[@map_state[last_function]])
                    if could_append is false # We couldn't find any suggestion that matched. We are probably at the end of a function (closing parenthesis)
                        last_function_for_description = @extract_last_function_for_description(query_before_cursor)

                        if last_function_for_description isnt ''
                            @add_description last_function_for_description
            else
                @hide_suggestion()
                last_function_for_description = @extract_last_function_for_description(query_before_cursor)

                if last_function_for_description isnt ''
                    @add_description last_function_for_description
            ###
            return false

        # Check if the end of the query is in the middle of a string. 
        is_in_string: (query) ->
            is_string = false
            char_used = ''
            
            for char, i in query
                if is_string is false
                    if char is '"' or char is '\''
                        is_string = true
                        char_used = char


                else
                    if char is char_used and query[i-1] isnt '\\' # It's safe to get query[i-1] because is_string cannot be true for the first char
                        is_string = false

            boolean: is_string
            char_used: char_used
        # Hipsters stuff
        
        #Highlight suggestion. Method called when the user hit tab or mouseover
        highlight_suggestion: (id) =>
            @.$('.suggestion_name_li').removeClass 'suggestion_name_li_hl'
            @.$('.suggestion_name_li').eq(id).addClass 'suggestion_name_li_hl'
            @.$('.suggestion_description').html @description_template @extend_description @current_suggestions[id]
            @show_suggestion_description()

        # Show the description of the suggestion
        show_suggestion_description: =>
            margin = (parseInt(@.$('.CodeMirror-cursor').css('top').replace('px', ''))+@line_height)+'px'
            @.$('.suggestion_full_container').css 'margin-top', margin
            @.$('.arrow').css 'margin-top', margin

            @.$('.suggestion_description').show()
            @.$('.arrow').show()

        # Write the suggestion
        write_suggestion: (args) =>
            suggestion_to_write = args.suggestion_to_write
            saved_cursor = args.saved_cursor
            @codemirror.setValue @query_first_part + @current_completed_query + suggestion_to_write + @query_last_part
    
            # We want look for the position of the cursor on the current line.
            start_line_index = (@query_first_part + @current_completed_query).lastIndexOf('\n')
            start_line_index++ # Set to 0 if not found else move after \n

            position = (@query_first_part + @current_completed_query + suggestion_to_write).length - start_line_index
            @codemirror.setCursor position
                line: saved_cursor.line
                ch: position

            # Let's save the new query
            @__proto__.saved_data._query = @codemirror.getValue()

        # Select the suggestion highlighted
        select_suggestion: (event) =>
            saved_cursor = @codemirror.getCursor()

            suggestion_to_write = @.$(event.target).html()
            @write_suggestion suggestion_to_write

            # Give back focus to code mirror
            @codemirror.focus()
            @hide_suggestion()

            @handle_keypress() # We can have a description to show or even suggestions (like after r or row)


        # Extract information from the current query
        
        # r.table(...).filter( functi => filter
        # r.table(...).filter( function(doc) { => filter
        # r.table(...).filter( function(doc) { r( => r
        # r.table(...).filter( function(doc) { doc('test => (
        # r.table(...).filter( function(doc) { r.row('key').add( => add
        # r.table(...).filter( function(doc) { r.row('key').add('fdsf => add
        # r.expr().map( {} )
        # r.table(...).filter( function(doc) { doc('id').eq('xxx') } ).count().run()
        #| |          |                                              |       |
        #                                    |                     |
        #                                         |    |   |     |
        # map( function(doc) { return doc.merge({1: doc('i
        # r.table('test').filter(function(doc) { doc('id').eq({key: 'test', other_key: 'other_value')}).map(r.row('data')('age').add(2)).count().run()
        # [
        #   { value: 'r',
        #     type: 'function'
        #   },
        #   {
        #     value: 'table('test')',
        #     type: function
        #     body: [
        #       value: 'test'
        #       type: string
        #     ]
        #   },
        #   {
        #     value: filter
        #     type: function
        #     body: [
        #       'doc'
        #     ]
        #     content: [
        #       doc('id').eq({key: 'test', other_key: 'other_value')
        #     ]
        #   }
        # ]
        #                                                                                                                                            
        # Ok, I give up the parsing from right to left
        #
        # We have to parse "return" too
        regex:
            anonymous:/^(\s)*function\(([a-zA-Z0-9,\s]*)\)(\s)*{/
            method: /^(\s)*([a-zA-Z]+)\(/ # forEach( merge( filter(

                '}': '{'
                ']': '['


        ### 
        element.type in ['string', 'function', 'var', 'separator', 'anonymous_function', 'object']
        TODO Add array type
        TODO Collapse the query.slice(...)
        
        ###
        extract_data_from_query: (args) =>
            query = args.query
            context = if args.context? then DataUtils.deep_copy(args.context) else {}
