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

feature: metals error reports #4971

Merged
merged 3 commits into from
Mar 17, 2023
Merged

feature: metals error reports #4971

merged 3 commits into from
Mar 17, 2023

Conversation

kasiaMarek
Copy link
Contributor

A framework for creating error reports in metals.

Types of reports:

  • bloop - for bloop issues
  • incognito - metals error reports without any user specific/sensitive data
  • unsanitized - metals error reports that may have user sensitive data (e.g. code fragments)

For all we replace home and workspace paths for generic placeholders.

part of: #4924

A framework for creating error reports in metals.
swallowUntilSemicolon(scanner.getNextToken(), line + addLine)
} else {
line + addLine
if (token == ITerminalSymbols.TokenNameEOF) line
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was looking at errors in metals.log to decide where to create reports and this was throwing an IndexOutOfBounds for scanner.getCurrentTokenSource.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

@@ -228,7 +228,7 @@ abstract class PcCollector[T](
def isForComprehensionOwner(named: NameTree) =
soughtNames(named.name) &&
named.symbol.owner.isAnonymousFunction && owners.exists(
_.pos.point == named.symbol.owner.pos.point
pos.isDefined && _.pos.point == named.symbol.owner.pos.point
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again. I had an pos on NoPosition error here in metals.log.

@kasiaMarek kasiaMarek requested a review from tgodzik February 15, 2023 16:24
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

Good work! I think this will be very useful in the future 🚀

swallowUntilSemicolon(scanner.getNextToken(), line + addLine)
} else {
line + addLine
if (token == ITerminalSymbols.TokenNameEOF) line
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

The errors are chosen based on what reoccurs in `metals.log`.
@kasiaMarek kasiaMarek marked this pull request as ready for review February 17, 2023 14:18
@kasiaMarek kasiaMarek requested a review from tgodzik February 17, 2023 14:18
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

Some very minor comments, but already looks great! We can merge it after the release just in case (being super careful here.)

@@ -31,7 +32,7 @@ final class AutoImportsProvider(
params: OffsetParams,
config: PresentationCompilerConfig,
buildTargetIdentifier: String,
):
)(using Option[Reports]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make it not an Option? Maybe the default being some kind of NOP reporting Reporting.empty ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about:

class EmptyReportContext extends OptReportContext {
  override def optUnsanitized(): Option[ReportsProvider] = None
  override def optIncognito(): Option[ReportsProvider] = None
  override def optBloop(): Option[ReportsProvider] = None
}

I'd rather be explicit, that nothing may happen. It's annoying that adding new types of reports would require more boilerplate code. We can instead pass type of report as an arg, but then opt seems to refer to the optional existence of such a raport type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer:

class EmptyReportContext extends OptReportContext {
  override def unsanitized(): ReportsProvider = EmptyReporter
  override def incognito(): ReportsProvider =  EmptyReporter
  override def nloop(): ReportsProvider =  EmptyReporter
}

but it;s fine if you want to go with your approach

import scala.meta.io.AbsolutePath

class ZipReportsProvider(
buildTargetsInfo: () => List[Map[String, String]],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
buildTargetsInfo: () => List[Map[String, String]],
doctor: () => MetalsDoctor

maybe? This way we clearly see that we depend on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a cheat to make the tests simpler... I was thinking also about creating a trait, but there wasn't really a good place to put it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ach ok, let's maybe rename it to doctorTargetsInfo and add a comment?

zip reports command:
 - zips error reports
 - adds build target info from doctor
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM! Let's check it out, great work!

@tgodzik tgodzik merged commit cd6c659 into scalameta:main Mar 17, 2023
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.

2 participants