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 #40

Open
5 of 11 tasks
obiwan87 opened this issue May 14, 2024 · 7 comments
Open
5 of 11 tasks

Refactoring #40

obiwan87 opened this issue May 14, 2024 · 7 comments

Comments

@obiwan87
Copy link
Owner

obiwan87 commented May 14, 2024

Add refactoring handlers for:

  • Introduce variable
  • Extract method
  • Safe delete
  • Remove unused imports
  • Rename
  • Inline renaming for identifiers with known scope
  • Extract parameter (Ctrl+Alt+P)
  • Specify type explicitly
  • Move packages
  • Move symbols
  • Create missing branches in switch and enum arrays
@Dima-369
Copy link
Contributor

How about Specify type explicitly? I don't need it often, but when I need it, it's really useful in other languages as well.

For instance, here in TypeScript when I am not fully sure of the type, and the type could be obfuscated from generics.

CleanShot 2024-08-13 at 14 19 01@2x


Like for this trivial example:

points_arr := make([]f32, 3 * n)

@obiwan87
Copy link
Owner Author

obiwan87 commented Aug 13, 2024

How about Specify type explicitly? I don't need it often, but when I need it, it's really useful in other languages as well.

Added it to the list ;-)

@obiwan87
Copy link
Owner Author

@Dima-369 Added support for "Specify type explicitly". I already found a little bug. The intention is not triggered at the end of an identifier, only at the beginning and in the middle of it

identifier := value        

so if the cursor is after the "r" it won't trigger

@Dima-369
Copy link
Contributor

Added support for "Specify type explicitly"

Cool, I tested with fmt.println() and with a local proc in the same file, and it worked flawlessly! This is really useful, thanks!

But, it fails on os.args, probably because it is defined like this.

// "Argv" arguments converted to Odin strings
args := _alloc_command_line_arguments()

CleanShot 2024-08-21 at 15 05 53@2x


It also fails on this: lines := strings.split("foo", "\n")

@obiwan87
Copy link
Owner Author

obiwan87 commented Aug 21, 2024

Yes, procedures with multiple values are not supported yet. Basically I wasn't sure how Odin handles multiple return values, when stored in only one variable. Would it be always safe to just infer the type of the first return argument?

os.args: Yes, the builtin-stuff is not fully supported yet. I'll look into it in another ticket

@Dima-369
Copy link
Contributor

how Odin handles multiple return values, when stored in only one variable. Would it be always safe to just infer the type of the first return argument?

I think so, yes.

@obiwan87
Copy link
Owner Author

Got ya.

There is so much more to this functionality. I thought about this feature this morning and there is a lot more to it that I haven't yet implemented. With composite types like procedures types maps and instantiated poly structs it should not work either.

Basically you have to analyze all the types a type might contain and import the package they're in, or use the import that is already defined in the current file.

@obiwan87 obiwan87 self-assigned this Aug 22, 2024
@obiwan87 obiwan87 removed their assignment Dec 29, 2024
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

2 participants