hansec / fortran-language-server

Fortran Language Server for the Language Server Protocol
MIT License
294 stars 57 forks source link

Non standard variable types e.g. PETSc not recognised as variables #185

Closed gnikit closed 3 years ago

gnikit commented 3 years ago

Hi

I have noticed that when a variable type, like Mat or PC from PETSc is used as an input argument to a subroutine or a function or even a local variable, the language server fails to recognise it all together as a variable

module multigrid

  use petsc

  implicit none
  subroutine DestroyMultigrid(prec)
    PC, intent(inout):: prec

    PetscErrorCode ierr
    PCType pctype
    PC subprec

    call PCGetType(prec, pctype, ierr)
    if (pctype==PCCOMPOSITE) then
      ! destroy the real mg
      call PCCompositeGetPC(prec, 0, subprec, ierr)
      ! destroy the internal mg
      call PCCompositeGetPC(prec, 1, subprec, ierr)
      call DestroyInternalSmoother()
    end if

  end subroutine DestroyMultigrid

end module multigrid
gbogopolsky commented 3 years ago

Hello,

I had the same question and I managed to find more info about this in another issue, with a functional workaround: https://github.com/hansec/fortran-language-server/issues/115#issuecomment-506767486

I simply added the PETSc types that I needed. They are now recognized as variables of PETSCINT type for example.
Just a caveat, the syntax coloration of the :: is not done for those cas, but it is good enough for my use.

Parsing the header files for type definition would be a better solution, but I don't know where the work on this feature is.

gnikit commented 3 years ago

Hi @gbogopolsky,

Thank you for the suggestion and the issue link, it is a substantial improvement from before. However, I cannot help but wonder if we could automate the parsing of the preprocessor directives by just including the Fortran header files holding these definitions. I might have a play with that idea in the near future and report any meaningful progress.

Until then, I am closing this issue. Thanks again.