obiwan87 / odin-intellij

Odin Support plugin for JetBrains IDEs
https://plugins.jetbrains.com/plugin/22933-odin-support
MIT License
37 stars 3 forks source link

Refactoring #40

Open obiwan87 opened 5 months ago

obiwan87 commented 5 months ago

Add refactoring handlers for:

Dima-369 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

@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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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.