Example #1
0
def run_test():
    # Set an editor read only
    b1 = GPS.EditorBuffer.get(GPS.File("foo.adb"))
    b1.set_read_only(True)
    expected1 = b1.get_chars()

    # Do a renaming on a second editor
    b2 = GPS.EditorBuffer.get(GPS.File("bar.adb"))
    b2.current_view().goto(b2.at(7, 16))
    expected2 = b2.get_chars()

    yield idle_modal_dialog(lambda: GPS.execute_action("rename entity"))
    new_name_ent = get_widget_by_name("new_name")
    new_name_ent.set_text("Bye")
    dialog = get_window_by_title("Renaming entity")
    # Don't allow the permission to change
    check = get_button_from_label("Make files writable", dialog)
    check.set_active(False)
    get_stock_button(dialog, Gtk.STOCK_OK).clicked()
    yield timeout(500)

    # A dialog reporting an error should be opened, reply no to it
    error_dialog = get_window_by_title(
        "Refactoring - rename Hello to Bye raises errors")
    GPS.Console().write(str(error_dialog))
    get_button_from_label("Undo", error_dialog).clicked()
    yield wait_idle()

    gps_assert(b1.get_chars(), expected1,
               "The read only buffer should not be modified")
    gps_assert(b2.get_chars(), expected2,
               "The writable buffer should be restored")
Example #2
0
def run_test():
    # Open main.adb and check that 'copy_base_file_name' works
    buf = GPS.EditorBuffer.get(GPS.File("main.adb"))
    GPS.execute_action("copy_base_file_name")
    clipboard_contents = GPS.Clipboard().contents()
    gps_assert(clipboard_contents[GPS.Clipboard().current()],
               "main.adb",
               "copy_base_file_name not working on focused editors")

    # Close the editor and select main.adb in the Project view
    # and check that 'copy_file_name' works
    explorer = get_widget_by_name("Project Explorer Tree")
    windows = Gtk.Window.list_toplevels()

    explorer.grab_focus()
    select_in_tree(explorer, column=1, key="main.adb")
    GPS.execute_action("copy_file_name")
    clipboard_contents = GPS.Clipboard().contents()
    gps_assert(clipboard_contents[GPS.Clipboard().current()],
               GPS.File(os.path.join(GPS.pwd(), "main.adb")).path,
               "copy_file_name not working on files in the Project view")

    # Check that 'copy_file_name' works on directories from the
    # Project view
    select_in_tree(explorer, column=1, key=".")
    GPS.execute_action("copy_file_name")
    clipboard_contents = GPS.Clipboard().contents()
    gps_assert(clipboard_contents[GPS.Clipboard().current()],
               GPS.File(os.path.join(GPS.pwd())).path,
               "copy_file_name not working on dirs in the Project view")
Example #3
0
def run_test():
    buf = GPS.EditorBuffer.get(GPS.File('main.adb'))
    buf.current_view().goto(buf.at(5, 10))

    GPS.execute_action('goto declaration')
    yield hook("language_server_response_processed")

    current_buf = GPS.EditorBuffer.get()
    gps_assert(current_buf.file(), GPS.File('hello_world.ads'),
               "'goto declaration' did not open the right file")

    current_loc = current_buf.main_cursor().location()
    gps_assert(current_loc, current_buf.at(3, 33),
               "'goto declaration' did not jump to right location")

    GPS.execute_action('goto body')
    yield hook("language_server_response_processed")

    current_buf = GPS.EditorBuffer.get()
    gps_assert(current_buf.file(), GPS.File('hello_world.adb'),
               "'goto body' did not open the right file")

    current_loc = current_buf.main_cursor().location()
    gps_assert(current_loc, current_buf.at(5, 33),
               "'goto body' did not jump to right location")
Example #4
0
File: test.py Project: AdaCore/gps
def run_test():
    buf_1 = GPS.EditorBuffer.get(GPS.File("main.adb"))
    yield wait_tasks()

    # Add a special line
    buf_1.add_special_line(3, "Special line")

    # Fold the main procedure in main.adb
    buf_1.at(3, 2).block_fold()

    # Rename the Print method
    buf_2 = GPS.EditorBuffer.get(GPS.File("a.ads"))
    buf_2.current_view().goto(buf_2.at(7, 16))
    yield wait_idle()

    yield idle_modal_dialog(lambda: GPS.execute_action("rename entity"))
    new_name_ent = get_widget_by_name("new_name")
    new_name_ent.set_text("Pri")
    dialog = get_window_by_title("Renaming entity")
    yield idle_modal_dialog(
        lambda: get_stock_button(dialog, Gtk.STOCK_OK).clicked())
    yield timeout(500)

    gps_assert(
        buf_1.get_chars(buf_1.at(6, 1),
                        buf_1.at(6, 1).end_of_line()).strip(),
        "Pri (ObjA);",
        "Renaming dit not work correctly in folded block",
    )
Example #5
0
def edit_dg(dg, source_filename, line, for_subprogram, in_external_editor):
    global highlighting, expanded_code_marks

    # If we are showing the dg in an external editor, simply open this editor
    # and jump to the line
    if in_external_editor:
        buf = GPS.EditorBuffer.get(GPS.File(dg))
        loc = buf.at(1, 1)
        try:
            (frm, to) = loc.search("^-- " + repr(line) + ":", regexp=True)
            if frm:
                buf.current_view().goto(frm.forward_line(1))
        except Exception:
            pass

        return

    clear_dg(source_filename)

    srcbuf = GPS.EditorBuffer.get(GPS.File(source_filename))

    if for_subprogram:
        (block_first,
         block_last) = subprogram_bounds(srcbuf.current_view().cursor())
    else:
        (block_first, block_last) = (0, 0)

    # Read the text of the dg file
    f = open(dg)
    txt = f.read()
    f.close()

    current_code = []
    current_line = 1
    lines = 0

    for line in txt.split("\n"):
        if line.startswith("-- "):
            if current_code:
                if (block_first == 0
                        or (block_first < current_line < block_last)):
                    mark = srcbuf.add_special_line(current_line + 1,
                                                   "\n".join(current_code),
                                                   highlighting)

                    # Add mark to the list of marks

                    mark_num = (mark, len(current_code))

                    if source_filename in expanded_code_marks:
                        expanded_code_marks[source_filename] += [mark_num]
                    else:
                        expanded_code_marks[source_filename] = [mark_num]

            current_line = int(line[3:line.find(":")])
            current_code = []
        else:
            if line != "":
                lines += 1
                current_code.append(line)
Example #6
0
def run_test():
    buf = GPS.EditorBuffer.get(GPS.File('main.adb'))
    buf.current_view().goto(buf.at(5, 10))

    # wait LSP responses has been processed to have folding information
    if GPS.LanguageServer.is_enabled_for_language_name("Ada"):
        yield wait_tasks(other_than=known_tasks)

    GPS.execute_action('goto declaration')
    yield wait_language_server('textDocument/declaration')

    current_buf = GPS.EditorBuffer.get()
    gps_assert(current_buf.file(), GPS.File('hello_world.ads'),
               "'goto declaration' did not open the right file")

    current_loc = current_buf.main_cursor().location()
    gps_assert(current_loc, current_buf.at(3, 33),
               "'goto declaration' did not jump to right location")

    # wait LSP responses has been processed to have folding information
    if GPS.LanguageServer.is_enabled_for_language_name("Ada"):
        yield wait_tasks(other_than=known_tasks)

    GPS.execute_action('goto body')
    yield wait_language_server('textDocument/implementation')

    current_buf = GPS.EditorBuffer.get()
    gps_assert(current_buf.file(), GPS.File('hello_world.adb'),
               "'goto body' did not open the right file")

    current_loc = current_buf.main_cursor().location()
    gps_assert(current_loc, current_buf.at(5, 33),
               "'goto body' did not jump to right location")
Example #7
0
File: test.py Project: AdaCore/gps
def run_test():
    GPS.Preference("LSP-Limit-Formatting").set(True)

    buf = GPS.EditorBuffer.get(GPS.File("main.cpp"))
    init_buf = buf.get_chars(include_hidden_chars=False)
    buf.current_view().goto(buf.at(2, 1))
    send_key_event(GDK_TAB)
    yield wait_idle()
    gps_assert(different_lines(buf.get_chars(include_hidden_chars=False),
                               init_buf),
               1,
               "Too many different lines without selection")
    gps_assert(buf.get_chars(include_hidden_chars=False),
               MAIN_EXPECTED,
               "Wrong formatting without selection")

    buf = GPS.EditorBuffer.get(GPS.File("foo.cpp"))
    init_buf = buf.get_chars(include_hidden_chars=False)
    buf.select(buf.at(2, 3), buf.at(4, 8))
    send_key_event(GDK_TAB)
    yield wait_idle()
    gps_assert(different_lines(buf.get_chars(include_hidden_chars=False),
                               init_buf),
               3,
               "Too many different lines with selection")
    gps_assert(buf.get_chars(include_hidden_chars=False),
               FOO_EXPECTED,
               "Wrong formatting with selection")
Example #8
0
def remove_ce(ce):
    for file in ce:
        if GPS.File(file).language() == "ada":
            buf = GPS.EditorBuffer.get(GPS.File(file))
            remove_ce_special_lines(buf)
            overlay = get_trace_overlay(buf)
            buf.remove_overlay(overlay)
Example #9
0
def test_driver():
    GPS.Preference("Debugger-Pending-Breakpoints").set(True)

    # Set a breakpoint in the Ada library
    buf = GPS.EditorBuffer.get(GPS.File("p.adb"))
    buf.current_view().goto(buf.at(8, 1))
    yield wait_idle()
    GPS.execute_action("debug set line breakpoint")
    yield wait_tasks()

    # Build and debug the C main: the Ada library is not loaded
    # at this stage so the breakpoint should be marked as pending
    GPS.execute_action("Build & Debug Number 1")
    yield hook('debugger_started')
    yield wait_idle()

    # Run the debugger and verify that we reach the breakpoint
    debug = GPS.Debugger.get()
    debug.send("run")
    yield timeout(300)

    gps_assert(debug.current_file, GPS.File("p.adb"),
               "The pending breakpoint has not been reached")
    gps_assert(debug.current_line, 8,
               "The pending breakpoint has not been reached")
Example #10
0
def test_driver():
    adb_file = GPS.File("main.adb")
    ads_file = GPS.File("main.ads")

    # Open ADB file, do modifications, check for diagnostics.

    adb_buffer = GPS.EditorBuffer.get(adb_file)

    location = GPS.EditorLocation(adb_buffer, 3, 16)
    adb_buffer.insert(location, " ")
    yield timeout(diagnosticTimeout)
    gps_assert(GPS.Locations.list_locations("Diagnostics", adb_file.path),
               [GPS.FileLocation(adb_file, 3, 17), "Missing ';'"],
               "Unexpected diagnostics (assertion 1)")

    # Save and close ADB file.

    adb_buffer.save()
    adb_buffer.close()

    # Reopen ADB file and check for diagnostics

    adb_buffer = GPS.EditorBuffer.get(adb_file)

    yield timeout(diagnosticTimeout)
    if diagnosticOnDidOpen:
        gps_assert(GPS.Locations.list_locations("Diagnostics", adb_file.path),
                   [GPS.FileLocation(adb_file, 3, 17), "Missing ';'"],
                   "Unexpected diagnostics (assertion 2)")

    # Undo changes, check for diagnostics

    location = GPS.EditorLocation(adb_buffer, 3, 16)
    adb_buffer.delete(location, location)
    yield timeout(diagnosticTimeout)
    gps_assert(GPS.Locations.list_locations("Diagnostics", adb_file.path), [],
               "Unexpected diagnostics (assertion 3)")

    # Create new file, fill it, save as ADS and check for diagnostics

    ads_buffer = GPS.EditorBuffer.get_new()
    location = ads_buffer.at(1, 1)
    ads_buffer.insert(location, "procedure Main")
    ads_buffer.save(False, ads_file)
    yield timeout(diagnosticTimeout)
    if diagnosticOnDidOpen:
        gps_assert(GPS.Locations.list_locations("Diagnostics", ads_file.path),
                   [GPS.FileLocation(adb_file, 1, 16), "Missing ';'"],
                   "Unexpected diagnostics (assertion 4)")

    # Fix error in ADS file and check for diagnostics

    location = ads_buffer.at(1, 16)
    ads_buffer.insert(location, ";")
    yield timeout(diagnosticOnDidOpen)
    gps_assert(GPS.Locations.list_locations("Diagnostics", adb_file.path), [],
               "Unexpected diagnostics (assertion 5)")
Example #11
0
    def build_and_debug(main_name):
        """
        Generator to debug a program launched in the emulator.
        """

        # STEP 1.0 get main name
        if main_name is None:
            GNATemulator.__error_exit(msg="Main not specified.")
            return

        # STEP 1.5 Build it

        try:
            yield GNATemulator.build(main_name)
        except RuntimeError:
            # Build error, we stop there
            return

        binary = GPS.File(main_name).executable_path.path
        # STEP 2 Switch to the "Debug" perspective To have GNATemu console in
        # the debugger perspective.

        GPS.MDI.load_perspective("Debug")

        # STEP 2 load with Emulator
        debug_port = GPS.Project.root().get_attribute_as_string(
            package="Emulator", attribute="Debug_Port")

        # TODO: remove this fall-back once GNATemulator supports the
        # new 'Debug_Port' attribute (Fabien's task)
        if debug_port == "":
            debug_port = "1234"

        yield GNATemulator.run_gnatemu(
            ["--freeze-on-startup",
             "--gdb=%s" % debug_port, binary])

        log("... done.")

        # STEP 3 launch the debugger
        try:
            debugger_promise = promises.DebuggerWrapper(
                GPS.File(binary),
                remote_target="localhost:" + debug_port,
                remote_protocol="remote")
        except Exception:
            GNATemulator.__error_exit("Could not initialize the debugger.")
            return

        # block execution until debugger is free
        r3 = yield debugger_promise.wait_and_send(block=True)
        if not r3:
            GNATemulator.__error_exit("Could not initialize the debugger.")
            return

        log("... done.")
Example #12
0
def test_driver():
    GPS.EditorBuffer.get(GPS.File("main.adb"))
    GPS.execute_action("gnatcheck file")
    yield wait_tasks(other_than=known_tasks)

    # If GNATcheck succeed to run, we should have a message in the
    # Locations view complaining about the comments style
    msgs = GPS.Message.list(file=GPS.File("main.adb"),
                            category="Coding Standard violations")
    gps_assert(len(msgs), 1, "No gnatcheck messages in the Locations")
Example #13
0
File: test.py Project: AdaCore/gps
def run_test():
    test_buf = GPS.EditorBuffer.get(GPS.File("test.ads"))
    GPS.execute_action("Lock or unlock current editor")

    test_buf.current_view().goto(test_buf.at(3, 1).end_of_line())
    GPS.execute_action("backward delete")
    gps_assert(test_buf.is_modified(), True,
               "Locked editors should still be editable")
    GPS.execute_action("undo")

    main_buf = GPS.EditorBuffer.get(GPS.File("main.adb"))
    main_buf.current_view().goto(main_buf.at(5, 10))

    GPS.execute_action("goto declaration")
    yield wait_language_server("textDocument/declaration", "Ada")

    gps_assert(
        len(test_buf.views()), 2,
        "Opened view for test.ads is locked: another view should have " +
        "been opened")

    test_buf.views()[0].destroy()

    GPS.MDI.get("test.ads").raise_window()
    yield wait_idle()

    GPS.execute_action("backward delete")
    GPS.execute_action("Compile File")
    yield wait_tasks(other_than=known_tasks)

    msgs = GPS.Message.list(category="Builder results")
    gps_assert(len(msgs), 1, "We should have an error after compiling")

    gps_assert(
        len(test_buf.views()), 2,
        "Opened view for test.ads is locked: another view should have " +
        "been opened after appearance of compilation error in " + "Locations")

    test_buf.views()[0].destroy()

    GPS.execute_action("Global Search in context: file names")
    yield wait_idle()

    field = get_widget_by_name("global_search")
    field.set_text("test.ads")
    yield timeout(1000)

    send_key_event(GDK_DOWN)
    send_key_event(GDK_RETURN)
    yield wait_idle()

    gps_assert(
        len(test_buf.views()), 2,
        "Opened view for test.ads is locked: another view should have " +
        "been opened when selecting test.ads via the omnisearch")
def on_gps_start(hook):
    # Disable launching of browser on exit
    GPS.Preference("Doc-Spawn-Browser").set(False)

    GPS.Docgen.register_tag_handler(ScreenshotTagHandler())
    GPS.Docgen.register_tag_handler(ExampleTagHandler())
    GPS.Docgen.register_css(GPS.File("gtkada.css"))
    GPS.Docgen.register_main_index(GPS.File("gtkada_rm/groups.html"))

    GPS.Project.root().generate_doc(True)
    GPS.Timeout(500, wait_doc)
Example #15
0
def test_driver():
    # Add recognized breakpoints
    main = GPS.File(MAIN)
    buf1 = GPS.EditorBuffer.get(main)
    add_breakpoint(buf1, 7)  # At line 8 when the debugger starts
    add_breakpoint(buf1, 11)
    add_breakpoint(buf1, 12)

    # Add a unrecognized breakpoint
    buf2 = GPS.EditorBuffer.get(GPS.File(ALONE))
    add_breakpoint(buf2, 3)

    # Open the Breakpoints view and check that the breakpoints has been set
    GPS.execute_action("open breakpoints editor")
    yield wait_for_mdi_child('Breakpoints')
    view = GPS.MDI.get("Breakpoints")
    tree = get_widgets_by_type(Gtk.TreeView, view.pywidget())[0]
    model = tree.get_model()
    check_breakpoints(model,
                      [MAIN, MAIN, MAIN, ALONE],
                      [7, 11, 12, 3],
                      "adding breakpoints via the editors")

    # Launch the debugger, modify the breakpoints list and quit
    GPS.execute_action("Build & Debug Number 1")
    yield hook('debugger_started')

    debug = GPS.Debugger.get()
    debug.break_at_location(main, 4)
    yield wait_until_not_busy(debug)
    debug.send("run")
    yield wait_until_not_busy(debug)

    check_breakpoints(model,
                      [MAIN, MAIN, MAIN, MAIN],
                      [8, 11, 12, 4],
                      "starting the debugger")
    gps_assert(debug.current_line, 4,
               "The debugger should stop at the newly created breakpoint")

    # Deleting breakpoints should update the list
    debug.send("delete 2 3")
    yield wait_until_not_busy(debug)
    check_breakpoints(model,
                      [MAIN, MAIN],
                      [8, 4],
                      "deleting breakpoints via the debugger")

    # Closing the debugger should add the unrecognized breakpoint
    debug.close()
    check_breakpoints(model,
                      [MAIN, MAIN, ALONE],
                      [8, 4, 3],
                      "closing the debugger")
Example #16
0
def run_test():
    ls_pid = get_language_server_pid()
    gps_assert(ls_pid is not None, True,
               "couldn't get the language server PID")

    # Kill the language server
    os.kill(ls_pid, signal.SIGKILL)

    # Wait for the language server to relaunch
    yield hook("language_server_started")

    # Give the language server the time to process all the events
    # (init, didChangeConfiguration, didOpenFile, etc)
    # because otherwise the call to "lanugage_server_response_processed"
    # below will catch one of those.
    yield timeout(1000)

    # Get the new language server PID
    new_ls_pid = get_language_server_pid()
    gps_assert(new_ls_pid is not None, True,
               "couldn't get the new language server PID after kill")
    gps_assert(ls_pid != new_ls_pid, True, "the language server wasn't killed")

    # Verify the functionality of the new language server
    buf = GPS.EditorBuffer.get(GPS.File('main.adb'))
    buf.current_view().goto(buf.at(5, 10))

    # wait LSP responses has been processed to have folding information
    if GPS.LanguageServer.is_enabled_for_language_name("Ada"):
        yield wait_tasks(other_than=known_tasks)

    GPS.execute_action('goto declaration')
    yield hook("language_server_response_processed")

    current_buf = GPS.EditorBuffer.get()
    gps_assert(current_buf.file(), GPS.File('hello_world.ads'),
               "'goto declaration' did not open the right file")

    # Verify that there isn't the error message in the console
    gps_assert("had to be restarted more than" in GPS.Console().get_text(),
               False,
               "the error message about language server showed unexpectedly")

    # Now try to kill the language server too many times
    for j in range(5):
        ls_pid = get_language_server_pid()
        if ls_pid:
            os.kill(ls_pid, signal.SIGKILL)
        yield timeout(200)

    # Verify that there is the error message in the console
    gps_assert("had to be restarted more than" in GPS.Console().get_text(),
               True,
               "the error message about language server showed unexpectedly")
Example #17
0
    def __emu_debug_wf(self, main_name):
        """
        Workflow to debug a program under the emulator.
        """

        # STEP 1.0 get main name
        if main_name is None:
            self.__error_exit(msg="Main not specified.")
            return

        # STEP 1.5 Build it
        log("Building Main %s..." % main_name)
        builder = promises.TargetWrapper("Build Main")
        r0 = yield builder.wait_on_execute(main_name)
        if r0 is not 0:
            self.__error_exit(msg="Build error.")
            return
        binary = GPS.File(main_name).executable_path.path

        log("... done.")

        # STEP 2 Switch to the "Debug" perspective To have GNATemu console in
        # the debugger perspective.

        GPS.MDI.load_perspective("Debug")

        # STEP 2 load with Emulator
        debug_port = GPS.Project.root().get_attribute_as_string(
            package="Emulator", attribute="Debug_Port")

        # TODO: remove this fall-back once GNATemulator supports the
        # new 'Debug_Port' attribute (Fabien's task)
        if debug_port == "":
            debug_port = "1234"

        self.run_gnatemu(
            ["--freeze-on-startup",
             "--gdb=%s" % debug_port, binary])

        log("... done.")

        # STEP 3 launch the debugger
        debugger_promise = promises.DebuggerWrapper(
            GPS.File(binary),
            remote_target="localhost:" + debug_port,
            remote_protocol="remote")

        # block execution until debugger is free
        r3 = yield debugger_promise.wait_and_send(block=True)
        if not r3:
            self.__error_exit("Could not initialize the debugger.")
            return

        log("... done.")
Example #18
0
def test_driver():
    GPS.EditorBuffer.get(GPS.File(FOO))
    GPS.EditorBuffer.get(GPS.File(BAR))
    cur = GPS.MDI.current()
    gps_assert(BAR in cur.name(), True, "Wrong focused MDI initially")
    # Button 9 is bounded to "move to previous tab"
    GPS.send_button_event(window=cur.pywidget().get_window(),
                          type=Gdk.EventType.BUTTON_PRESS,
                          button=9)
    GPS.process_all_events()
    gps_assert(FOO in GPS.MDI.current().name(), True,
               "The action was not triggered")
Example #19
0
def run_test():
    buf = GPS.EditorBuffer.get(GPS.File("main.adb"))
    buf.current_view().goto(buf.at(3, 32))

    GPS.execute_action("goto declaration or body")
    yield wait_language_server("textDocument/definition", "Ada")

    current_buf = GPS.EditorBuffer.get()
    current_loc = current_buf.current_view().cursor()

    gps_assert(current_buf.file(), GPS.File("test.ads"), "Wrong file opened")
    gps_assert(current_loc.line(), 3,
               "Wrong location after 'goto declaration'")
Example #20
0
def interactive_dependency_path():
    """
    Explains one of the reasons why a file depends on another one (through
    a chain of with clauses or #include statements).
    """

    try:
        (file1, file2) = GPS.MDI.input_dialog("Show file dependency path",
                                              "From File", "To File")
    except:
        return

    print_dependency_path(GPS.File(file1), GPS.File(file2))
Example #21
0
def on_gps_started():
    buf_bb = GPS.EditorBuffer.get(GPS.File("bb.adb"))
    buf_a = GPS.EditorBuffer.get(GPS.File("a.adb"))
    yield wait_tasks(other_than=known_tasks)

    # Retrieve the "Window" menu items for all the displayed
    # views
    menu = get_widget_by_name("gtkada-mdi-children-menu")
    dump = [get_widgets_by_type(Gtk.Label, x)[0].get_label() \
            for x in WidgetTree(menu) if \
            isinstance(x, Gtk.MenuItem) and x.get_label() is None]

    gps_assert(dump, EXPECTED,
               "The 'Window' menu items are not correctly sorted")
Example #22
0
def run_test():
    b1 = GPS.EditorBuffer.get(GPS.File("my_class.hh"))
    buf = GPS.EditorBuffer.get(GPS.File("main.cpp"))
    yield wait_tasks()
    # timeout to let clangd indexing the files
    yield timeout(200)
    buf.current_view().goto(buf.at(7, 17))
    yield wait_idle()

    GPS.execute_action("find all references")
    yield hook("language_server_response_processed")
    yield wait_idle()

    gps_assert(dump_locations_tree(), expected)
Example #23
0
File: test.py Project: AdaCore/gps
def test_driver():
    GPS.Preference("LSP-Ada-Diagnostics").set(True)
    GPS.execute_action("Restart ada language server")
    yield hook('language_server_started')

    yield wait_tasks()
    f = GPS.File('to_be_called.adb')
    sf = GPS.File('second.adb')
    b = GPS.EditorBuffer.get(f)

    b.find_all_refs(b.at(1, 17), True)
    yield hook("language_server_response_processed")
    yield wait_tasks()

    gps_assert(
        GPS.Locations.list_locations(
            "References for To_Be_Called (to_be_called.adb:1)", sf.path),
        [GPS.FileLocation(sf, 1, 6), '[reference] with To_Be_Called;',
         GPS.FileLocation(sf, 4, 4), '[call] To_Be_Called;'],
        "wrong list of locations (1)")
    GPS.Locations.remove_category(
        "References for To_Be_Called (to_be_called.adb:1)")
    yield wait_tasks()

    #  Reopen project

    GPS.execute_action('/File/Open Recent Projects/test.gpr')
    yield wait_tasks()

    b = GPS.EditorBuffer.get(f)

    b.find_all_refs(b.at(1, 17), True)
    yield hook("language_server_response_processed")
    yield wait_tasks()

    gps_assert(
        GPS.Locations.list_locations(
            "References for To_Be_Called (to_be_called.adb:1)", sf.path),
        [GPS.FileLocation(sf, 1, 6), '[reference] with To_Be_Called;',
         GPS.FileLocation(sf, 4, 4), '[call] To_Be_Called;'],
        "wrong list of locations (2)")

    l = GPS.EditorLocation(b, 1, 16)
    b.insert (l, " ")
    yield timeout(1000)

    gps_assert(GPS.Locations.list_locations("Diagnostics", f.path),
               [GPS.FileLocation(f, 1, 17), 'Invalid token, ignored',
                GPS.FileLocation(f, 1, 18), "Missing ';'"],
               "Unexpected diagnostics")
Example #24
0
def run_test():
    GPS.EditorBuffer.get(GPS.File("a.ads"))
    buf = GPS.EditorBuffer.get(GPS.File("main.adb"))
    buf.current_view().goto(buf.at(4, 14))
    yield wait_idle()

    yield idle_modal_dialog(lambda: GPS.execute_action("rename entity"))
    new_name_ent = get_widget_by_name("new_name")
    new_name_ent.set_text("Object_Type_Aa")
    dialog = get_window_by_title("Renaming entity")
    yield idle_modal_dialog(
        lambda: get_stock_button(dialog, Gtk.STOCK_OK).clicked())

    yield wait_idle()
Example #25
0
def run_test():
    buf = GPS.EditorBuffer.get(GPS.File("hello.h"))
    yield wait_idle()

    buf.current_view().goto(buf.at(12, 13))
    yield hook('location_changed', debounced=True)
    yield timeout(1000)

    # Verify that navigation from 'hello.h' works fine and that
    # it correctly jumps to the corresponding c++ implementation
    # file.

    GPS.execute_action("goto declaration")
    yield wait_language_server("textDocument/declaration", "C")
    yield wait_until_true(lambda: GPS.EditorBuffer.get().file() == GPS.File("hello.cpp"))

    current_buf = GPS.EditorBuffer.get()
    current_loc = current_buf.current_view().cursor()
    gps_assert(current_buf.file(), GPS.File('hello.cpp'),
               "'goto declaration' did not open the right file")
    gps_assert(current_loc.line(),
               12,
               "'goto declaration' did not got the right line")
    gps_assert(current_loc.column(),
               24,
               "'goto declaration' did not got the right column")

    buf = GPS.EditorBuffer.get(GPS.File("hi.h"))
    buf.current_view().goto(buf.at(3, 8))
    yield hook('location_changed', debounced=True)
    yield timeout(1000)

    # Verify that navigation from 'hi.h' works fine and that
    # it correctly jumps to the corresponding C implementation
    # file.

    GPS.execute_action("goto declaration")
    yield wait_language_server("textDocument/declaration", "C")
    yield timeout(1000)

    current_buf = GPS.EditorBuffer.get()
    current_loc = current_buf.current_view().cursor()
    gps_assert(current_buf.file(), GPS.File('hi.c'),
               "'goto declaration' did not open the right file")
    gps_assert(current_loc.line(),
               4,
               "'goto declaration' did not got the right line")
    gps_assert(current_loc.column(),
               17,
               "'goto declaration' did not got the right column")
Example #26
0
def show_ce(ce):
    for file in ce:
        if GPS.File(file).language() == "ada":
            first = next(iter(ce[file]), None)
            if first:
                first_sloc = GPS.FileLocation(GPS.File(file), int(first), 1)
                buf = GPS.EditorBuffer.get(first_sloc.file())
                goto_location(first_sloc)
                overlay = get_trace_overlay(buf)
                for line in ce[file]:
                    text = get_str_indent(buf, int(line)) + "--  " + \
                           get_ce_text_for_line(ce[file][line])
                    add_ce_special_line(buf, int(line), text)
                    buf.apply_overlay(overlay, buf.at(int(line), 1),
                                      buf.at(int(line), 1))
Example #27
0
File: test.py Project: TurboGit/gps
def test_driver():
    GPS.Preference("Src-Editor-Fold-With-Use-Blocks").set(2)
    GPS.Preference("Src-Editor-Fold-Comment-reg1").set("testing")

    buf = GPS.EditorBuffer.get(GPS.File("main.adb"))
    yield wait_idle()
    gps_assert(buf.debug_dump_all_lines(),
               ['[0] el:1 (2)',
                '[1] el:2',
                '[1] el:3',
                '[0] el:4',
                '[0] el:5',
                '[0] el:6',
                '[0] el:7',
                '[0] el:8',
                '[0] el:9',
                '[0] el:10',
                '[0] el:11',
                '[0] el:12',
                '[0] el:13',
                '[0] el:14',
                '[0] el:15',
                '[0] el:16 (2)',
                '[1] el:17',
                '[1] el:18',
                '[0] el:19'],
               "line contents wrong after folding")
Example #28
0
File: test.py Project: AdaCore/gps
def run_test():
    yield wait_tasks()
    GPS.Preference("Smart-Completion-Mode").set("3")
    GPS.Preference("Completion-Filter-Mode").set("Strict")
    buf = GPS.EditorBuffer.get(GPS.File("main.adb"))
    view = buf.current_view()
    view.goto(buf.at(5, 1).end_of_line())
    yield wait_idle()

    for ch in ".Te":
        send_key_event(ord(ch))
        yield timeout(100)

    # Verify that the completion window is there
    pop_tree = get_widget_by_name("completion-view")
    model = pop_tree.get_model()
    yield wait_until_true(
        lambda: model.get_value(model.get_iter_first(), 0) != "Computing...")

    gps_assert(pop_tree is not None, True,
               "The completion window should be open at that point")

    # Verify that the invisible 'Do_Nothing' subprogram is listed after
    # the visible one
    gps_assert(dump_tree_model(pop_tree.get_model(), LABEL_COLUMN),
               ['Text_IO'], "We should only match Text_IO in strict mode.")
Example #29
0
    def edit(self):
        if self.ruleseditor:
            # Already opened
            return

        prev_cmd = self.gnatCmd
        self.updateGnatCmd()

        if self.gnatCmd == "":
            return

        # gnat check command changed: we reinitialize the rules list
        if prev_cmd != self.gnatCmd or self.rules is None:
            self.rules = get_supported_rules(self.gnatCmd)

        # we retrieve the coding standard file from the project
        for opt in GPS.Project.root().get_attribute_as_list(
            "default_switches", package="check", index="ada"
        ):
            res = re.split("^\-from\=(.*)$", opt)
            if len(res) > 1:
                self.rules_file = GPS.File(res[1])

        self.ruleseditor = rulesEditor(self.rules, self.rules_file)
        self.ruleseditor.connect('response', self.onResponse)
Example #30
0
    def async_fetch_status_for_all_files(self):
        _re = re.compile(
            '(?P<file>[^@@]+)(?P<sep>@@)?(?P<rev>[^\s]*)(\n|$)')

        with self.set_status_for_all_files() as s:
            p = self._cleartool(['ls', '-short', '.'])
            while True:
                line = yield p.wait_line()
                if line is None:
                    break

                GPS.Logger("CLEARCASE").log(line)
                m = _re.search(line)
                if m:
                    # ??? These are just (bad) guesses for now
                    status = GPS.VCS2.Status.UNMODIFIED
                    rev = m.group('rev')
                    if rev.contains('CHECKEDOUT'):
                        status = GPS.VCS2.Status.MODIFIED
                    elif m.group('sep') == '':
                        status = GPS.VCS2.Status.UNTRACKED
                    elif rev == '':
                        status = GPS.VCS2.Status.IGNORED

                    s.set_status(
                        GPS.File(m.group('file')),
                        0,
                        rev,
                        '')  # repo revision