Skip to content

improvement: Add location to failure to help mark it in VS Code #834

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

Closed
wants to merge 1 commit into from

Conversation

tgodzik
Copy link
Collaborator

@tgodzik tgodzik commented Jan 23, 2025

I did a similar thing in scalameta/metals-vscode#1571 but I wonder if it would safer here.

@adpi2 any idea if we can get a full path easily instead of just the name? Otherwise, it seems the regex is an ok solution.

@adpi2
Copy link
Member

adpi2 commented Jan 24, 2025

Thanks, that looks great!

@adpi2 any idea if we can get a full path easily instead of just the name?

If you use the SourceLookupProvider you should be able to find the full source path from the class name.

Also I would appreciate if you could add a scripted test for it, similarly to this is one.

Copy link
Collaborator Author

@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.

I tried to go a bit further this direction, but it seems that getting source lookup to summarizing test event will require a large refactor than I hoped 😓

@@ -19,4 +21,10 @@ trait Debuggee {
def classPath: Seq[Path] = classPathEntries.map(_.absolutePath)
def classEntries: Seq[ClassEntry] = classPathEntries ++ javaRuntime
def classPathString: String = classPath.mkString(File.pathSeparator)

@volatile private[debugadapter] var sourceLookUpProvider: Option[SourceLookUpProvider] = None
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This gets a bit hacky unfortunately, so not sure if we want to go that way. Alternatively, we could just add the name and resolve it in metals when forwarding the event.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should not be a var but a normal parameter in the run method.

@@ -25,7 +26,8 @@ object TestSuiteEventHandler {
* Provide a summary of test suite execution based on passed TestSuiteEvent.Results parameter.
*/
def summarizeResults(
testSuiteResult: TestSuiteEvent.Results
testSuiteResult: TestSuiteEvent.Results,
sourceLookUpProviderOpt: Option[SourceLookUpProvider]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bloop will not be able to provide this, so this becomes again more difficult. We could make it all public, but then it becomes a bit unmanagable without a a large refactor

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure to understand why Bloop could not provide an instance of SourceLookUpProvider. Bloop starts a debug server, which always creates an instance of SourceLookUpProvider.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We would need to reimplement it in Bloop, or make SourceLookUpProvider not private.

@tgodzik
Copy link
Collaborator Author

tgodzik commented Jan 24, 2025

Or maybe I could just switch to attaching stack trace? We already have utilities in Metals that can change that to an exact location. This would make this PR much simpler and we can intercept the message in Metals.

@tgodzik
Copy link
Collaborator Author

tgodzik commented Jan 24, 2025

So the alternative is in #837 and it will require only minor changes in Metals

Comment on lines 70 to 72
override def run(listener: DebuggeeListener): CancelableFuture[Unit] = {
val eventHandler = new SbtTestSuiteEventHandler(listener)
val eventHandler = new SbtTestSuiteEventHandler(listener, () => sourceLookUpProvider)

Copy link
Member

Choose a reason for hiding this comment

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

This is really hacky.

It would be clearer to pass the sourceLookupProvider as a parameter of run.

override def run(listener: DebuggeeListener, sourceLookup: SourceLookupProvider): CancelableFuture[Unit] = {
  val eventHandler = new SbtTestSuiteEventHandler(listener, sourceLookup)
  
    ???

run is called by the debugger itself which always has an instance of SourceLookupProvider.

Copy link
Member

Choose a reason for hiding this comment

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

Now I remember that run is called too early, before we construct the instance of SourceLokkupProvider. Maybe we should wait for the launch request before we start the debuggee process.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you think about the other PR then? Might be simpler for us to calculate it in Metals

@@ -19,4 +21,10 @@ trait Debuggee {
def classPath: Seq[Path] = classPathEntries.map(_.absolutePath)
def classEntries: Seq[ClassEntry] = classPathEntries ++ javaRuntime
def classPathString: String = classPath.mkString(File.pathSeparator)

@volatile private[debugadapter] var sourceLookUpProvider: Option[SourceLookUpProvider] = None
Copy link
Member

Choose a reason for hiding this comment

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

I think it should not be a var but a normal parameter in the run method.

@@ -25,7 +26,8 @@ object TestSuiteEventHandler {
* Provide a summary of test suite execution based on passed TestSuiteEvent.Results parameter.
*/
def summarizeResults(
testSuiteResult: TestSuiteEvent.Results
testSuiteResult: TestSuiteEvent.Results,
sourceLookUpProviderOpt: Option[SourceLookUpProvider]
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure to understand why Bloop could not provide an instance of SourceLookUpProvider. Bloop starts a debug server, which always creates an instance of SourceLookUpProvider.

Comment on lines +54 to +56
def uriFromFilename(filename: String): Option[URI] = {
sourceNameToSourceFile.get(filename).flatMap(_.headOption).map(_.uri)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need this new method. You should be able to use getSourceFileUri instead which takes a class name, instead of a file name.

@tgodzik
Copy link
Collaborator Author

tgodzik commented Feb 5, 2025

Closing this one, since it's much more involved than I can work on right now. Alternative should be reasonably quick

@tgodzik tgodzik closed this Feb 5, 2025
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