Skip to content

Turn Dotty import suggestions into code actions #2536

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

gabro
Copy link
Member

@gabro gabro commented Feb 21, 2021

@gabro gabro force-pushed the dotty-implicit-suggestinos branch from 32c7576 to 560081c Compare February 21, 2021 18:08
diagnostic.getRange.getEnd()
)
compilers
.autoImports(textDocumentPositionParams, name, token)
Copy link
Contributor

Choose a reason for hiding this comment

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

autoImports aren't yet implemented for Scala 3, so we would have to make do without it.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, I was just thinking about that. The only difficult thing would be to determine import position

@@ -30,4 +30,22 @@ object ScalacDiagnostic {
case _ => None
}
}

object SymbolNotFoundWithImportSuggestions {
Copy link
Contributor

Choose a reason for hiding this comment

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

I also wonder if we could get this from the compiler itself and maybe use completions?

private val regexes = for {
fix <- List("One of the following imports", "The following import")
help <- List("fix ", "make progress towards fixing")
} yield s"""(?s)$fix imports might $help the problem:(.*)""".r
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} yield s"""(?s)$fix imports might $help the problem:(.*)""".r
} yield s"""(?s)$fix might $help the problem:(.*)""".r

?

Comment on lines +37 to +39
fix <- List("One of the following imports", "The following import")
help <- List("fix ", "make progress towards fixing")
} yield s"""(?s)$fix imports might $help the problem:(.*)""".r
Copy link
Contributor

Choose a reason for hiding this comment

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

The exact format of the compiler message strings is not stable and may change at any time, please do not rely on it. Instead, I encoruage you to contribute upstream a way to expose this information semantically in our Reporting API (we also implement scalafix-like rewrites which could be displayed as quick fix actions in vscode).

Copy link
Member

Choose a reason for hiding this comment

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

Revisiting long after the fact. @smarter has any thought gone into what this would look like, exposing this information semantically? I've been thinking about this often lately and sort of year for an error index like rust has and more structured errors that we can use for stuff like this. I see some convos that touch on this a bit like this old convo, but has there been any design though or conversation around what this could look like in Dotty?

Copy link
Contributor

Choose a reason for hiding this comment

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

has there been any design though or conversation around what this could look like in Dotty?

No, this is still waiting for a motivated individual to step up :).

@gabro
Copy link
Member Author

gabro commented Mar 1, 2021

Closing this for a few reasons:

  • too much infrastructure missing for auto-imports with Scala 3
  • the regex approach was a quick and dirty attempt to get it done, but I agree it's unreliable and it would be better to contribute an API in the dotty's presentation compiler.
  • that said, I won't realistically have time to put down the amount of work required to implement this feature properly

Thanks everyone for the feedback

@gabro gabro closed this Mar 1, 2021
@tgodzik
Copy link
Contributor

tgodzik commented Mar 1, 2021

Should we turn it into a feature request though? We might be able to get that data from the compiler anyway, so it might still be doable, but will need a greater amount of time.

@gabro
Copy link
Member Author

gabro commented Mar 1, 2021

scalameta/metals-feature-requests#192

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.

5 participants