-
Notifications
You must be signed in to change notification settings - Fork 60
Code action: convert type to module #532
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
Open
aspeddro
wants to merge
9
commits into
rescript-lang:master
Choose a base branch
from
aspeddro:code-action-type-to-module
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73a00cf
test
aspeddro dc10daa
Merge branch 'master' into code-action-type-to-module
aspeddro 1ddd96d
codeaction: type to module
aspeddro 5e99d07
Merge branch 'master' into code-action-type-to-module
aspeddro a9c63c0
handle with record/variant
aspeddro 09bc060
support multiple file
aspeddro 6598a23
refactor
aspeddro 7a4c6cb
refactor
aspeddro e9e6295
update changelog
aspeddro 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
let command ~path ~pos ~newName ~debug = | ||
match Cmt.fullFromPath ~path with | ||
| None -> None | ||
| Some full -> ( | ||
match References.getLocItem ~full ~pos ~debug with | ||
| None -> None | ||
| Some locItem -> | ||
let allReferences = References.allReferencesForLocItem ~full locItem in | ||
let referencesToToplevelModules = | ||
allReferences | ||
|> Utils.filterMap (fun {References.uri = uri2; locOpt} -> | ||
if locOpt = None then Some uri2 else None) | ||
in | ||
let referencesToItems = | ||
allReferences | ||
|> Utils.filterMap (function | ||
| {References.uri = uri2; locOpt = Some loc} -> Some (uri2, loc) | ||
| {locOpt = None} -> None) | ||
in | ||
let fileRenames = | ||
referencesToToplevelModules | ||
|> List.map (fun uri -> | ||
let path = Uri.toPath uri in | ||
let dir = Filename.dirname path in | ||
let newPath = | ||
Filename.concat dir (newName ^ Filename.extension path) | ||
in | ||
let newUri = Uri.fromPath newPath in | ||
Protocol.RenameFile | ||
{oldUri = uri |> Uri.toString; newUri = newUri |> Uri.toString}) | ||
in | ||
let textDocumentEdits = | ||
let module StringMap = Misc.StringMap in | ||
let textEditsByUri = | ||
referencesToItems | ||
|> List.map (fun (uri, loc) -> (Uri.toString uri, loc)) | ||
|> List.fold_left | ||
(fun acc (uri, loc) -> | ||
let textEdit = | ||
Protocol.{range = Utils.cmtLocToRange loc; newText = newName} | ||
in | ||
match StringMap.find_opt uri acc with | ||
| None -> StringMap.add uri [textEdit] acc | ||
| Some prevEdits -> | ||
StringMap.add uri (textEdit :: prevEdits) acc) | ||
StringMap.empty | ||
in | ||
StringMap.fold | ||
(fun uri edits acc -> | ||
let textDocumentEdit = | ||
Protocol.TextDocumentEdit | ||
{textDocument = {uri; version = None}; edits} | ||
in | ||
textDocumentEdit :: acc) | ||
textEditsByUri [] | ||
in | ||
let documentChanges = fileRenames @ textDocumentEdits in | ||
Some Protocol.{documentChanges}) |
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.