hansec / fortran-language-server

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

Preprocessor statements in declarations break parsing #203

Open rwirth opened 3 years ago

rwirth commented 3 years ago

My project contains a lot of declarations like this:

REAL &
#ifdef HAVE_CONTIGUOUS
, CONTIGUOUS &
#endif
:: & 
var1(:), &
var2(:)

The variables var1 and var2 do not get recognized by fortls and I do not get a hover. The debug log shows fortls returning null results:

DEBUG:fortls.jsonrpc:RECV {"jsonrpc":"2.0","id":10,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///[...].f90"},"position":{"line":115,"character":12}}}
DEBUG:fortls.langserver:REQUEST 10 textDocument/hover
DEBUG:fortls.jsonrpc:SEND {"jsonrpc":"2.0","id":10,"result":null}

Preprocessing is activated for .f90 files.

I have temporarily fixed this by replacing the preprocessor directives with a string of spaces of equal length when performing the output_file.append in preprocess_file. This seems to work but I do not know if it breaks something else.

gnikit commented 2 years ago

BTW this has now been fixed in fortls and will soon be released for download with PyPi in version 2.0.0

gnikit commented 2 years ago

Actually @rwirth , this is not entirely fixed. If the variable definition spans multiple lines and there are preprocessor directives inside it, the preprocessor directives are now ignored. The reason why I chose to do that is because currently we would have to create a second preprocessor parser to evaluate #if.. conditionals whenever we "get a line" inside the existing preprocessor parser.

So instead of doing that, I will at some point sit down and implement the preprocessor similarly to the rest of the Fortran objects.

you can find the solution in v2.0.0 of fortls e.g. pip install fortls --upgrade