Skip to content
Updated CSS Context API implementation spec (markdown) authored by RaymondLim's avatar RaymondLim
CSS Context Utility API Specification In Brackets we have an HTML utility API ``getTagInfo(editor, cursorPosition)`` to provide the context of an HTML tag and is already used by tag hinting and attribute hinting. However, we do not have a similar CSS utility API to provide CSS rule information. So this document specifies the new CSS utility API for the following goals.
* To avoid duplicate effort in detecting CSS context by individual extension provider.
In Brackets we already have an HTML utility API ``getTagInfo(editor, cursorPosition)`` to provide the context of an HTML tag and is already used by tag hinting and attribute hinting. However, we do not have a similar CSS utility API to provide CSS rule information. In the absent of this API we have the following issues for each CSS hint provider. * To avoid inconsistent or incomplete implementation of CSS context detection.
* Each CSS hint provider has to implement its own code to detect the CSS context. * To provide a maintainable, scalable implementation of CSS context that has complete coverage of all possible CSS context.
* Implementation may not consistent and may have some of its own bugs or issues.
## getRuleInfo ## ## getRuleInfo ##
This API takes two arguments -- editor object and cursor position and it returns a rule infomation object. The new API will be defined as getRuleInfo(editor, cursorPos). It takes two arguments -- editor object and cursor position, and returns a rule infomation object.
The rule information is defined as follows... The rule information is defined as follows...
``` ```
{ {
selector: selector:
{ index: -1, { index: currentIndexInValues,
values: [selector1, selector2, ...] }, values: [selector1, selector2, ...] },
prop: prop:
{ name: propName || "", { name: propName,
index: -1, index: currentIndexInValues,
values: [propValue1, propValue2, ...] }, values: [propValue1, propValue2, ...] },
position: position:
{ tokenType: tokenType || "", { tokenType: tokenType,
offset: offset || 0 } offset: offsetInCurrentToken }
} }
``` ```
```tokenType``` is an empty string if the current cursor position is within an unsupported context location, or an enum that has one of the following string values if the cursor is inside a supported context. ```tokenType``` is either an empty string or one of the following values.
* **PROP_NAME** - will implement in sprint 18 for CSS hinting and font hinting * **PROP_NAME** - will implement in sprint 18 for CSS hinting and font hinting
* **PROP_VALUE** - will implement in sprint 18 for CSS hinting and font hinting * **PROP_VALUE** - will implement in sprint 18 for CSS hinting and font hinting
* **SELECTOR** - not plan to implement it in sprint 18 * **SELECTOR** - not plan to implement it in sprint 18
* **MEDIA** - may support in the future with some modification to the rule info structure * **MEDIA** - may support in the future with some modification to the rule info structure
* **CHARSET* - may support in the future with some modification to the rule info structure * **CHARSET* - may support in the future with some modification to the rule info structure
The value of ```tokenType``` is an empty string for the following context.
* Current cursor position is in a non-css/non-less document
* Current cursor position is within a not-yet-supported or unsupported context
* Current cursor position is within an invalid context
###Default values of rule information### ###Default values of rule information###
If the cursor is in a non-CSS and non-less document, or inside the unsupported context of a css/less document a rule info with the following values is returned. If the cursor is in a non-css/non-less document, or inside the unsupported context of a css/less document a rule info with the following values is returned.
``` ```
{ {
selector: selector:
... ...
......