hansec / fortran-language-server

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

Error during parsing #207

Open vickysharma0812 opened 2 years ago

vickysharma0812 commented 2 years ago

Thank you very much for FLS and its support in VS Code. I am using FLS-v1.12.0

I use Fortran module in my project.

If the name of the module is IntVector_Method.F90 Then the name of submodules are IntVector_Method@submodule1.F90, IntVector_Method@submodule2.F90, and so on.

I receive following error from FLS.

Initialization failed for file "/home/vikassharma/Dropbox/easifem/easifem-base/src/submodules/IntVector/src/IntVector_Method@getMethod.F90": Error during parsing

How can remove this error?

Regards Vikas

gnikit commented 2 years ago

Hi @vickysharma0812 could you provide a Minimal Working Example so that the issue can be replicated?

vickysharma0812 commented 2 years ago

Hello @gnikit Sorry for the late response.

Please find the attached directory. It also contains the screen shot of problem.

fls_vikas_issue.zip Regards Vikas

vickysharma0812 commented 2 years ago

@gnikit I want to ask whether FLS supports SUBMODULE feature of Modern Fortran?

Regards Vikas

gnikit commented 2 years ago

So both the fortran language server and the Modern Fortran extension support submodules, as far as I know at least. I had a look at your example and I am not entirely convinced that it is compilable code. Would you mind elaborating a bit how you compile and what are you trying to accomplish?

On a separate matter, fortls should not be failing catastrophically like it currently is. The traceback reads

Traceback (most recent call last):
  File "~/pip-dev/fortls/langserver.py", line 1264, in update_workspace_file
    ast_new = process_file(file_obj, True, pp_defs=self.pp_defs, include_dirs=self.include_dirs)
  File "~/pip-dev/fortls/parse_fortran.py", line 1538, in process_file
    new_smod = fortran_submodule(file_ast, line_number, obj_info.name, ancestor_name=obj_info.parent)
  File "~/pip-dev/fortls/objects.py", line 753, in __init__
    self.base_setup(file_ast, line_number, name)
  File "~/pip-dev/fortls/objects.py", line 538, in base_setup
    self.FQSN = self.name.lower()
AttributeError: 'NoneType' object has no attribute 'lower'

This is most definitely a bug which is triggered by using a space character between the base module's name and the right parenthesis in the submodule definition i.e.

This breaks

submodule(baseModule ) submodule1

This works

submodule(baseModule) submodule1
vickysharma0812 commented 2 years ago

So both the fortran language server and the Modern Fortran extension support submodules, as far as I know at least.

Yes, your are right here. I face no problem with Modern Fortran extension. I don't know much about FLS.

I had a look at your example and I am not entirely convinced that it is compilable code. Would you mind elaborating a bit how you compile and what are you trying to accomplish?

The process of compiling the code is given below.

Step-1: Compile foo_module.F90, it will create .mod and .smod files.

gfortran -c foo_module.F90
├── call_foo.F90
├── foo_module.F90
├── foo_module.mod   <--------
├── foo_module.o <------
├── foo_module.smod <-------
├── foo_module@submodule1.F90
├── foo_module_submodule2.F90
└── Screenshot from 2021-10-02 23-07-24.pngfg

Step-2: Compile submodules, it will create

gfortran -c foo_module@submodule1.F90
gfortran -c foo_module_submodule2.F90

Output:

├── call_foo.F90
├── foo_module.F90
├── foo_module.mod
├── foo_module.o
├── foo_module.smod
├── foo_module@submodule1.F90
├── foo_module@submodule1.o <---------------
├── foo_module@submodule1.smod <--------------
├── foo_module_submodule2.F90
├── foo_module@submodule2.smod <--------------
├── foo_module_submodule2.o <--------------
└── Screenshot from 2021-10-02 23-07-24.png

Step:3 compile call_Foo.F90

gfortran -c call_foo.F90 -I.

Output

.
├── call_foo.F90
├── call_foo.o <-----------
├── foo_module@display.smod
├── foo_module.F90
├── foo_module.mod
├── foo_module.o
├── foo_module.smod
├── foo_module@submodule1.F90
├── foo_module@submodule1.o
├── foo_module@submodule1.smod
├── foo_module_submodule2.F90
├── foo_module_submodule2.o
└── Screenshot from 2021-10-02 23-07-24.png

Linking:

gfortran -o test.out call_foo.o foo_module@submodule1.o foo_module_submodule2.o foo_module.o 

Executing:

./test.out

Output

testing :: hello::world
testing :: hello::world
vickysharma0812 commented 2 years ago

@gnikit thank you for responding.

Would you mind elaborating a bit how you compile and what are you trying to accomplish?

In my project I keep the header definition in modules and implementations in submodules.

Regards Vikas

gnikit commented 2 years ago

@vickysharma0812 did you try removing the trailing whitespace between the base module foo_module and the closing parenthesis )?

gnikit commented 2 years ago

I am not sure what I was doing last night and I couldn't compile your MWE, thanks for the instructions all seems to work on my end. Try the fix I mentioned, for the time being at least. I will have a look when I get some time.

BTW as a general note you mind want to incorporate a formatter into your workflow findent and fprettify are good IMO and can be installed through Python's pip

vickysharma0812 commented 2 years ago

@gnikit Thank you for your message. Your trick works well 👍🏼 💯

I have installed findent and fprettify

Can I ask what do they do?

Regards Vikas

gnikit commented 2 years ago

@vickysharma0812

Your trick works well 👍🏼 Glad to hear it

I have installed findent and fprettify Can I ask what do they do?

They are formatters, so they make your code easier to read and look pretty findent and fprettify you only need one of the too. I simply mentioned them because the bug you stumbled upon was due to formatting.

vickysharma0812 commented 2 years ago

@gnikit Thanks, I have uninstall findent, and kept only fprettify.

gnikit commented 2 years ago

@vickysharma0812 I have gone ahead and issued a fix for this under a dev version of fortls.

JHenneberg commented 2 years ago

@gnikit: It seems you are frequently updating fortls on your side. Is there any chance that you are gonna release your own version over python? I guess you tried to communicate with hansec to merge your development? Sry for beeing offtopic.

gnikit commented 2 years ago

Hi @JHenneberg, I tried contacting hansec to update this repo instead of making a fork but I suspect that he is extremely busy with work that's why I went ahead and released the dev version of fortls under the name fortls in PyPi which you can install by pip install fortls. I think I updated the README on my fork yesterday with install instructions etc.

Given that it has been a while since all of this happened and a lot of changes have occured in the codebase, the fork has now diverged substantially from the main fortran-language-server repository which means it is unlikely I will be opening another PR in future to incorporate the changes from dev to master.

JHenneberg commented 2 years ago

@gnikit I see. Great I will give your version a try. Overlooked the install instruction probably. Thanks for your effort.