Add simple code snippet support#116998
Add simple code snippet support#116998Goldenlion5648 wants to merge 1 commit intogodotengine:masterfrom
Conversation
|
|
The user is about to type the string, it is not meant to be auto filled with a certain type like string or digit. Also \1 is less commonly used in gdscript, only for regex. (Though I guess I'll add a way to escape)
I would have to check if there is a way to add multiline support inside arrays currently.
Not sure what you're saying here, the trash icon is already there (it was automatically added)
Is that easily fixable? Isn't this the case for all settings? |
Is that over complicating for a feature that could be relatively simple?
I didn't look too closely, but I think there is "display_text" or similar property that allows choosing how the completion should be shown.
what is the preferred way to handle this? Say wrap all snippets entries with
I can look into adding this |
Emphasis on subset. So in practice this would mean using
The issue is, that there is no way (that I know of) to have an insertion consistently replace existing text. And if you typed the name you need to replace the name with the actually snippet consistently.
This can't be encoded in the string. The insertion text is fully dependent on user input.
You also need to check whether |
|
I just noticed some bugs (like when the snippet has $0, it literally inserts that, and multiple \ do not put the cursor at the right spot). Not sure how deep in the "allow escaping" rabbit hole we wanted, but I'll fix it if desired, or simplify the escaping if we don't want to go as deep. I tried to addressed some feedback:
Now using '$0'
I opted not to do this. While it would be nice to have, it is a lot more work. I think having snippets at all would be a really nice qol change. Maybe this can be added on in the future?
Done
Seems like it does. Here is the current state of features in this PR: screenrecording-2026-03-04_20-14-03.mp4 |
I mean the video looks like it does not correctly maintain indentation 🤔 |
|
I wasn't sure what you meant by "support" (compared to crashing or similar), but yes you are correct that it doesn't indent as it should. Would you say adding multiline support is blocking this PR? Or is that something that could be added in the future? |
|
^ @HolonProduction while this PR does still need to fix the "escape $" and removing the correct number of "", in terms of multiline support, I think that might be out of scope since it appears that even typing multiline strings in the settings GUI might not be doable currently (the multiline snippet was added via the engine c++ code) Do we care about making |
Yes. The point is that every possible string still needs to be re-presentable. (That's mostly relevant for working with those patterns in code.) |
926c310 to
27290ed
Compare
|
@HolonProduction I addressed escaping and squashed commits here's how each of these converts now (if $0 is not shown in the output, the cursor was moved there) new video of the feature in action: screenrecording-2026-03-15_16-43-48.mp4 |
Allows users to add code snippets in the editor settings.
Supports 1 spot that the cursor should jump to after insertion, by using "\1" (no quotes) in the user snippet.
Defaults to these snippets:
Addresses this proposal (by me) godotengine/godot-proposals#14368
screenrecording-2026-03-02_20-52-10.mp4
The editor settings page (I believe this would be the first setting that uses an array value, unless I missed one)