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

Syntax Highlighting Errors when Diffing - Fixed Format Fortran #19684

Open
smf007 opened this issue May 11, 2022 · 8 comments
Open

Syntax Highlighting Errors when Diffing - Fixed Format Fortran #19684

smf007 opened this issue May 11, 2022 · 8 comments
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail issue/workaround it is or has a workaround type/bug

Comments

@smf007
Copy link

smf007 commented May 11, 2022

Description

The chroma library had added a fixed format fortran syntax highlighter back in version v0.9.2, which gitea started using as of v1.15.0-RC1. The fortran fixed format syntax highlighting works for displaying files in gitea, however it is broken when displaying a diff of changes.

This can be see using the try.gitea portal:

The syntax highlighting is correct
https://try.gitea.io/test1765/fortran_test/src/branch/main/fortran_fixed.f

The syntax highlighting is incorrect when doing a diff
https://try.gitea.io/test1765/fortran_test/commit/228401fa1860d7aea71f3511937e49ee39d10938

Gitea Version

Tried both 1.16.4, 1.16.7

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

See https://try.gitea.io/test1765/fortran_test/commit/228401fa1860d7aea71f3511937e49ee39d10938

Git Version

No response

Operating System

ROCKY 8.5 (RHEL 8.5)

How are you running Gitea?

Used pre-built binaries for Linux x64, running on ROCKY Linux 8.5.

Database

No response

@wxiaoguang

This comment was marked as outdated.

@wxiaoguang

This comment was marked as outdated.

@wxiaoguang
Copy link
Contributor

Another test shows that the problem is related to github.com/alecthomas/[email protected]/lexers/f/fortran_fixed.go, which is used by inline diff highlighter

If you rename the file from test.f to test.f90 (use lexers/f/fortran.go), then the highlight in diff view is correct.

@wxiaoguang wxiaoguang added the type/upstream This is an issue in one of Gitea's dependencies and should be reported there label Jun 13, 2022
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Jun 13, 2022

Workaround, either:

  • use *.f90
  • [or] set highlight.mapping in app.ini to force the *.f use Fortran instead of FortranFixed lexer.

@wxiaoguang wxiaoguang added issue/workaround it is or has a workaround and removed type/upstream This is an issue in one of Gitea's dependencies and should be reported there labels Jun 13, 2022
@smf007
Copy link
Author

smf007 commented Jun 17, 2022

Workaround, either:

* use `*.f90`

* [or] set `highlight.mapping` in app.ini to force the `*.f` use `Fortran` instead of `FortranFixed` lexer.

I can confirm that overriding the highlight mapping makes the diff more usable.

Looking at this more closely though, the fixed format highlighting performed by the library is itself incorrect regardless of using fortranfixed or fortran. Fortranfixed is not resolving comments as actual comments. This can be seen in the example, lines 1-5 should be greyed out as comments, but are not https://try.gitea.io/test1765/fortran_test/src/branch/main/fortran_fixed.f So my original statement above that the fixed format highlighting was correct is actually false.

@wxiaoguang
Copy link
Contributor

There is a tricky thing in Gitea.

When doing whole file rendering, the extension name is not respected, instead, Gitea will guess what's the language of the source file by its content, so even if the ext name is .f, the full file view can still be rendered correctly like .f90

However, when Gitea is doing inline diff, it's done line by line without the guess, and only use the ext name as the language, then FortranFixed is used for .f, the rendered result is not ideal.

@smf007
Copy link
Author

smf007 commented Oct 26, 2022

Seems I forgot to update this issue. I had done some work upstream in Chroma for the parsing of fortran.

646 & 648 were included in Chroma 2.3.0, and 647 is in master awaiting a version tag.

Chroma 2.3.0 has been merged into Gitea 1.18.0 branch.

As the demo site is kept up to date, I need to check if the Chroma 2.3.0 inclusion has resolved most of this issue.

@wxiaoguang
Copy link
Contributor

Is there still any problem? Or should we hard-code *.f as Fortran (but not FortranFixed)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail issue/workaround it is or has a workaround type/bug
Projects
None yet
Development

No branches or pull requests

2 participants