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

Cannot execute when creating multiple odin scratch files #142

Open
zenwerk opened this issue Feb 20, 2025 · 4 comments
Open

Cannot execute when creating multiple odin scratch files #142

zenwerk opened this issue Feb 20, 2025 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@zenwerk
Copy link

zenwerk commented Feb 20, 2025

Plugin Version: 0.13.0
Odin version: dev-2025-02
IDE: CLion 2024.3.3
OS: macOS 15.3.1(24D70)

When I created multiple odin files using the IDE's scratch file function, I was unable to execute them due to the following error.

/Users/zenwerk/CLionProjects/Odin/odin run "/Users/zenwerk/Library/Application Support/JetBrains/CLion2024.3/scratches" "" -out:bin/learn-odin
/Users/zenwerk/Library/Application Support/JetBrains/CLion2024.3/scratches/scratch_1.odin(29:1) Error: Redeclaration of 'main' in this scope 
	at /Users/zenwerk/Library/Application Support/JetBrains/CLion2024.3/scratches/scratch_2.odin(7:1) 
	main :: proc() { 
	^ 

In the scratch file environment, I think that it is necessary to execute files on a file-by-file basis using the -file option.

@zenwerk zenwerk changed the title Cannot Execute When Creating Multiple Odin Scratch Files Cannot execute when creating multiple odin scratch files Feb 20, 2025
@obiwan87
Copy link
Owner

Hi there. It's not a plugin error. You need to put the Odin files in different directories otherwise you get that compile error

@zenwerk
Copy link
Author

zenwerk commented Feb 20, 2025

Certainly, this is the correct behavior for Odin, but it is incompatible with the scratch feature provided by the IntelliJ IDE platform.
A scratch file is created in a specific directory specified by the IDE and is essentially never manipulated by the user.

https://www.jetbrains.com/help/idea/scratches.html#use-dependency-in-scratch-file

It would be ideal if scratch's main could be executed independently, as in Goland.


Thanks for developing such a useful plugin.

@obiwan87
Copy link
Owner

obiwan87 commented Feb 20, 2025

Oh maybe there's an easy way to achieve that. "odin run" also supports "-f" which will ignore any other file other than the one passed to it. (see odin run --help)

So a possible way to implement it is to

  1. detect whether file to be run is a scratch file (see ScratchUtils#isScratch)
  2. if yes, add -f to compiler options (need to extend RunConfiguration to support running file instead of directory)

Yeah, I think that's the proper way to do it. I'm re-opening the issue. Expect this to be implemented one or two releases down the way. Also, if you want to help testing, feel free to join the Odin discord server. There I will also share pre-releases.

@obiwan87 obiwan87 reopened this Feb 20, 2025
@obiwan87 obiwan87 self-assigned this Feb 20, 2025
@obiwan87 obiwan87 added the enhancement New feature or request label Feb 20, 2025
@obiwan87 obiwan87 removed their assignment Feb 20, 2025
@obiwan87 obiwan87 added this to the 0.14.0 milestone Feb 21, 2025
obiwan87 added a commit that referenced this issue Feb 22, 2025
Also add "Build as file" checkbox in run configuration. This allows to run the main methods of multiple scratch files, without the compiler complaining about re-declared main procedure.
@obiwan87
Copy link
Owner

This features has been implemented with c3bd98c. Needs to be tested. Feel free to join the Odin discord server to access the pre-release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants