Skip to content

gdscript: allow color picking#990

Open
paul-marechal wants to merge 4 commits intogodotengine:masterfrom
paul-marechal:color-pick
Open

gdscript: allow color picking#990
paul-marechal wants to merge 4 commits intogodotengine:masterfrom
paul-marechal:color-pick

Conversation

@paul-marechal
Copy link
Copy Markdown

@paul-marechal paul-marechal commented Mar 7, 2026

Implement DocumentColorProvider by extracting Color expressions, interpreting them, and replacing arguments in place when possible.

Add the following configurations:

  • godotTools.colorPicker.precision: Controls how many decimals to include when applying edits.
  • godotTools.colorPicker.padValues: Whether or not to pad decimal numbers.
  • godotTools.colorPicker.uppercaseHex: Whether or not to write hexadecimals in uppercase when applying edits.

It should now be possible to get a preview of the color expressed by common Color methods, as well as pick and choose from a color palette provided by VS Code.

Only static expressions are evaluated, if you use a variable as one of the parameters then it will be ignored.

Color constant expressions are considered "readonly": The palette will show but provide no edits.

Test file:

Color.CYAN

Color()

Color("YELLOW")
Color("#ffff00")
Color("YELLOW", 0.5)
Color("#ffff00", 0.5)

Color(0, 1, 0)
Color(0, 1, 0, 0.5)
Color(0, 1, 0, 0.2)

Color8(255, 0, 0)
Color8(255, 0, 0, 128)
Color8(255, 0, 0, 0)

Color.from_rgba8(
    255, # red
            255, #green
    255,) #blue

Color.hex(
    0xFF00FFFF # best color
)

Illustration:
image

@paul-marechal
Copy link
Copy Markdown
Author

Ideally this information should come from Godot itself through LSP?

I had a lot of pain trying to implement an ad-hoc way of parsing expressions to allow editing arguments in place as I felt like this was a desirable behavior (being a user of the extension myself)... But honestly the code required to allow for this is a bit much so I'd understand if we'd want to scrap it.

@DaelonSuzuka
Copy link
Copy Markdown
Collaborator

This looks good! I had starting building this feature last year but I got bogged down in supporting all the color formats and never finished it.

Give me a chance to play with this but I like what I see.

Implement `DocumentColorProvider` by extracting Color expressions,
interpreting them, and replacing arguments in place when possible.
The idea is to break the potentially expensive for-loops to potentially
catch cancellation requests. After some reading `setImmediate` should
be better suited for this than `await Promise.resolve()`
@paul-marechal
Copy link
Copy Markdown
Author

Cleaned up a little and rebased on master.

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.

3 participants