-
-
Notifications
You must be signed in to change notification settings - Fork 23.3k
Add warning for deprecated identifiers in GDScript #104955
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
base: master
Are you sure you want to change the base?
Conversation
I foresee that if this is implemented, users would rather the warning be a strikethrough on the deprecated subject (even if currently CodeEdit cannot support it) |
Another PR of mine, #100019, adds a strikethrough to deprecated items in the code completion list, which is similar at least 🙂 |
There are still a few cases to figure out, and then the other tasks to complete as well, but I think this is close enough to complete now that it'd make sense to open it for review. I'm also keeping the commits separate for now (i.e., not squashing) since I'm trying to include one type of detection per commit so I can tell them apart easier. Once it's ready for merging, I'll squash and force push. |
StringName enum_type = type.enum_type; // Something like MyEnum. | ||
GDScriptParser::ClassNode *class_type = type.class_type; | ||
StringName class_name = class_type ? class_type->identifier->name : "@GlobalScope"; | ||
DocTools *dd = EditorHelp::get_doc_data(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a warning here but I bring it up to attention as well. You're calling get_doc_data
here even though it's already done above at line 1991
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I saw that in my terminal output, so thanks for catching that! I'll have to take a look at it again and confirm it's working properly.
All of my test cases appear to be working now! I would really appreciate it if someone more familiar with the GDScript parser could take a look at I've also noticed that as a little quirk of the identifier recognition, accessing a deprecated property from within its getter or setter causes those lines to trigger the warning. Ultimately, it does make sense, I guess - you are using the deprecated identifier - but in this specific context, it's a bit funny for it to complain about. |
Warnings now display information about what exactly is deprecated! The only case that doesn't seem to work right is when an autoload's global variable name is used as a type specifier: var my_autoload: SomeAutoload I'm having trouble extracting the name I tried regenerating the GDScript tests, but one of them is causing a hard crash. I'll have to look more at it over the next couple of days when I have time. |
37e9286
to
bdd6cd1
Compare
I'm getting a crash while typing an enum name. extends Node2D
enum MyEnum {
OPTION1,
OPTION2
}
# Type MyEnum here to crash.
var my_enum:
There is
Autoloads are more a project setting than a class type but the parser shows the global name and path when there are errors. You can find the name like this By the way, you can build with |
1fde830
to
314605d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected. Code looks good to me. Great work on the comprehensive integration tests 🙂
I've looked at the TODOs in code comments but can't think of a better way to implement these right now.
PS: I noticed --script --check-only
does not print any warnings when the script contains warnings. We should look into implementing this in a separate PR to make it more viable for CI use, along with an additional --warnings-as-errors
CLI argument (which would complement #99254 nicely).
Thank you very much! 😄 I had that script for testing on my side, and realized it would make for a nice comprehensive unit test file. It seems I have run into a bit of a pickle with the tests, though. It looks like at least the RenderingServer may not be constructed when running tests - trying to instantiate ERR_FAIL_NULL_MSG(RS::get_singleton(), "RenderingServer is null, so AnimatedTexture can't set itself up"); It prints out in the test results. I've changed it to use But tests on some other platforms appear to still be failing 🙁
|
983b14e
to
880dd04
Compare
c5d4dac
to
9b9b711
Compare
35d9438
to
82c9b92
Compare
624bc89
to
10d8954
Compare
21c7498
to
593603e
Compare
6709959
to
b7f23be
Compare
d1af266
to
da55f72
Compare
da55f72
to
dcecc7b
Compare
56cc5c2
to
b6d5083
Compare
9b88a0a
to
a429bdf
Compare
6e03308
to
d4a5b47
Compare
Note to self about methods for other non-user classes Display warning for deprecated methods on built-in classes (like AnimationPlayer) Protect from doc data being null Push warning for user-defined signal marked as `@deprecated` Recognize user-defined constant marked as `@deprecated` Recognize user-defined enums and values in anonymous enums marked as `@deprecated` Recognize user-defined property marked as `@deprecated` Recognize local variable marked as `@deprecated` Recognize built-in class (such as for constructors or static methods) marked as deprecated Recognize global autoload marked as `@deprecated` Recognize constant in `@GlobalScope` marked as deprecated Recognize global script class(?) marked as deprecated Recognize types from type hints in assignment statements marked as deprecated Recognize signal from native class marked as deprecated Recognize property from native class marked as deprecated Recognize constant from native class marked as deprecated Recognize enum from native class marked as deprecated Recognize individual value in enum marked as deprecated Recognize local constant marked as deprecated Recognize inner class in expression marked as deprecated Recognize individual value in user-defined named enum in inner class marked as deprecated Fix recognition of individual value from native enum with enum name marked as deprecated Remove some duplicate code Update modules/gdscript/gdscript_warning.cpp Co-authored-by: Micky <[email protected]> Provide context for warning, including type and name, when available Get rid of `auto` usages Fix some crashes when trying to access a null identifier Add test for warning Fix variable redeclaration Update test to use classes that don't crash Try removing AnimationPlayer case from unit test Add description in documentation for DEPRECATED_IDENTIFIER Replace DEBUG_ENABLED with TOOLS_ENABLED Add explanation for test case being commented out Update doc/classes/ProjectSettings.xml Co-authored-by: Micky <[email protected]> Update test Apply suggestions from code review Co-authored-by: A Thousand Ships <[email protected]> # Conflicts: # modules/gdscript/gdscript_analyzer.cpp Update modules/gdscript/gdscript_analyzer.cpp Co-authored-by: A Thousand Ships <[email protected]>
d4a5b47
to
1c28228
Compare
Closes godotengine/godot-proposals#12105 .
This PR adds a new warning,
DEPRECATED_IDENTIFIER
, to GDScript. As the name suggests, it activates when a line contains an identifier that has been marked as deprecated in the documentation.Tested cases
To Do
auto
or two)