-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
ColorProvider API: Let extensions define the color formats #34366
Comments
Additional suggestion: |
@jrieken @rebornix @dbaeumer @joaomoreno Please have a look! |
👍 for |
I like the proposal but would make everything text edits. |
I like that. We only have to think if we would ever want to support snippet-style-color insertion? E.g one could insert a choice snippet with all color formats? |
Thanks all for your input on this ❤️ Previously the only concern I have about delegating formatting to extensions is it might lead to potential performance issue (flooding extension host when dragging inside saturation box, re #32235 (comment) ). Since we already reduce document changes with #34001 , I did testing again with functional formatter, the performance is reasonable: my idle CPU usage of Code is 20%, keep dragging inside saturation box will increase the usage to 40-50% on my machine. The number is acceptable as none one keeps dragging quickly forever, even they do so the CPU usage adds 20 - 30 % is still not bad. Based on @aeschli 's proposal and suggestions from Jo and Joao in #32235 , now I change the API to export class ColorPresentation {
/**
* The label of this color presentation. It will be shown on the color
* picker header. By default this is also the text that is inserted when selecting
* this color presentation.
*/
label: string;
/**
* An [edit](#TextEdit) which is applied to a document when selecting
* this presentation for the color. When `falsy` the [label](#ColorPresentation.label)
* is used.
*/
textEdit?: TextEdit;
/**
* An optional array of additional [text edits](#TextEdit) that are applied when
* selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves.
*/
additionalTextEdits?: TextEdit[];
}
export interface DocumentColorProvider {
provideDocumentColors(document: TextDocument, token: CancellationToken): ProviderResult<ColorInformation[]>;
provideColorPresentations(colorInfo: ColorInformation, token: CancellationToken): ProviderResult<ColorPresentation[]>;
} What it covers:
I separate |
Synced with @aeschli , the
|
I like it but I'd replace |
I always thought that we have insertText and range on a completion item is some sort of backwards compatibility. Wouldn't it make more sense to always express this as a text edit ? |
No, moved |
Marking as fixed. API is up-to-date, and extensions and language servers have adopted the new API. We can create new issues for follow-up issues. |
The proposed API for the color provider currently has a knowledge of color formats. Problem is these are language specific. In the case of CSS there are even more formats coming.
Therefore I'd suggest the following API instead of the currently proposed resolveDocumentColor
Given a color value (e.g.
{red:1, green:0, blue:0}
) , the provider returns a number of possible presentations: (#FF0000
,rgb(255, 0, 0)
,hsl(0, 100%, 50%)
,red
) that apply at the given range.The color picker can let the user toggle through the different presentations.
While the color picker is open and the user looks at different colors, new presentation requests will be sent to the provider for each color value. The color picker label will be updated once the result arrives.
label
field which is used as label to show to the user in the color picker.insertText
is provided, theinsertText
will be used if the when the color picker decides to apply that color presentation at the given color range. If noinsertText
is provided, thelabel
will be used asinsertText
.If there is a need for it,
insertText
could also supportSnippetString
.additionalTextEdits
are set, these edits can be additionally applied (e.g. for adding an import statement)type
file is optional. The idea is that the same type of presentation (e.g. hsl) always gets the same type (type: hsl
). That way the color picker can stick with the same presentation type while the user browses through different colors.The text was updated successfully, but these errors were encountered: