Seeking submissions: Adding snippets to Modern Fortran VS Code

I am looking to extend the number of available code snippets offered via Modern Fortran in VS Code and I would be interested if the Community has any suggestions. Do you use any snippets in your workflows that you would like to see in the extension? Do you find yourself often typing boilerplate code?

Post your Fortran code or the JSON snippet format directly in this thread to be considered for addition. Vote by liking any existing submissions you would like to see being added.

1 Like

Opening a file, reading the whole content via a formatted stream and closing it, might be a candidate

But I guess adding it to stdlib might be a better choice.

1 Like

(Re)allocating a rank 1 array using move_alloc is something I implement once in a while

2 Likes

Maybe it is easier to search for common tasks which are done when developing Fortran projects and require writing extensive boilerplate code. If there is some pattern in the boilerplate it might be useful to extract it as snippet for VSCode.

An example might be a type with user-defined constructor

type :: a_type
end type a_type

interface a_type
  module procedure :: new_a_type
end interface a_type

contains

pure function new_a_type() result(new)
  type(a_type) :: new
end function new_a_type

The actual members of the type as well as the function arguments and the copying over would also be part of the boilerplate but maybe more difficult to put in a snippet.

1 Like

I haven’t forgotten about this…I have set a reminder for tomorrow to actually implement the work in vscode. Thanks for providing all the recommendations.

Yeah, that would be ideal. It just depends on the style of Fortran you use. My PhD research was almost entirely procedural style Fortran so I’m afraid recommendations from personal experiences would not be very “modern” and OOP.

Maybe we can add some fypp snippets? @aradi what do you think? Do you have any suggestions?

That is absolutely doable. We just wouldn’t want to add to many tab-navigated fields for the user to browse, since they might get confused.

Another thing I was thinking of adding is a “class” i.e. user type with procedures, for initialisation and finalizing.