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

Properly change global class paths on move or rename in the filesystem dock #85037

Closed
wants to merge 1 commit into from

Conversation

Jordyfel
Copy link
Contributor

@Jordyfel Jordyfel commented Nov 17, 2023

This fixes error spam about script files being looked for at the old location when moving lots of files together, as well as corruption of global class info which would require a project reload to fix.

MRP: test_proj.zip
Test by moving the resource together with it's script in the additional dir. Note the errors, and switch to the script tab. After the second move, the parser complains about problems with the global class.

editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
@Jordyfel Jordyfel force-pushed the global-classes-on-move branch 3 times, most recently from cbfb46b to 3efdc10 Compare November 18, 2023 20:51
editor/filesystem_dock.cpp Outdated Show resolved Hide resolved
Copy link
Member

@KoBeWi KoBeWi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR probably fixes some open issue(s).

}

int index = -1;
EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->find_file(pair.key, &index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nearly 100% copied from EditorFileSystem._update_script_classes. I wonder if we can instead extract the necessary part of the method to a new method and call if from both locations?

The code in EditorFileSystem also handles the case when the file does not exist, which looks good to have in place as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did consider this, but the differences are enough that trying to extract it into a single function would be more annoying than useful. It's not like its a lot of code.

The "file" should be guaranteed to exist, because it is a EditorFileSystemDirectory fetched before a fs rescan is called, it uses data from before the move/rename operation. Can you think of a case where this would break?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes the maintenance easier, as right now only EditorFileSystem._update_script_classes is responsible for updating script classes.
With your PR, there will be 2 places and if something needs to be fixed in the logic, one place may be forgotten.

Is there really a difference? I only see the order of ScriptServer::remove_global_class_by_path(path) and ClassDB::is_parent_class(type, "Script"), but that is also handled below at the language check. All other differences can be handled easily.

No, but for FS operations generally, it is always better to check and be safe as you can never be 100% sure.
Your code right now can fail or even crash if the index is not found and therefore -1.

@Maran23
Copy link
Contributor

Maran23 commented Dec 22, 2023

I wonder why this happens in the first place?
Some move operations work, some will corrupt the editor, resulting in errors like:

Class "..." hides a global script class.
Could not resolve super class "...".

@Jordyfel
Copy link
Contributor Author

Jordyfel commented Apr 6, 2024

Superseded by #90186

@Jordyfel Jordyfel closed this Apr 6, 2024
@AThousandShips AThousandShips removed this from the 4.3 milestone Apr 6, 2024
@Jordyfel Jordyfel deleted the global-classes-on-move branch April 6, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants