8000 PoC for presentation compiler based errors as you type. by dragos · Pull Request #7430 · scalameta/metals · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PoC for presentation compiler based errors as you type. #7430

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dragos
Copy link
Contributor
@dragos dragos commented Apr 29, 2025

A few notable changes:

  • used an instance of InteractiveReporter in order to collect problems per compilation unit
  • implemented MetalsSourceFile to make sure sources are not duplicated (equality was not correctly implemented for virtual files)
  • Added a method to report un-adjusted diagnostics

To try it out:

  • publishLocal from this branch
  • set the Metals Version in VS Code to 1.5.3-SNAPSHOT (or whatever is the version you built).
  • To enable errors as you type, you need to modify package.json in your Metals installation directory to show the new setting. You should find it in~/.vscode/extensions/scalameta.metals-1.49.0/package.json on Mac Os. Then, add the snippet below where it makes sense (for example, after "metals.enableSemanticHighlighting" around line 375.
                "metals.presentationCompilerDiagnostics": {
                    "type": "boolean",
                    "default": false,
                    "markdownDescription": "Show presentation compiler errors and warnings as you type. This gives a much faster feedback loop but may show incorrect or incomplete error messages."
                },
  • enable "Metals: Presentation Compiler diagnostics"
Screenshot 2025-04-29 at 17 41 09

@dragos dragos marked this pull request as draft April 29, 2025 09:56
@dragos
Copy link
Contributor Author
dragos commented Apr 29, 2025

open for early feedback :)

/cc @olafurpg

compilers.didChange(path)
compilers
.didChange(path)
.map(diagnostics.publishDiagnosticsNotAdjusted(path, _))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Diagnostics coming from the PC are already correctly positioned relative to in-memory buffers. Not sure if there is a cleaner way than this.

@@ -1221,3 +1222,10 @@ class MetalsGlobal(
}
}
}

class MetalsReporter(initSettings: Settings) extends InteractiveReporter {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps not the best solution, but the presentation compiler is using this class to populate the problems field in ComplilationUnit. The annoying part is that the compiler needs a reporter in its constructor, and the reporter needs a reference to the compiler so we need to set it after the constructor call

@filipwiech
Copy link
Contributor

Cool idea! 👍 Is this somehow connected with scala/scala3#22259? 🙂

iuliand-db and others added 2 commits April 29, 2025 15:59
… you type.

A few notable changes:
- used an instance of InteractiveReporter in order to collect problems per compilation unit
- implemented MetalsSourceFile to make sure sources are not duplicated (equality was not correctly implemented for virtual files)
- Added a method to report un-adjusted diagnostics

All of the above can be challenged by the OSS project, we might need to revisit these decisions later.
@dragos dragos force-pushed the dragos/errors-as-you-type branch from 12b1925 to db3d16e Compare April 29, 2025 15:08
@dragos
Copy link
Contributor Author
dragos commented Apr 29, 2025

Cool idea! 👍 Is this somehow connected with scala/scala3#22259? 🙂

Not exactly... I'm trying to get Metals working for our large in-house monorepo and one direction is to rely less on expensive builds (via the build tool) and instead provide as much feedback as we can via the presentation compiler. I'm familiar with the Scala 2 presentation compiler, having worked extensively with it on the scala-ide project, but that's almost a decade ago... trying to piece together something and see how far we can go.

val sources = buildTargets.buildTargetSources(targetId)
val modifiedFiles =
buffers.open.filter(buf => sources.exists(buf.startWith)).toList
pprint.pprintln(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

debug message, will remove.

@@ -1318,7 +1333,22 @@ class Compilers(
targetId: BuildTargetIdentifier
): Option[PresentationCompiler] =
withKeyAndDefault(targetId) { case (key, getCompiler) =>
Option(jcache.computeIfAbsent(key, { _ => getCompiler() }).await)
val sources = buildTargets.buildTargetSources(targetId)
val modifiedFiles =
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it modified files or any open files within a target? In case of the first option OutlineFilesProvider already has that data.

@@ -578,6 +597,7 @@ case class ScalaPresentationCompiler(
val vd = new VirtualDirectory("(memory)", None)
val settings = new Settings
settings.Ymacroexpand.value = "discard"
settings.YpresentationDelay.value = 500
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this option needed? Will this not cause the other features to become sluggish as well?

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.

4 participants
0