Skip to content

Conversation

@Strum355
Copy link
Contributor

Previously, ranges would be wrong for files indented with tabs or tabs&spaces.

This happened because javac replaces every tab with 8 spaces in the linemap. As this is potentially inconsistent with the source file itself, we adjust for that when building ranges if the line is actually indented with tabs.

As for every tab there are 8 spaces, we remove 7 spaces for every tab to get the correct char offset (note: different to column offset your editor shows)

image

Closes #115 and closes #169

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

The fix looks good. Can we add some test case to reproduce the issue?

We may need to disable javafmt in the minimized project so that we can write tab characters in the source files.

lazy val minimized = project
  .in(file("tests/minimized/.j11"))
  .settings(minimizedSettings)
  .dependsOn(agent, plugin)
+  .disablePlugins(JavaFormatterPlugin)

lazy val minimized8 = project
  .in(file("tests/minimized/.j8"))
  .settings(minimizedSettings, javaToolchainVersion := "8")
  .dependsOn(agent, plugin)
+  .disablePlugins(JavaFormatterPlugin)

lazy val minimized15 = project
  .in(file("tests/minimized/.j15"))
  .settings(minimizedSettings, javaToolchainVersion := "15")
  .dependsOn(agent, plugin)
+  .disablePlugins(JavaFormatterPlugin)

return Optional.empty();
}

return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

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

My brain is not wired anymore for statements, I can only think in expressions.

@Strum355
Copy link
Contributor Author

@olafurpg I've added a snapshot example just now. Thankfully as we're emitting char offset ranges as opposed to column offset ranges, it didnt require any changes to the snapshot printer to make everything line up just right 🙂

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

LGTM 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle TABs in code Wrong ranges for lines with tab indentation

3 participants