fortran-lang / fortls

fortls - Fortran Language Server
https://fortls.fortran-lang.org/
MIT License
257 stars 41 forks source link

`incl_suffixes` ignored if they do not start with a dot #300

Closed albertziegenhagel closed 1 year ago

albertziegenhagel commented 1 year ago

Describe the bug If I pass include suffixes via --incl_suffixes to fortls that do not start with a dot, they are simply ignored, with no warning whatsoever. This is especially surprising, since the description of the setting in the Modern Fortran VS Code extension lists the defaults without dots (see package.json#L443)

To Reproduce

Having a source repository with

<root>
 |- main.f90
 |- subdir
   |- include.inc

running python -m fortls --debug_rootpath=C:\source\test-fortls --incl_suffixes inc

gives

Testing "initialize" request:
  Root = "C:\source\test-fortls"
[INFO - 12:03:10] fortls - Fortran Language Server 2.13.1.dev172+gc04d2ab.d20230629 Initialized
  Successful!

  Source directories:
    C:\source\test-fortls

but running python -m fortls --debug_rootpath=C:\source\test-fortls --incl_suffixes .inc

gives the correct:

Testing "initialize" request:
  Root = "C:\source\test-fortls"
[INFO - 12:03:13] fortls - Fortran Language Server 2.13.1.dev172+gc04d2ab.d20230629 Initialized
  Successful!

  Source directories:
    C:\source\test-fortls\subdir
    C:\source\test-fortls

Expected behavior

In the order of my personal preference:

  1. It should not matter whether I pass the include suffixes with or without a dot in the beginning
  2. OR I should get a warning when a passed argument is incorrect and ignored
  3. OR The documentation should at least very explicitly state that a dot in the beginning is a mandatory requirement.
albertziegenhagel commented 1 year ago

@gnikit If you too prefer solution 1. as expected behaviors (not requiring the suffixes to start with a dot) I can open a pull request with a fix (I think there is basically just an else missing for the if in

https://github.com/fortran-lang/fortls/blob/c04d2abb12e68da10ac917332cd982528152d26b/fortls/regex_patterns.py#L174

Although I would say the code could use a few other slight improvements. Eg. passing .a.b as suffix will make it look for files ending in ab, since all dots are being removed).

gnikit commented 1 year ago
  1. OR The documentation should at least very explicitly state that a dot in the beginning is a mandatory requirement.

Well it kinda does since it only provides suffixes prefixed via ., see.

IMO the suffixes should not be limited to just file extensions, they could be also globs or any type of string at the end of a file. I can't say I remember why I coded it the src_file_exts function that way, but improvements are always welcome.

Please remember to also add/edit the tests, update the docs and CHANGELOG or allow for maintainer edits in the PR.

grantyuc commented 1 year ago

I have a similar issue.

Having a source repository with

<root>
 |- main.f90
 |- inc
   |- main.inc

But running fortls --debug_rootpath /path/to/root --incl_suffixes .inc gives unexpected result.

Testing "initialize" request:
  Root = "/path/to/root"
[INFO] fortls - Fortran Language Server 2.13.0 Initialized
  Successful!

  Source directories:
    /path/to/root

^^^ The /path/to/root/inc is expected here. In VSCode, the Modern Fortran extension does not parse my .inc files.

Update I realize that the v2.13.0 I am using is released before these discussions, so I need to upgrade to a newer version.