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

Some annotations are very tall #241

Open
LiamPattinson opened this issue Dec 16, 2024 · 1 comment
Open

Some annotations are very tall #241

LiamPattinson opened this issue Dec 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@LiamPattinson
Copy link
Collaborator

As mentioned in #240 which introduces the missing-default-case rule, some annotations can take up a lot of space in the terminal. Another example is old-style-array-literal:

program p
  implicit none

  real :: x(40)

  x(:) = (/ &
    0, &
    1, &
    2, &
    ...
    37, &
    38, &
    39 /)

  write (*,*) x

end program p

When running fortitude check --select=old-style-array-literal with the default output format, the entire array is annotated. Ideally, the annotation should be truncated or abbreviated in some way.

@LiamPattinson LiamPattinson added the enhancement New feature or request label Dec 16, 2024
@ZedThree
Copy link
Member

Turns out there's a fold argument that does this, except it also snips any context:

modified   fortitude/src/message/text.rs
@@ -213,7 +213,8 @@ impl Display for MessageCodeFrame<'_> {
         let snippet = Level::None.title("").snippet(
             Snippet::source(&source_text)
                 .line_start(start_index.get())
-                .annotation(Level::Error.span(start_byte..end_byte).label(&code)),
+                .annotation(Level::Error.span(start_byte..end_byte).label(&code))
+                .fold(true),
         );
 
         let snippet_with_footer = if let Some(s) = self.message.suggestion() {

gives output like:

test.f90:84:5: T003 [*] 'implicit none' set on the enclosing module
   |
84 |     implicit none
   |     ^^^^^^^^^^^^^ T003
   |
   = help: Remove unnecessary 'implicit none'

fortitude/resources/test/fixtures/bugprone/B001.f90:4:3: B001 Missing default case may not handle all values
  |
4 | /   select case(foo)
5 | |   case(1)
... |
8 | |     print*, "two"
9 | |   end select
  | |____________^ B001
  |
  = help: Add 'case default'

We could selectively turn it on if the range spans more than some number of lines. Maybe we can add the context as additional snippets? I'm not sure if it merges them or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants