fortran-plugin
fortran-plugin copied to clipboard
Better support of include statements
Thanks for the great plugin! The go to definition (ctrl-click) is a great feature. It would be nice if it understood that some variables are defined in include files. E.g.
sub.f90
subroutine sub
include 'const.inc'
write(*,*) pi
end subroutine
const.inc
real, parameter :: pi = 3.14
Ctrl-click on pi
in sub.f90
and it says that there are no usages/definition in the project. I would expect it to open const.inc
and jump to the line where pi is declared.
I know new code should use modules and the use
statement instead of include files, but older code uses include files because modules were not invented yet.
Hi.
I'm glad that you love the plugin. I suppose that problem is in *.inc
extension. Currently, we don't recognize such files as Fortran files so we don't perform any analysis in them. If all your *.inc
files are Fortran files, you can solve the issue by using file types feature.
Thanks for the quick reply. I forgot to mention that I used File > Settings > File Types to configure *.inc as fixed format Fortran files.
Ok, at first I didn't read the issue carefully, plugin has no support for include statements, that's true.
A couple of questions:
- Do you use CMake to build your project?
- Where included files are located in your case?
Why I'm asking: I'm trying to figure out how to resolve included file. If we are talking about old projects, than there is most probably no CMake there. This means that I have no project model and I can't resolve file precisely. According to https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vna1/index.html there are four places where include files can be located. I can look only in first and last ones. In CMake based projects it should be possible to resolve file precisely, but I'm not sure that it would be easy.
So I need a real use-case to implement patial support of include statements that will cover it.
Do you use CMake to build your project?
yes
Where included files are located in your case?
in the same directory as the main Fortran source files. Test files (in a separate directory) include the .inc files from the main directory.
Thanks for taking the time to look in to this. If it is easier I think just searching through directories that are marked as source directories in IDEA would be sufficient. That is how I currently grep through the include files. Theoretically it is possible to have multiple include files with the same name in different directories, but that would be horrendously confusing so I don't see a need to support it.
I've added support in parser for including absolute and relative files. Includes that require CMake will be difficult to support just as I expected. For now it doesn't really helps with "Find usages" or navigation, but I want to try it in this way, because I've already made a lot of changes in parser and I'm afraid that something will break. I will also add file navigation in include statements before release and maybe completion and move refactoring support