microsoft / vscode-css-languageservice

CSS, LESS & SCSS language service extracted from VSCode to be reused, e.g in the Monaco editor.
MIT License
317 stars 176 forks source link

Completion kind `Color` for color keywords and hex 4 / hex 8 #346

Closed romainmenke closed 1 year ago

romainmenke commented 1 year ago

This builds upon and is directly related to : https://github.com/microsoft/vscode-css-languageservice/pull/315

My initial intention was to verify those changes but I quickly ran into issues.

Having a match for rgb in completionItem.documentation doesn't actually mean that the value is a color. This becomes more apparent when considering new color functions like lab which can easily be part of a larger word or can be used in a sentence.

A documentation string can also contain multiple values :

--border: 1px solid rgb(255 0 0);

Screenshot 2023-04-30 at 13 11 02

I started writing regexp's to match actual color functions, but this exploded in complexity and would only cover the most simplistic of cases. I don't think it is ideal to have parser functions and regexp matchers for all the color functions.


However I do think it is valuable to add support for color keywords transparent and currentColor and to extend hex support to hex 4 and hex 8.

I also moved some regexp constructors outside of functions.

aeschli commented 1 year ago

Does this make https://github.com/microsoft/vscode-css-languageservice/pull/315 obsolte?

romainmenke commented 1 year ago

I think so.

imho the remaining functionality from that PR is not possible with the current available API's'. It requires a way to assign a color attribute through a different field than completionItem.documentation.