PFLOTRAN + VSCode + Modern Fortran langauge server?

21 views
Skip to first unread message

Hansol Suh

unread,
Apr 22, 2025, 6:45:25 PMApr 22
to pflotran-dev
Hi all.

I was told that VSCode would be a good platform for developing PFLOTRAN, but

I have been having some issues getting language server working with VSCode.

Namely, it appears either fortls or Modern Fortran cannot pick up PETSc's include headers.

For starter:
1. I have petsc build, have $PETSC_DIR, $PETSC_ARCH properly defined, and was able to successfully build PFLOTRAN and run some tests.
2. Both VSCode and YouCompleteMe were not able to pick up on petsc's include.[*]

Normally, I would imagine that this is my fault, and totally independent of how PFLOTRAN/Petsc interacts with each other, but I saw this on fortls manual page [**], and made me wonder whether there are some secret PFLOTRAN/Petsc specific config that I am missing?

My current configurations on VSCode are
`--include_dirs=$PETSC_DIR/include/**`,
`--pp_suffixes=' .h, .f, .f90'`

Regardless, it would be great if i could get some sneak peek at seasons PFLOTRAN developers settings.


Thanks,
Hansol.




[*]:  When I open, say, `pm_richards.f90`, it says 
`"message": "petsc/finclude/petscsnes.h: No such file or directory",`, and all hell ensues.
```
{ "pp_defs": { "HAVE_PETSC": "" "Mat": "type(tMat)" } }
```

[***] Modern Fortran Output on VSCode:
["INFO" - 5:21:56 PM] Extension Name: Modern Fortran
["INFO" - 5:21:56 PM] Extension Version: 3.2.0
["INFO" - 5:21:56 PM] Linter set to: gfortran
["INFO" - 5:21:56 PM] Formatter set to: findent
["INFO" - 5:21:56 PM] Autocomplete set to: fortls
["INFO" - 5:21:56 PM] Hover set to: fortls
["INFO" - 5:21:56 PM] Symbols set to: fortls
["INFO" - 5:21:56 PM] using linter: gfortran located in: /opt/homebrew/bin/gfortran
["INFO" - 5:21:56 PM] Linter.arguments:
-Wall
-ffree-line-length-none
-ffixed-line-length-none
["INFO" - 5:21:56 PM] Linter.include:

["INFO" - 5:21:56 PM] Fortran Language Server
["INFO" - 5:21:57 PM] Initialising Language Server for workspace: /Users/hansolsuh/code/pflotran/src/pflotran/pm_richards.F90 with command-line options: --enable_code_actions, --hover_signature, --use_signature_help, --lowercase_intrinsics, --nthreads=4, --incremental_sync, --incl_suffixes, F,F77,F90,F95,F03,F08,FOR,FPP,.H, --source_dirs, ./**, /Users/hansolsuh/code/petsc_pflotran/petsc/include, --pp_suffixes, .h, .f, .f90, --include_dirs, /Users/hansolsuh/code/petsc_pflotran/petsc/include/**
[INFO - 17:22:02] fortls - Fortran Language Server 3.2.2 Initialized


[****] Other than the inability to find petscsnes.h, all the other errors say something like,
say, for Line 330 of `pm_richards.F90`,  it says that all of its inputs are "No matching declaration foudnf ro argument ...XYZ..."




Glenn Hammond

unread,
May 13, 2025, 12:29:52 PMMay 13
to pflotran-dev

Hansol,

 

I apologize for not responding sooner. This email was never delivered to my PNNL address.

 

I have never been able to get fortls to work reliably with VSCode. I know that Piyoosh was able to use it somewhat on his MacBook. Perhaps he can provide insight on the setup.

 

Glenn

Piyoosh Jaysaval

unread,
May 13, 2025, 6:40:10 PMMay 13
to pflotr...@googlegroups.com
Hansol, 

It handles PFLOTRAN's internal subroutines/functions correctly, but has trouble resolving PETSc-specific headers and interfaces.

Piyoosh 

--
You received this message because you are subscribed to the Google Groups "pflotran-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pflotran-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pflotran-dev/e20978e6-a2a5-4d50-bd78-18ba353b70a7n%40googlegroups.com.

Hansol Suh

unread,
May 13, 2025, 7:12:17 PMMay 13
to pflotr...@googlegroups.com
Thanks all.

I finally got fortls to work with PFLOTRAN (with Vim Youcompleteme + ALE).

It turns out there is some "bug" on fortls - see https://github.com/fortran-lang/fortls/issues/481

Following is what I posted on petsc discord:

-------------------------------------------------------------------------------------------------------------------------------------------------------------
My journey: (for future reference)
  1. fortls’s regex has weird “bug” (it works correctly when run on small example.py, but behaves “incorrectly” in actualy fortls package”)
    1. I had to change fortls/regex_patterns.py:133to be [ ]*#[ ]*include[ ]*([\”\w\./]* (added backslash. It couldn’t parse “petsc/finclude/petscsnes.h”)
    2. pp_defs
      1. fortls cannot memorize all the globals in $PETSC_DIR/$PETSC_ARCH/include/petscconf.h, so you have to manually define some of them, like PetscInt, Real, PetscErrorCode, etc
        1. But actually addding pp_defs somehow breaks module path? so I had to change $PETSC_DIR/include/petsc/finclude/petscsys.h to be following
        2. Also, for things like SNESConvergedReason, if I changed it in actualy petscsnes.h, it doesn’t work - had to comment it out and paste it in petscsys.h
        ```
      //include/petsc/finclude/petscsys.h#define PetscInt integer4#define PetscErrorCode integer4#define PetscReal real(kind=selected_real_kind(10))#define SNESConvergedReason integer4```
    3. Still doesn’t work
      1. It no longer yells at me, but fetching from headers for typechecks and on-the-go error checking doesnt work. (This may be an issue on my part with YCM config, but whatever)
    4. Slow
      1. It doesn’t use nice things like compile_commands.json, but it just parses through all the headers and mod, so on my machine, when I open a new file, it takes around 5s to finish.
I am probably missing something, but looks like even if I were to fix all the issues, I don't think slowness would go-away.
  1. My .fortlsrc:
    { "source_dirs": [ "./**", "/Users/hansolsuh/code/petsc_pflotran/petsc/include/**", "/Users/hansolsuh/code/petsc_pflotran/petsc/arch_3.21.6_pflotran/include/**", "/Users/hansolsuh/code/petsc_pflotran/petsc/src/vec/f90-mod", "/Users/hansolsuh/code/petsc_pflotran/petsc/src/mat/f90-mod", "/Users/hansolsuh/code/petsc_pflotran/petsc/src/ksp/f90-mod", "/Users/hansolsuh/code/petsc_pflotran/petsc/src/snes/f90-mod", "/Users/hansolsuh/code/petsc_pflotran/petsc/src/dm/f90-mod", "/Users/hansolsuh/code/petsc_pflotran/petsc/src/ts/f90-mod", "/Users/hansolsuh/code/petsc_pflotran/petsc/src/sys/f90-mod", ], "include_dirs": [ "/Users/hansolsuh/code/petsc_pflotran/petsc/arch_3.21.6_pflotran/include/**", "/Users/hansolsuh/code/petsc_pflotran/petsc/include/**", ], "pp_suffixes": [".h", ".F90"], //you need .F90 otherwise it will just abort "lowercase_intrinsics": true, }

  2. .vimrc
    let g:ycm_language_server =[] let g:ycm_language_server += [ \ { 'name': 'fortls', \ 'filetypes': [ 'fortran' ], \ 'cmdline': [ 'fortls', '--notify_init', '--hover_signature', '--hover_language', 'fortran', '--use_signature_help', '--debug_full_result', '--debug_log', '--config', '/Users/hansolsuh/code/pflotran/src/pflotran/.fortlsrc'], \ }, \ ]

-------------------------------------------------------------------------------------------------------------------------------------------------------------

Also, after getting this to work, I found that fortls has difficulty parsing "more complex" defines, like in `input_aux.F90`
`#if defined(PETSC_HAVE_FORTRAN_GET_COMMAND_ARGUMENT) || PETSC_VERSION_GE(3,21,0)` By and large, fortls cannot remember all the variables in `petscconf.h` - but manually putting them in `pp_defs` somehow breaks everything.
So I need something stupid like ```
// $PETSC_DIR/include/petscsys.h #define PetscInt integer4 #define PetscErrorCode integer4 #define PetscReal real(kind=selected_real_kind(10)) #define SNESConvergedReason integer4
```
to have minimally working LSP.


At any rate, I am more-or-less okay with my current state of Fortran LSP on Vim


You received this message because you are subscribed to a topic in the Google Groups "pflotran-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pflotran-dev/tX09_0bFuW0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pflotran-dev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pflotran-dev/CA%2BiB7fZAzKAaeRompMnvq6yoHdmyNPi5rNHUWkfnSJu956%2B4nw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages