         # Write the suggestion in the code mirror
         write_suggestion: (args) =>
             suggestion_to_write = args.suggestion_to_write
-            @codemirror.setValue @query_first_part+suggestion_to_write+@query_last_part
+            if suggestion_to_write[suggestion_to_write.length-1] is '(' and @count_not_closed_brackets('(') >= 0
+                @codemirror.setValue @query_first_part+suggestion_to_write+')'+@query_last_part
+            else
+                @codemirror.setValue @query_first_part+suggestion_to_write+@query_last_part
     
             @codemirror.focus() # Useful if the user used the mouse to select a suggestion
             @codemirror.setCursor


            @current_highlighted_suggestion = -1
            @.$('.suggestion_name_list').empty()

            # Codemirror return a position given by line/char.
            # We need to retrieve the lines first
            query_lines = @codemirror.getValue().split '\n'
            # Then let's get query before the cursor
            query_before_cursor = ''
            if @codemirror.getCursor().line > 0
                for i in [0..@codemirror.getCursor().line-1]
                    query_before_cursor += query_lines[i] + '\n'
            query_before_cursor += query_lines[@codemirror.getCursor().line].slice 0, @codemirror.getCursor().ch

            # Get query after the cursor
            query_after_cursor = query_lines[@codemirror.getCursor().line].slice @codemirror.getCursor().ch
            if query_lines.length > @codemirror.getCursor().line+1
                query_after_cursor += '\n'
                for i in [@codemirror.getCursor().line+1..query_lines.length-1]
                    if i isnt query_lines.length-1
                        query_after_cursor += query_lines[i] + '\n'
                    else
                        query_after_cursor += query_lines[i]
            @query_last_part = query_after_cursor

            # Initialize @current_element, which tracks what the user typed before they hit TAB (to auto-complete).
            # Tracking this helps us let the user loop over all the suggestions available for the fragment they typed (and go back to the fragment).
            @current_element = ''

            stack = @extract_data_from_query
                query: query_before_cursor
                position: 0

            result =
                status: null

            last_char_is_white: /.*(\s+)$/
        stop_char: # Just for performance (we look for a stop_char in constant time - which is better than having 3 and conditions) and cleaner code
            opening:
                '(': ')'
                '{': '}'
                '[': ']'
            closing:
                ')': '(' # Match the opening character
                '}': '{'
