-
Notifications
You must be signed in to change notification settings - Fork 4
Intellisense Package
Although the python packages for parsing Fortran modules can be run standalone on specific code files, they can be integrated with emacs for real-time code support during development. Other editors are not supported at the moment. Here are the builtin behaviors once Fortpy and Fortpy-el have been configured correctly.
Fortpy supports real-time updating of code using the source in the buffer. Usually, files are parsed from the file system to determine the code elements and documentation they contain. Depending on the length of the code file, the parse can take between one and five seconds per code file. When minor changes are made to the source code in the buffer, Fortpy will update the in-memory instance of the module's representation without needing to reparse the entire file. It does this using an optimized diff library. Typically, the updates take a few milliseconds to complete.
When a code file is saved, the cached copy in memory becomes invalidated and the file is re-read from disk. A file can also be forced to be reparsed from disk using the fortpy:reparse-buffer-file
command inside of emacs.
If you edit Fortran files over SSH using tramp
inside of emacs, Fortpy will still provide real-time code support. The python library will copy any dependencies from the code libraries you specify in config.xml
to a local temporary folder and then parse them. After parsing them, the temporary files are deleted and the parsed representations are cached via serialization.
By default, Fortpy serializes all modules that it parses onto the file system. The rationale behind this is that usually a single module gets developed over several days. The other modules that it depends on via the use
statement don't change much. When the module is loaded, all its first-level dependency modules are also loaded. When editing via tramp, all these loads require remote copies via SFTP using the SSH session and can take several seconds. Since the files don't change frequently, the cached versions are used if the file modified date has not changed.
In practice (as an example), one module that we tested the isense support on took 10 seconds to parse including all its first-level dependencies. The same operation took less than half a second when they were loaded from the serialized copies on disk. These tests were performed using a local Fortran library. For SSH editing, the performance gains are much larger.
There are three auto-complete operations that are included with Fortpy.
If the cursor sits still for a set amount of time (default: 1 sec), it requests context-specific information for the current cursor location. When the context is analyzed, only the text to the left of the cursor position is used. If there is also text to the right, it will be ignored. The following are common usage scenarios:
- call signatures: when you forget the exact call signature of a method, let the cursor sit for a second to see specific documentation for the current parameter that the cursor is on.
- variable assignments: if a few variables have a common prefix and you don't remember the full name of the one you want. Any matching variables (including CamelCase matches) with their documentation strings are displayed for selection.
- function calls: when assigning values to variables via function calls, typing a few characters will bring up all matching functions with descriptions of what they do from the documentation tags.
In Fortran, members and procedures that belong to user-defined types are accessed using a "%". When "%" is pressed, Fortpy looks at the name of the variable immediately preceding "%" and finds its type information to offer suggestions for possible members or methods to call. As long as each of those members or methods has documentation tags, their descriptions will also be provided.
For procedures inside a user-defined type, Fortpy looks at the actual method in the body of the module
to find the documentation tags. This is also true for procedures that use an alternate name via the syntax procedure, public :: public_name => module_method
.
Brackets are used in Fortran for encapsulating argument lists for subroutine or function calls, specifying indices for selection of subsets of arrays and for logical grouping of arithmetic or logic operations. Fortpy provides isense support for array dimensions and method calls. When you type "(", the symbol immediately preceding the bracket is examined. If it is a valid variable or method, the call signature or dimension data is returned including any documentation tags.