hansec / fortran-language-server

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

Help with using fortls (in vscode) #173

Open mathomp4 opened 4 years ago

mathomp4 commented 4 years ago

All,

I decided to try out VSCode with fortls today and when I tried it on my code, I got this from the VSCode...uh...bottom terminal/problems/debug thing? Not sure what it's called, but this was in the Output tab:

[Error - 7:14:34 PM] Server initialization failed.
  Message: Error sending result: '(<fortls.parse_fortran.fortran_file object at 0x1088bd4c0>, None)'. Reason: 'RecursionError('maximum recursion depth exceeded while pickling an object')'
  Code: -32603 
[object Object]

I did see #100 which seems to be like what this is, but #100 is closed so I'm not sure. Any ideas on what I might be doing wrong? I'm new to even VSCode so any help is nice (perhaps this is in the wrong repo?).

JHenneberg commented 4 years ago

Hey,

Can you give a minimal example?

mathomp4 commented 4 years ago

@JHenneberg Well, if I clone one of the projects I work on:

git clone https://github.com/GEOS-ESM/MAPL.git

and then open that folder in Code and then open, say, base/MAPL_Base.F90, I get:

[Error - 2:48:14 PM] Server initialization failed.
  Message: Error sending result: '(<fortls.parse_fortran.fortran_file object at 0x10a08c940>, None)'. Reason: 'RecursionError('maximum recursion depth exceeded while pickling an object')'
  Code: -32603 
[object Object]
JHenneberg commented 4 years ago

for now I can confirm I am getting the same error so it is not your specific machine. I would guess it is a problem with the precompiler includes which are causing a circular structure.

Edit:

When you add a .fortls for example like this to your main folder it works

{
  "source_dirs": ["base", "include", "tests", "shared"],
  "pp_suffixes": [".H", ".h"],
  "debug_log": false
}
hansec commented 3 years ago

Hi @mathomp4, thanks for the report. I have been able to track down the issue, which appears to be related to handling the macros in base/MAPL_EsmfRegridder.F90. In particular, there is a problem with the handling of semi-colons in the inline if statements. For the _VERIFY macro for example, which is defined as

#define _VERIFY(A)   if(  A/=0) then; if(present(rc)) rc=A; PRINT *, Iam, __LINE__; return; endif

we can expand it on multiple lines as

if(  A/=0) then
  if(present(rc)) rc=A; PRINT *, Iam, __LINE__; return
endif

and that middle inline if statement is tripping things up since currently the parser crudely treats semi-colons by inserting line breaks. I will try work on better handling of semi-colons, which should fix this. If you want a quick fix in the meantime you can replace these macros with all "then" and "endif" closed if statements. For example the _VERIFY macro would become

#define _VERIFY(A)   if(  A/=0) then; if(present(rc)) then rc=A; PRINT *, Iam, __LINE__; return; endif; endif

Obviously, the solution to "change your code" isn't great when it is working fine but figured I'd let you know as a quick workaround. You can also exclude the file base/MAPL_EsmfRegridder.F90 from parsing, but of course that has disadvantages as well.