-
-
Notifications
You must be signed in to change notification settings - Fork 43
[feat] integrate refactorex #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b4ad1ce
temp: commented formatter dep imports
gp-pereira 56d203d
feat: added refactorex as a dependency
gp-pereira 8d73fa4
feat: added refactorex as a code action handler
gp-pereira 28aa84e
temp: skipping broken remote control tests
gp-pereira 59d4fde
refactor: less restrict refactorex dependency version
gp-pereira ebc9996
refactor: removed useless test
gp-pereira a362383
feat: range subtree (selection) extraction algorithm - inlined from r…
gp-pereira 0ea28d6
Revert "feat: range subtree (selection) extraction algorithm - inline…
gp-pereira 9987517
refactor: using Document.fragment/3 to find the selection, then posit…
gp-pereira 82266c2
refactor: improved test infrastructure and multiline selection test
gp-pereira d65b698
fix: fixed the formatter import deps problem
gp-pereira 2400b0b
Revert "temp: commented formatter dep imports"
gp-pereira de8c2f4
feat: introducing context.trigger_kind to Code Actions so they can de…
gp-pereira 4999d81
refactor: adding more supported code actions
gp-pereira c7dcf6e
refactor: removed Logger used for debugging
gp-pereira 648fffe
[bugfix] Only index if there's stuff to index
scohen 9dcc8c0
refactor: sort aliases
gp-pereira 8ce74bb
refactor: remove unnecessary changes.
gp-pereira c8a09f8
refactor: better naming the test cases
gp-pereira bc6ad96
Revert "temp: skipping broken remote control tests"
gp-pereira e637c57
Update Nix hash of Mix deps
gp-pereira 536e259
fix: removed GenLSP from refactorex so it is not imported into remote…
gp-pereira 2e9882c
Update Nix hash of Mix deps
gp-pereira 36ec2ae
fix: setting up Project before tests
gp-pereira 57a50ad
refactor: bump Sourceror and using updates on Refactorex
gp-pereira 7c4c972
Update Nix hash of Mix deps
gp-pereira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
apps/remote_control/lib/lexical/remote_control/code_action/handlers/refactorex.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| defmodule Lexical.RemoteControl.CodeAction.Handlers.Refactorex do | ||
| alias Lexical.Document | ||
| alias Lexical.Document.Changes | ||
| alias Lexical.Document.Range | ||
|
|
||
| alias Lexical.RemoteControl | ||
| alias Lexical.RemoteControl.CodeAction | ||
| alias Lexical.RemoteControl.CodeMod | ||
|
|
||
| alias Refactorex.Refactor | ||
|
|
||
| @behaviour CodeAction.Handler | ||
|
|
||
| @impl CodeAction.Handler | ||
| def actions(%Document{} = doc, %Range{} = range, _diagnostics) do | ||
| with {:ok, target} <- line_or_selection(doc, range), | ||
| {:ok, ast} <- Sourceror.parse_string(Document.to_string(doc)) do | ||
| ast | ||
| |> Sourceror.Zipper.zip() | ||
| |> Refactor.available_refactorings(target, true) | ||
| |> Enum.map(fn refactoring -> | ||
| CodeAction.new( | ||
| doc.uri, | ||
| refactoring.title, | ||
| map_kind(refactoring.kind), | ||
| ast_to_changes(doc, refactoring.refactored) | ||
| ) | ||
| end) | ||
| else | ||
| _ -> [] | ||
| end | ||
| end | ||
|
|
||
| @impl CodeAction.Handler | ||
| def kinds, do: [:refactor] | ||
|
|
||
| @impl CodeAction.Handler | ||
| def trigger_kind, do: :invoked | ||
|
|
||
| defp line_or_selection(_, %{start: start, end: start}), do: {:ok, start.line} | ||
|
|
||
| defp line_or_selection(doc, %{start: start} = range) do | ||
| doc | ||
| |> Document.fragment(range.start, range.end) | ||
| |> Sourceror.parse_string(line: start.line, column: start.character) | ||
| end | ||
|
|
||
| defp map_kind("quickfix"), do: :quick_fix | ||
| defp map_kind(kind), do: :"#{String.replace(kind, ".", "_")}" | ||
|
|
||
| defp ast_to_changes(doc, ast) do | ||
| {formatter, opts} = CodeMod.Format.formatter_for_file(RemoteControl.get_project(), doc.uri) | ||
|
|
||
| ast | ||
| |> Sourceror.to_string( | ||
| formatter: formatter, | ||
| locals_without_parens: opts[:locals_without_parens] || [] | ||
| ) | ||
| |> then(&CodeMod.Diff.diff(doc, &1)) | ||
| |> then(&Changes.new(doc, &1)) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.