-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add String/Comment tracking, AutoComplete and hints to CodeEdit #45393
Conversation
585e76d
to
74632cd
Compare
So I tested if the PR really solves the linked issues and The autocompletion seems broken on master for some things, which makes testing this difficult. EDIT: |
@KoBeWi Re, #24077 #42382: Yeah not entirely sure how to test these fully on master at the moment. Though the string tracking "should" fix them. Re, '$': '$' seems to be the same as master for me? Do you have some steps to reproduce your issue? |
Neat! You should probably mention it in the OP.
EDIT: |
74632cd
to
36bb651
Compare
is_cursor_line_visible = true; | ||
cursor_pos.y = line_top_offset_y; | ||
|
||
if (!clipped && cursor.line == line && line_wrap_index == caret_wrap_index) { |
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.
CC @bruvzg, I'm not entirely sure about this change. Was there any reason this was ran on all wrapped lines rather then where the caret is?
36bb651
to
8fab005
Compare
Ci crash CodeEdit.confirm_code_completion
Parameters [False]
ERROR: FATAL: Index p_index = 0 is out of bounds (size() = 0).
at: get (./core/templates/cowdata.h:157)
handle_crash: Program crashed with signal 4
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] bin/godot.linuxbsd.tools.64s() [0x1e5e7d8] (/home/runner/work/godot/godot/platform/linuxbsd/crash_handler_linuxbsd.cpp:54)
[2] /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7f712225a210] (??:0)
[3] CowData<ScriptCodeCompletionOption>::get(int) const (/home/runner/work/godot/godot/./core/templates/cowdata.h:157 (discriminator 7))
[4] Vector<ScriptCodeCompletionOption>::operator[](int) const (/home/runner/work/godot/godot/./core/templates/vector.h:89)
[5] CodeEdit::confirm_code_completion(bool) (/home/runner/work/godot/godot/scene/gui/code_edit.cpp:954 (discriminator 1)) This code should crash with same as above message CodeEdit.new().confirm_code_completion(false)
ClassDB.instance("CodeEdit").confirm_code_completion(false) |
8fab005
to
a6b13f7
Compare
a6b13f7
to
e980f4c
Compare
e980f4c
to
874f3c8
Compare
/* Keep enum in sync with: */ | ||
/* /core/object/script_language.h - ScriptCodeCompletionOption::Kind */ |
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.
Can't you just use the other enum, instead of introducing another one that needs to be the same?
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.
That's possible, though it felt incorrect to bind a enum from /core
to CodeEdit
, not sure of any cases where enums
aren't local to the class. Also can't bind it to ScriptCodeCompletionOption
as it's a struct, because of that, if we did cross reference, the docs get confused tying to look for ScriptCodeCompletionOption
.
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.
Ah, it's required for binding. Not sure then, either we move it to CodeEdit or maybe it's fine to have duplicates if they are commented properly.
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.
Yeah that crossed my mind too, but as it's used in script_language
, moving it would make /core
dependent on /scene
, which is a no go.
Not sure there is a clean way out of it as is, without duplicating. The alternative is to not use enums
, or we rewrite ScriptCodeCompletionOption
into a bindable class, which is a lot easier said then done.
I went over the code and, aside from that weird double enum I mentioned above, it looks mostly ok (although it's a lot of code and I didn't take a very detailed look). Would be nice to have this rebased, so it's possible to test. |
874f3c8
to
022f6e2
Compare
I checked again all the linked issues and #42382 is not fixed. There are also many new methods that need to be documented. It would be best to have them filled in this PR, even if very briefly. |
022f6e2
to
b05941c
Compare
Updated docs and removed #42382 from the op. |
b05941c
to
1684276
Compare
Thanks! |
Continuation of #31739
Builds on top of #42775 and blocked by #43663.
The main aim of this PR is abstracting out the auto complete system into
CodeEdit
, in order to do so it needed a system to trackStrings
.The implementation of
String
tracking will also trackComments
. The system closely follows that of the syntax highlighter, using the idea of regions.It exposes
add_[string|comment]_delimiter
methods to register the begin and end keys for each type. Once registeredCodeEdit
will keep track of the region. It's possible to check regions viais_in_[string|comment]
methods, if no column is provided it will returntrue
if the entire line is aString
orComment
. It is also possible to get the start and end position of regions viaget_delimiter_[start|end]_position
.Regions are updated on the
lines_edited_from
signal, I've tried to make this somewhat fast to hopefully have minimal impact on performance.AutoComplete is now exposed to the
GDScript
, items are added viaadd_code_completion_option
. Once all items are added a call toupdate_code_completion_options
will update the list of possible completions in the drop down. In addition to this there are three overridable methods:_request_code_completion
-> Checks and emitsrequest_code_completion
signal._filter_code_completion_candidates
-> Filters the list of options._confirm_code_completion
-> Inserts the selected optionThere are also various ways to query autocomplete getting the current selected, setting the selected item and getting the full list of options.
As part of the refactor I've attempted to remove the editor specific code and added a couple of new features. The first one allowing the user to force autocomplete. Secondly, adding a second shortcut to replace the existing text rather then inserting ontop. This is currently bound to
Tab
, the old behaviour is preserved by usingEnter / KP Enter
.In addition to this the
request_completion
signal has been renamed torequest_code_completion
To handle drawing, I've added two methods to
TextEdit
to get thecaret
draw position and to check if thecaret
is visible.Finally
CodeHint
has also been moved and exposed, andcallhint_offset
has been removed.TODO
Remove old code fromTextEdit
Update input handling after Remove hardcoded shortcuts from /scene and instead use the input action system to allow them to be customised. #43663Update draw code and removecallhint_offset
Fix initial '$' completioncloses #22196
closes #36833
closes #23756
closes #34168
closes #24077
closes #44000
Should solve some of #38847 and godotengine/godot-proposals/issues/1514