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

Allow user to overwrite line-length flags for gfortran linter #924

Merged
merged 2 commits into from
Jun 22, 2023

Conversation

albertziegenhagel
Copy link
Contributor

Currently, the code appends -ffree-line-length-none and -ffixed-line-length-none by default to the argument list when invoking gfortran as linter. While it is possible to overwrite the line-length by setting fortls.maxLineLength, this does only allow to set the same value for both, free-form as well es fixed-form Fortran code. What I need is to keep the common default values (72 for fixed-form and 132 (or none) for free-form Fortran).

A comment in the code at src/lint/provider.ts#L554 states that it should be possible to overwrite those defaults by setting them explicitly in extraArgs, but this does not currently work. The reason is that the default arguments are pushed to the argument list after the user provided arguments. Hence the defaults will always overwrite the user provided flags.

The proposed fix here is to put the default arguments before the user provided flags. This way, if a user puts -ffixed-line-length-X or -ffree-line-length-X into extraArgs, these will always overwrite the defaults.

If there is any other preferred way to solve this issue, just let me know and I will update the PR. I choose the current approach because it seemed to be the least invasive change and the comment in the code made me feel that this was actually the desired behavior in the first place.

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Merging #924 (3485ae0) into main (fc0419d) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #924      +/-   ##
==========================================
+ Coverage   83.58%   83.60%   +0.01%     
==========================================
  Files          12       12              
  Lines        2303     2305       +2     
  Branches      205      205              
==========================================
+ Hits         1925     1927       +2     
  Misses        373      373              
  Partials        5        5              
Impacted Files Coverage Δ
src/lint/provider.ts 81.78% <100.00%> (+0.05%) ⬆️

Copy link
Member

@gnikit gnikit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good, nice catch. Can you also update the CHANGELOG and add a comment in the source-code about why we use unshift there.

I think this warrants a more robust fix in the future, but it looks good for now.

@gnikit gnikit linked an issue Jun 21, 2023 that may be closed by this pull request
1 task
Currently, the default line length arguments for the gfortran linter are appended AFTER the users extraArgs. Since in gfortran, the last occurrence of an argument that is passed multiple times will be taken, the default line length arguments will always overwrite what a user has explicitly set in extraArgs.

By prepending the default line length arguments instead, a user should now have the possibility to overwrite the default.
@albertziegenhagel
Copy link
Contributor Author

Can you also update the CHANGELOG and add a comment in the source-code about why we use unshift there.

Done.

I think this warrants a more robust fix in the future, but it looks good for now.

Yes, that was my impression as well. If you have any specific idea how this should be handled, let me know and I would be glad to create a subsequent PR.

@gnikit
Copy link
Member

gnikit commented Jun 22, 2023

Thanks @albertziegenhagel for the PR.

The more robust way will be to add a separate diagnostic option in fortls, propagate that option to vscode, and if an option that overrides the fortls line length diagnostics (, or linter defaults) is specified in the extraArgs then replace that option.

@gnikit gnikit merged commit e02a6b9 into fortran-lang:main Jun 22, 2023
3 checks passed
@albertziegenhagel albertziegenhagel deleted the fix-line-length-flags branch June 22, 2023 12:48
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

Successfully merging this pull request may close these issues.

bug: line length default args not overridable by extraArgs
2 participants