Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preprocessor statements in declarations break parsing #203

Open
rwirth opened this issue Aug 3, 2021 · 2 comments
Open

Preprocessor statements in declarations break parsing #203

rwirth opened this issue Aug 3, 2021 · 2 comments

Comments

@rwirth
Copy link

rwirth commented Aug 3, 2021

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 referenced this issue in fortran-lang/fortls Jan 17, 2022
Fixes Preprocessor statements in declarations break parsing #203
Fixes Preprocessor statements in declarations break parsing #4
@gnikit
Copy link

gnikit commented Jan 17, 2022

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

@gnikit
Copy link

gnikit commented Jan 19, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants