def __init__(self): # If true, gnatinspect is never run. # This should be the case when the LSP support is enabled for Ada: if GPS.Logger("GPS.LSP.ADA_SUPPORT").active: return # Whether we trust that there are no links in the project hierarchy self.trusted_mode = True cross_ref_runtime.create( "Cross references in runtime files", 'boolean', "Index files in the runtime for cross references queries", False) # When we support python, we add support for the --runtime attribute. # This is not supported in GNAT Bench though xml = self.xml xml = xml.replace( "<!-- Runtime_switch support -->", "<arg>%python(cross_references.runtime_switch())</arg>") GPS.parse_xml(xml) GPS.Hook("project_view_changed").add(self.on_project_view_changed) GPS.Hook("compilation_finished").add(self.on_compilation_finished) GPS.Hook("preferences_changed").add(self.on_preferences_changed) GPS.Hook("rsync_finished").add(self.on_rsync_finished) self.gnatinspect_launch_registered = False self.gnatinspect_already_running = False # Initialize self.trusted_mode and other preferences self.on_preferences_changed(None) # An action for the menu item /Build/Recompute Xref Info gs_utils.make_interactive( lambda *args: self.recompute_xref(quiet=False), name="recompute xref info")
def gps_started(self): """ Initializations done after the gps_started hook (add menu) """ # declare local function as action (menu, shortcut, etc.) gps_utils.make_interactive(callback=self.mark_unjustified_code, name='Mark Unjustified Code') gps_utils.make_interactive(callback=self.check_density, name='Check Density') # declare local function as action (menu, shortcut, etc.) gps_utils.make_interactive(callback=self.list_subp_requirements, name='List Subprogram Requirements') gps_utils.make_interactive(callback=self.list_all_requirements, name='List All Requirements') # context menu in editor #gps_utils.make_interactive( # callback=self.reload_file, # name='MBe reload requirements', # contextual='Requirements/Reload') GPS.Hook("project_view_changed").add(self._project_recomputed) GPS.Hook("before_exit_action_hook").add(self._before_exit) GPS.Hook("project_changed").add(self._project_loaded) GPS.Hook("project_saved").add(self._project_loaded) GPS.Completion.register(self._resolver, "ada")
def __init__(self): """ Initialize a new highlighter. It monitors changes in the current context to highlight the entity under the cursor. It is intended that a single entity of this class is created in GPS. """ Location_Highlighter.__init__(self, style=None, context=0) # Cache for some of the preferences self.highlight_entities = None self.highlight_selection = None self.highlight_word = None self.entity = None self.word = None self.styles = { "text": OverlayStyle( name="{}simple".format(MSG_PREFIX), speedbar=True, style=GPS.Style( "Editor ephemeral highlighting simple", False)), "entity": OverlayStyle( name="{}smart".format(MSG_PREFIX), speedbar=True, style=GPS.Style( "Editor ephemeral highlighting smart", False))} self.pref_cache = {} self.current_buffer = None # Words that should not be highlighted. # ??? This should be based on the language GPS.Hook("preferences_changed").add(self._on_preferences_changed) GPS.Hook("location_changed").add_debounce(self.highlight) GPS.Hook("file_closed").add(self.__on_file_closed)
def setup(): """ Create the build-and-run and debug-and-run workflow buttons. """ if not WorkflowButtons.__build_targets_created: targets_def = [[ "Build & Run", "build-and-run", WorkflowButtons.__build_and_run_wf, "gps-run-symbolic" ], [ "Build & Debug", "build-and-debug", WorkflowButtons.__build_and_debug_wf, "gps-debugger-initialize-symbolic" ]] for target in targets_def: workflows.create_target_from_workflow( target_name=target[0], workflow_name=target[1], workflow=target[2], icon_name=target[3], parent_menu='/Build/Project/%s/' % target[0]) WorkflowButtons.__build_targets_created = True WorkflowButtons.__connect_editor_hooks() GPS.Hook('build_mode_changed').add( WorkflowButtons.__on_mode_or_view_changed) GPS.Hook('project_view_changed').add( WorkflowButtons.__on_mode_or_view_changed)
def __connect_hook(self, hook_name): """ Connects a method of the object with a hook, and ensure the function will be called without the hook name as a first parameter. """ pref = getattr(self, hook_name, None) # a bound method if pref: def internal(*args, **kwargs): if args: hook = args[0] args = args[1:] if hook == hook_name: return pref(*args, **kwargs) else: return pref(hook, *args, **kwargs) else: return pref(*args, **kwargs) setattr(self, "__%s" % hook_name, internal) p = getattr(self, "__%s" % hook_name) if hook_name == "context_changed": GPS.Hook(hook_name).add_debounce(p) else: GPS.Hook(hook_name).add(p)
def setup(self): GPS.parse_xml(targets) GPS.Hook("compilation_finished").add(self.on_compilation_finished) GPS.Hook("preferences_changed").add(self.on_preferences_changed) # Initialize trusted_mode and other preferences self.on_preferences_changed(None)
def hook(hook_name, debounced=False): """ This primitive allows the writer of a workflow to connect to a hook once, as if it were a function, and get the parameters of the hook as return values. For example: file = yield hook("buffer_edited") This will wait until the "buffer_edited" hook is triggered, and the file will be stored in the file variable. Result is a list if hook returns several values. """ p = Promise() def hook_handler(hook, *args): GPS.Hook(hook_name).remove(hook_handler) # resolve accepts only one argument, so pass list of args if it longer if len(args) <= 1: p.resolve(*args) else: p.resolve(args) if debounced: GPS.Hook(hook_name).add_debounce(hook_handler) else: GPS.Hook(hook_name).add(hook_handler) return p
def __disconnect_hooks(): """ Disconnect our hook function from the 'file_changed_on_disk' and 'buffer_edited' hooks. """ GPS.Hook('file_changed_on_disk').remove( WorkflowButtons.__on_file_changed) GPS.Hook('buffer_edited').remove(WorkflowButtons.__on_file_changed)
def __connect_hooks(): """ Connect to the 'file_changed_on_disk' and 'buffer_edited' hooks to know if we can skip the 'Build Main' BuildTarget when executing the workflows or not. """ GPS.Hook('file_changed_on_disk').add(WorkflowButtons.__on_file_changed) GPS.Hook('buffer_edited').add(WorkflowButtons.__on_file_changed)
def exit_alias_expansion(): editor.remove_overlay( overlay, editor.beginning_of_buffer(), editor.end_of_buffer() ) editor.remove_all_slave_cursors() GPS.Hook("character_added").remove(on_edit) GPS.Hook("location_changed").remove(on_move)
def __del__(self): self.__source_id = None # Don't try to kill the idle, GPS is quitting self.stop_highlight() GPS.Hook("before_exit_action_hook").remove(self.__before_exit) GPS.Hook("file_closed").remove(self.__on_file_closed) GPS.Hook("source_lines_folded").remove( self.__on_lines_folded_or_unfolded) GPS.Hook("source_lines_unfolded").remove( self.__on_lines_folded_or_unfolded)
def __disconnect_hook(self, hook_name): """ Disconnect a hook connected with __connect_hook. """ p = getattr(self, "__%s" % hook_name, None) if p: GPS.Hook(hook_name).remove(p) p = getattr(self, hook_name, None) if p: GPS.Hook(hook_name).remove(p)
def __del__(self): Location_Highlighter.__del__(self) GPS.Hook("preferences_changed").remove(self.__on_preferences_changed) GPS.Hook("file_edited").remove(self.__on_file_edited) GPS.Hook("file_changed_on_disk").remove(self.__on_file_edited) if GPS.Logger("ENTITIES.SQLITE").active: GPS.Hook("xref_updated").remove(self.__on_compilation_finished) else: GPS.Hook("compilation_finished").remove( self.__on_compilation_finished)
def __init__(self, style): self.__source_id = None # The gtk source_id used for background # or the GPS.Timeout instance self.__buffers = [] # The list of buffers to highlight self.terminated = False self.style = style GPS.Hook("before_exit_action_hook").add(self.__before_exit) GPS.Hook("file_closed").add(self.__on_file_closed) GPS.Hook("source_lines_folded").add(self.__on_lines_folded_or_unfolded) GPS.Hook("source_lines_unfolded").add( self.__on_lines_folded_or_unfolded)
def stop(self): """ Stop highlighting through self """ GPS.Hook("file_edited").remove(self.__do_whole_highlight) GPS.Hook("file_saved").remove(self.__do_whole_highlight) GPS.Hook("file_changed_on_disk").remove(self.__do_whole_highlight) if gobject_available: GPS.Hook("character_added").remove(self.__do_context_highlight) for buffer in GPS.EditorBuffer.list(): if self.must_highlight(buffer) and self.style: self.style.remove(buffer)
def __init__(self): Location_Highlighter.__init__(self, style=None) self.background_color = None self.context = None self.__on_preferences_changed(hook=None) GPS.Hook("preferences_changed").add(self.__on_preferences_changed) GPS.Hook("file_edited").add(self.__on_file_edited) GPS.Hook("file_changed_on_disk").add(self.__on_file_edited) if GPS.Logger("ENTITIES.SQLITE").active: GPS.Hook("xref_updated").add(self.__on_compilation_finished) else: GPS.Hook("compilation_finished").add( self.__on_compilation_finished)
def _commit_amend(self): """ Commit all staged files and add these to the previous commit. """ # ??? Should do nothing if the previous commit has been pushed # already. GPS.Hook('vcs_before_commit').run() p = self._git(['commit', '--amend', '--reuse-message=HEAD'], block_exit=True) status, _ = yield p.wait_until_terminate(show_if_error=True) if status == 0: GPS.MDI.information_popup('Commit successful', 'github-commit-symbolic') GPS.Hook('vcs_refresh').run(False) yield self.async_fetch_status_for_all_files(from_user=False)
def start(self): """ Start highlighting. This is automatically called from __init__, and only needs to be called when you have called stop() first. Do not call this function multiple times. """ GPS.Hook("file_edited").add(self.__do_whole_highlight) GPS.Hook("file_saved").add(self.__do_whole_highlight) GPS.Hook("file_changed_on_disk").add(self.__do_whole_highlight) if gobject_available: GPS.Hook("character_added").add(self.__do_context_highlight) for buf in GPS.EditorBuffer.list(): if self.must_highlight(buf): self.start_highlight(buf)
def __destroy(self, widget): """ Callback on destroy """ if self.refresh_timeout is not None: GLib.source_remove(self.refresh_timeout) self.refresh_timeout = None GPS.Hook("preferences_changed").remove(self.__on_preferences_changed) self.window.destroy()
def __call__(self, fn): def do_work(hook, *args, **kwargs): return fn(*args, **kwargs) do_work.__name__ = fn.__name__ # Reset name for interactive() do_work.__doc__ = fn.__doc__ GPS.Hook(self.name).add(do_work, last=self.last) return do_work
def hook_handler(hook, *args): GPS.Hook(hook_name).remove(hook_handler) # resolve accepts only one argument, so pass list of args if it longer if len(args) <= 1: p.resolve(*args) else: p.resolve(args)
def setup(self): # This plugin makes sense only if GNATcoverage is available. if not self.is_gnatcov_available(): return # Create all custom things that do not require GPS' GUI to be ready # (i.e.: all but menus and hooks). for xml_nodes in ( self.BUILD_MODES, self.GNATCOV_DOCUMENTATION, self.GNATEMU_DOCUMENTATION, ): GPS.parse_xml(list_to_xml(xml_nodes)) # Update the GNATcoverage workflow Build Targets, creating them and # showing/hiding them appropriately. Also fill the custom targets. process = GPS.Process(["gnatcov", "--help"]) help_msg = process.get_result() GPS.parse_xml( list_to_xml(self.BUILD_TARGET_MODELS).format(help=help_msg)) self.update_worflow_build_targets() # Try to retrieve a prebuilt GNATcov runtime from the history global prebuilt_runtime_path prebuilt_runtime_path = GPS.History.get(RUNTIME_PATH_HIST_KEY, most_recent=True) GPS.Hook('compilation_finished').add(self.on_compilation_finished)
def setup(self): # Create an "open Libadalang" action make_interactive(self.get_view, category="Views", name="open Libadalang") GPS.Hook("location_changed").add_debounce( self.location_changed_debounced)
def setup(self): """ When setting up the module, create the associated Build Targets. """ GPS.Hook("debugger_terminated").add(self.debugger_terminated) self.__create_targets_lazily()
def __init__(self, auto_exec=True): """If auto_exec is True, execute the loop automatically when the gps_started callback is called. Otherwise no automatic execution, you'll need to call execute() explicitly""" self.list = [] if auto_exec: GPS.Hook('gps_started').add(self.execute)
def gps_started(self): """ Initializations done after the gps_started hook (add menu) """ # declare local function as action (menu, shortcut, etc.) gps_utils.make_interactive( callback=self.text_report, name='Unit Statistics Text Report') gps_utils.make_interactive( callback=self.html_report, name='Unit Statistics HTML Report') GPS.Hook("project_view_changed").add(self._project_recomputed) GPS.Hook("before_exit_action_hook").add(self._before_exit) GPS.Hook("project_changed").add(self._project_loaded) GPS.Hook("project_saved").add(self._project_loaded)
def on_exit(self, status, command): if status != 0: GPS.Logger("XREF").log("gnatinspect returned with status %s" % status) r.gnatinspect_completed() if not r.gnatinspect_already_running: GPS.Hook("xref_updated").run()
def __init__(self): self.widget = None # The view self.runs = {} # The saved runs, indexed by their timestamp self.reload_from_disk() def on_project_changed(*args): self.reload_from_disk() GPS.Hook("project_view_changed").add(on_project_changed)
def gps_started(self): """ Initializations done after the gps_started hook """ gps_utils.make_interactive(callback=self.show_python_library, filter='Python file', name='display python library help') gps_utils.make_interactive(callback=self.reload_file, name='reload python file', filter='Python file', contextual='Python/Import & Reload') gps_utils.make_interactive(callback=self.indent_on_new_line, name="Python Auto Indentation", filter='Python file') self.pydoc_proc = None GPS.Hook("project_view_changed").add(self._project_recomputed) GPS.Hook("before_exit_action_hook").add(self._before_exit)
def on_activate(self, context, choice, choice_index): decl = context.methods_list[choice_index].body() GPS.Hook('open_file_action_hook').run( decl.file(), decl.line(), # line decl.column(), # column decl.column(), # column_end 1, # enable_navigation 1, # new_file 0, # force_reload 1, # focus decl.file().project())