@codemirror/lang-css
Advanced tools
Comparing version 6.1.1 to 6.2.0
@@ -0,1 +1,11 @@ | ||
## 6.2.0 (2023-04-26) | ||
### Bug fixes | ||
Explicitly list @lezer/common as a package dependency. | ||
### New features | ||
Export `defineCSSCompletionSource`, which allows one to define a CSS-style completion source for dialects with their own variable syntax. | ||
## 6.1.1 (2023-03-08) | ||
@@ -2,0 +12,0 @@ |
import { LRLanguage, LanguageSupport } from '@codemirror/language'; | ||
import { CompletionSource } from '@codemirror/autocomplete'; | ||
import { SyntaxNodeRef } from '@lezer/common'; | ||
/** | ||
Create a completion source for a CSS dialect, providing a | ||
predicate for determining what kind of syntax node can act as a | ||
completable variable. This is used by language modes like Sass and | ||
Less to reuse this package's completion logic. | ||
*/ | ||
declare const defineCSSCompletionSource: (isVariable: (node: SyntaxNodeRef) => boolean) => CompletionSource; | ||
/** | ||
CSS property, variable, and value keyword completion source. | ||
@@ -20,2 +28,2 @@ */ | ||
export { css, cssCompletionSource, cssLanguage }; | ||
export { css, cssCompletionSource, cssLanguage, defineCSSCompletionSource }; |
@@ -153,3 +153,3 @@ import { parser } from '@lezer/css'; | ||
} | ||
function variableNames(doc, node) { | ||
function variableNames(doc, node, isVariable) { | ||
if (node.to - node.from > 4096) { | ||
@@ -162,3 +162,3 @@ let known = VariablesByNode.get(node); | ||
do { | ||
for (let option of variableNames(doc, cursor.node)) | ||
for (let option of variableNames(doc, cursor.node, isVariable)) | ||
if (!seen.has(option.label)) { | ||
@@ -176,3 +176,3 @@ seen.add(option.label); | ||
var _a; | ||
if (node.name == "VariableName" && node.matchContext(declSelector) && ((_a = node.node.nextSibling) === null || _a === void 0 ? void 0 : _a.name) == ":") { | ||
if (isVariable(node) && node.matchContext(declSelector) && ((_a = node.node.nextSibling) === null || _a === void 0 ? void 0 : _a.name) == ":") { | ||
let name = doc.sliceString(node.from, node.to); | ||
@@ -189,5 +189,8 @@ if (!seen.has(name)) { | ||
/** | ||
CSS property, variable, and value keyword completion source. | ||
Create a completion source for a CSS dialect, providing a | ||
predicate for determining what kind of syntax node can act as a | ||
completable variable. This is used by language modes like Sass and | ||
Less to reuse this package's completion logic. | ||
*/ | ||
const cssCompletionSource = context => { | ||
const defineCSSCompletionSource = (isVariable) => context => { | ||
let { state, pos } = context, node = syntaxTree(state).resolveInner(pos, -1); | ||
@@ -202,5 +205,5 @@ let isDash = node.type.isError && node.from == node.to - 1 && state.doc.sliceString(node.from, node.to) == "-"; | ||
return { from: node.from, options: pseudoClasses, validFor: identifier }; | ||
if (node.name == "VariableName" || (context.explicit || isDash) && isVarArg(node, state.doc)) | ||
return { from: node.name == "VariableName" ? node.from : pos, | ||
options: variableNames(state.doc, astTop(node)), | ||
if (isVariable(node) || (context.explicit || isDash) && isVarArg(node, state.doc)) | ||
return { from: isVariable(node) || isDash ? node.from : pos, | ||
options: variableNames(state.doc, astTop(node), isVariable), | ||
validFor: variable }; | ||
@@ -224,2 +227,6 @@ if (node.name == "TagName") { | ||
}; | ||
/** | ||
CSS property, variable, and value keyword completion source. | ||
*/ | ||
const cssCompletionSource = /*@__PURE__*/defineCSSCompletionSource(n => n.name == "VariableName"); | ||
@@ -256,2 +263,2 @@ /** | ||
export { css, cssCompletionSource, cssLanguage }; | ||
export { css, cssCompletionSource, cssLanguage, defineCSSCompletionSource }; |
{ | ||
"name": "@codemirror/lang-css", | ||
"version": "6.1.1", | ||
"version": "6.2.0", | ||
"description": "CSS language support for the CodeMirror code editor", | ||
@@ -32,2 +32,3 @@ "scripts": { | ||
"@codemirror/state": "^6.0.0", | ||
"@lezer/common": "^1.0.2", | ||
"@lezer/css": "^1.0.0" | ||
@@ -34,0 +35,0 @@ }, |
@@ -40,4 +40,12 @@ <!-- NOTE: README.md is generated from src/README.md --> | ||
<dd><p>CSS property and value keyword completion source.</p> | ||
<dd><p>CSS property, variable, and value keyword completion source.</p> | ||
</dd> | ||
<dt id="user-content-definecsscompletionsource"> | ||
<code><strong><a href="#user-content-definecsscompletionsource">defineCSSCompletionSource</a></strong>(<a id="user-content-definecsscompletionsource^isvariable" href="#user-content-definecsscompletionsource^isvariable">isVariable</a>: fn(<a id="user-content-definecsscompletionsource^isvariable^node" href="#user-content-definecsscompletionsource^isvariable^node">node</a>: <a href="https://lezer.codemirror.net/docs/ref/#common.SyntaxNodeRef">SyntaxNodeRef</a>) → <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a>) → <a href="https://codemirror.net/docs/ref#autocomplete.CompletionSource">CompletionSource</a></code></dt> | ||
<dd><p>Create a completion source for a CSS dialect, providing a | ||
predicate for determining what kind of syntax node can act as a | ||
completable variable. This is used by language modes like Sass and | ||
Less to reuse this package's completion logic.</p> | ||
</dd> | ||
</dl> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38954
538
51
5
+ Added@lezer/common@^1.0.2