Skip to content

Turn Dotty import suggestions into code actions - #2536

Closed
gabro wants to merge 1 commit into
mainfrom
dotty-implicit-suggestinos
Closed

Turn Dotty import suggestions into code actions#2536
gabro wants to merge 1 commit into
mainfrom
dotty-implicit-suggestinos

Conversation

@gabro

@gabro gabro commented Feb 21, 2021

Copy link
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown
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

}
}

object SymbolNotFoundWithImportSuggestions {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

gabro commented Mar 1, 2021

Copy link
Copy Markdown
Member Author

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

tgodzik commented Mar 1, 2021

Copy link
Copy Markdown
Contributor

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

gabro commented Mar 1, 2021

Copy link
Copy Markdown
Member Author

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