Example #1
0
    def process(self, start, end):  # overriding
        ed = start.buffer()

        s = GPS.FileLocation(ed.file(), start.line(), start.column())
        e = GPS.FileLocation(ed.file(), end.line(), end.column())

        for entity_name, ref in self._refs:
            if s <= ref <= e:
                u = entity_name.decode("utf-8").lower()
                s2 = ed.at(ref.line(), ref.column())

                try:
                    e2 = s2 + (len(u) - 1)
                except Exception:
                    # An invalid location ?
                    continue

                b = ed.get_chars(s2, e2).decode("utf-8").lower()
                if b == u:
                    self.highlighted += 1
                    self.style.apply(s2, e2)

                elif self.context > 0:
                    for c in range(1, self.context + 1):
                        # Search after original xref line (same column)
                        try:
                            s2 = GPS.EditorLocation(ed,
                                                    ref.line() + c,
                                                    ref.column())
                            e2 = s2 + (len(u) - 1)
                            b = ed.get_chars(s2, e2).decode("utf-8").lower()
                            if b == u:
                                self.highlighted += 1
                                self.style.apply(s2, e2)
                                break

                            # Search before original xref line
                            s2 = GPS.EditorLocation(ed,
                                                    ref.line() - c,
                                                    ref.column())
                            e2 = s2 + (len(u) - 1)
                            b = ed.get_chars(s2, e2).decode("utf-8").lower()
                            if b == u:
                                self.highlighted += 1
                                self.style.apply(s2, e2)
                                break
                        except Exception:
                            # An invalid location ?
                            continue
Example #2
0
def test_driver():
    f = GPS.File('to_be_called.adb')
    sf = GPS.File('second.adb')
    tf = GPS.File('third.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/1)")
    gps_assert(
        GPS.Locations.list_locations(
            "References for To_Be_Called (to_be_called.adb:1)", tf.path), [],
        "wrong list of locations (1/2)")
    GPS.Project.set_scenario_variable('VALUE', 'third')
    GPS.Project.recompute()

    GPS.EditorBuffer.get(sf).close()
    yield wait_tasks()

    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)", tf.path), [
                GPS.FileLocation(tf, 1, 6), '[reference] with To_Be_Called;',
                GPS.FileLocation(tf, 4, 4), '[call] To_Be_Called;'
            ], "wrong list of locations (2/1)")
    gps_assert(
        GPS.Locations.list_locations(
            "References for To_Be_Called (to_be_called.adb:1)", sf.path), [],
        "wrong list of locations (2/2)")
Example #3
0
    def parse_trace_file(self, filename):
        """ parse the trace file as a list of "file:line" information and
            return the result
        """

        lines = []
        if os.path.isfile(filename):
            with open(filename, 'r') as f:
                for line in f:
                    sl = line.split(':')
                    if len(sl) >= 2:
                        lines.append(
                            GPS.FileLocation(GPS.File(sl[0]), int(sl[1]), 1))
        return lines
Example #4
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 #5
0
File: test.py Project: AdaCore/gps
def test_driver():
    initial = count_object("File")

    x = GPS.FileLocation(GPS.File("main.adb"), 1, 1)
    gps_assert(count_object("File"), initial,
               "A FileLocation should not increase the number of File")
    f = x.file()
    gps_assert(count_object("File"), initial + 1,
               "A File should have been created")
    # Deleting the FileLocation should not affect the File
    del x
    gc.collect()
    gps_assert(count_object("File"), initial + 1,
               "File should not be affected by the deletion of FileLocation")
    del f
    gc.collect()
    gps_assert(count_object("File"), initial,
               "Python should have the last ref to File")
Example #6
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 #7
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')

    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)")