/usr/share/gps/library/gnatfind.py is in gnat-gps-common 6.1.2016-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | """
This script implements a contextual menu to launch the command "gnatfind"
on the selected source entity.
This works only when the project hierarchy consists in a single project.
"""
import GPS
import os.path
import gps_utils
def __on_gnatfind_exit(gprfind_process, status, full_output):
""" Parse the output of the gprfind command and enter it in the
GPS Locations View.
"""
if status == 0:
# Write OK
GPS.Console().write("%s... done.\n" % full_output)
GPS.Locations.parse(
output=full_output,
category="gnatfind %s" % gprfind_process.query,
highlight_category="Search results")
else:
# Raise an error, listing the full output in the Messages
GPS.Console().write("Error with gnatfind:\n %s\n" % full_output,
"error")
@gps_utils.interactive(
'run gnatfind',
contextual='gnatfind %e',
contextual_ref='goto other file',
filter=lambda ctx: hasattr(ctx, 'entity') and ctx.entity() is not None)
def __activate():
context = GPS.contextual_context() or GPS.current_context()
entity = context.entity()
loc = context.location()
buf = GPS.EditorBuffer.get(loc.file())
location = buf.at(loc.line(), loc.column())
entity_name = entity.name()
length = len(entity_name)
# Go to the beginning of the entity, as needed by gnatfind
while not location.starts_word():
location = location.forward_word(-1)
entity_file = os.path.basename(loc.file().name())
entity_line = location.line()
entity_column = location.column()
source_dirs = GPS.Project.root().get_attribute_as_list("source_dirs")
object_dir = GPS.Project.root().get_attribute_as_string("object_dir")
ais = " ".join(["-aI%s" % d for d in source_dirs])
# Create the gnatfind command line
command = "gnatfind -r %s -aO%s %s:%s:%s:%s" % (
ais, object_dir, entity_name, entity_file.split('\\')[-1],
entity_line, entity_column)
# Write the command line in the Messages window
GPS.Console().write(command + "\n")
# Launch the process
proc = GPS.Process(command, on_exit=__on_gnatfind_exit)
proc.query = "%s (%s:%s)" % (entity_name, entity_line, entity_column)
|