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

Refactoring support #18

Closed
olafurpg opened this issue Apr 17, 2019 · 4 comments
Closed

Refactoring support #18

olafurpg opened this issue Apr 17, 2019 · 4 comments

Comments

@olafurpg
Copy link
Member

olafurpg commented Apr 17, 2019

Currently, Metals doesn't provide any refactoring support. For the upcoming v0.6, we have assigned a ticket to implement "rename symbol" (scalameta/metals#679).

After renaming, it would be nice to add basic refactoring actions such as:

// before
List(1).map(x => x + 1)
// after
List(1).map { x => x + 1 }
// before
"Hello\nWorld"
// after
"""Hello
   |World""".stripMargin

Those would be good starting points and down the road we could introduce more advanced refactorings:

  • move class with option to select new project and package name
  • extract method
  • inline method

Some challenges:

  • Scalafix integration (https://github.com/scalameta/metals-feature-requests/issues/7), it would be nice if we could move as much as possible into Scalafix so that people can enforce the same refactoring rules in CI. However, not all code actions like "convert to multiline string" make sense in a Scalafix context.
  • testing, what is the best way to test non-Scalafix refactorings?
  • extensibility, how do we organize code actions so that it's easy to introduce new rules? In the future, we might have thousands of code actions! Some code actions only require basic inputs like tokens while other actions require fully type-checked source files.

Search terms: code actions, inspections

@torkelrogstad
Copy link

Another refactoring (which I believe is pretty simple) which I really miss from IntelliJ is the "Use named argument for current and subsequent arguments" action. Would be much appreciated if something like that could make its way into Metals!

@fkoehler
Copy link

I would like to see from intellij: "remove unnecessary parentheses" which highlights the extra parentheses and allows to remove them via a code action.

I would be willing to help out here but I guess some more basic work needs to be done before I can "just" write a code action, no idea where to start currently.

@gabro
Copy link
Member

gabro commented Jan 2, 2020

Since we're slowly starting to tackle refactoring in Metals, this issue is not useful anymore in its current form.

I propose to keep the feature requests more focused and open separate ones for each refactoring.

So far we already support:

  • renaming (which has special treatment in LSP)
  • import missing symbol

I'm going to close this issue and re-open single ones so that we can analyze and prioritize them separately.

@gabro gabro closed this as completed Jan 2, 2020
@gabro
Copy link
Member

gabro commented Jan 2, 2020

@co-category thanks for the encouragement! Feel free to open a feature request for specific refactors you consider essential to your workflow.

As an aside, please try to keep a positive tone in your messages. Despite Metals being a lightweight alternative to IntelliJ, we do so with a spirit of positive OSS collaboration and we do not tolerate harsh tones against it or other projects.

Thank you 🙏

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

No branches or pull requests

4 participants