Godot Version
4.3
Question
Hello, I’m trying to use Godots Code Edit Node but I cannot figure out how to use code complete, every script I attempt has failed. I’m just lookin for a basic script that works, Cheers.
4.3
Hello, I’m trying to use Godots Code Edit Node but I cannot figure out how to use code complete, every script I attempt has failed. I’m just lookin for a basic script that works, Cheers.
You need to set the code_completion_enabled
property to true.
I’ve set it to true, but it still doesn’t work
This is the script I’ve attempted to use
extends CodeEdit
func _ready() -> void:
code_completion_enabled = true
code_completion_requested.connect(_request_code_completion)
func _request_code_completion(force):
print("request")
add_code_completion_option(CodeEdit.KIND_FUNCTION, "alert", "alert")
update_code_completion_options(true)
What if you swap the two lines under ready func with each other, or somehow make it true after you already edit the text file.
code_completion_requested.connect(_request_code_completion)
code_completion_enabled = true
Didn’t fix it
What about the confirm_code_completion function? It seems to say in the documentation that it replaces current text with selected text.
How do I do that?
The code edit won’t invoke a completion request when typing. Does it work when using Ctrl + Space
? If so, you might be missing a connection from TextEdit.text_changed
to CodeEdit.request_code_completion
Also if you are using the virtual method _request_code_completion
you don’t need to connect it to the code_completion_requested
signal (the signal will never be emitted), see this proposal for info on how they interact.
When I press ctrl + space
it did work, but I don’t think code edit has a text_changed
API, well I couldn’t find it
It’s a signal on TextEdit
which CodeEdit
inherits from
Hey everyone, I have figured it out
extends CodeEdit
func _ready() :
text_changed.connect(code_request_code_completion)
code_completion_enabled = true
func code_request_code_completion():
add_code_completion_option(CodeEdit.KIND_FUNCTION, "[display text]", "[text inserted into code]")
update_code_completion_options(true)
The code above makes an sends an autocomplete to the user without ctrl+space
extends CodeEdit
func _ready():
code_completion_enabled = true
# code_completion_requested.connect(_request_code_completion) (Not Needed)
func _request_code_completion(force):
add_code_completion_option(CodeEdit.KIND_FUNCTION, "[display text]", "[text inserted into code]")
update_code_completion_options(force)
Thank you, and thanks to @holonproduction
code_completion_requested.connect(_request_code_completion)
shouldn’t be necessary in your second example. The implementation of _request_code_completion
overrides the default implementation which would emit the signal.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.