vscode-css-languageservice 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/parser/cssNodes.js +21 -0
- package/lib/esm/parser/cssParser.js +15 -0
- package/lib/esm/parser/lessParser.js +1 -0
- package/lib/esm/parser/scssParser.js +1 -0
- package/lib/esm/services/cssNavigation.js +25 -18
- package/lib/esm/services/scssNavigation.js +35 -57
- package/lib/umd/parser/cssNodes.js +23 -1
- package/lib/umd/parser/cssParser.js +15 -0
- package/lib/umd/parser/lessParser.js +1 -0
- package/lib/umd/parser/scssParser.js +1 -0
- package/lib/umd/services/cssNavigation.js +25 -18
- package/lib/umd/services/scssNavigation.js +34 -56
- package/package.json +6 -6
|
@@ -96,6 +96,7 @@ export var NodeType;
|
|
|
96
96
|
NodeType[NodeType["Layer"] = 83] = "Layer";
|
|
97
97
|
NodeType[NodeType["LayerNameList"] = 84] = "LayerNameList";
|
|
98
98
|
NodeType[NodeType["LayerName"] = 85] = "LayerName";
|
|
99
|
+
NodeType[NodeType["PropertyAtRule"] = 86] = "PropertyAtRule";
|
|
99
100
|
})(NodeType || (NodeType = {}));
|
|
100
101
|
export var ReferenceType;
|
|
101
102
|
(function (ReferenceType) {
|
|
@@ -108,6 +109,7 @@ export var ReferenceType;
|
|
|
108
109
|
ReferenceType[ReferenceType["Module"] = 6] = "Module";
|
|
109
110
|
ReferenceType[ReferenceType["Forward"] = 7] = "Forward";
|
|
110
111
|
ReferenceType[ReferenceType["ForwardVisibility"] = 8] = "ForwardVisibility";
|
|
112
|
+
ReferenceType[ReferenceType["Property"] = 9] = "Property";
|
|
111
113
|
})(ReferenceType || (ReferenceType = {}));
|
|
112
114
|
export function getNodeAtOffset(node, offset) {
|
|
113
115
|
let candidate = null;
|
|
@@ -893,6 +895,25 @@ export class Layer extends BodyDeclaration {
|
|
|
893
895
|
return this.names;
|
|
894
896
|
}
|
|
895
897
|
}
|
|
898
|
+
export class PropertyAtRule extends BodyDeclaration {
|
|
899
|
+
constructor(offset, length) {
|
|
900
|
+
super(offset, length);
|
|
901
|
+
}
|
|
902
|
+
get type() {
|
|
903
|
+
return NodeType.PropertyAtRule;
|
|
904
|
+
}
|
|
905
|
+
setName(node) {
|
|
906
|
+
if (node) {
|
|
907
|
+
node.attachTo(this);
|
|
908
|
+
this.name = node;
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
getName() {
|
|
914
|
+
return this.name;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
896
917
|
export class Document extends BodyDeclaration {
|
|
897
918
|
constructor(offset, length) {
|
|
898
919
|
super(offset, length);
|
|
@@ -272,6 +272,7 @@ export class Parser {
|
|
|
272
272
|
|| this._parseKeyframe()
|
|
273
273
|
|| this._parseSupports(isNested)
|
|
274
274
|
|| this._parseLayer()
|
|
275
|
+
|| this._parsePropertyAtRule()
|
|
275
276
|
|| this._parseViewPort()
|
|
276
277
|
|| this._parseNamespace()
|
|
277
278
|
|| this._parseDocument()
|
|
@@ -717,6 +718,20 @@ export class Parser {
|
|
|
717
718
|
}
|
|
718
719
|
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
719
720
|
}
|
|
721
|
+
_parsePropertyAtRule() {
|
|
722
|
+
// @property <custom-property-name> {
|
|
723
|
+
// <declaration-list>
|
|
724
|
+
// }
|
|
725
|
+
if (!this.peekKeyword('@property')) {
|
|
726
|
+
return null;
|
|
727
|
+
}
|
|
728
|
+
const node = this.create(nodes.PropertyAtRule);
|
|
729
|
+
this.consumeToken(); // @layer
|
|
730
|
+
if (!this.peekRegExp(TokenType.Ident, /^--/) || !node.setName(this._parseIdent([nodes.ReferenceType.Property]))) {
|
|
731
|
+
return this.finish(node, ParseError.IdentifierExpected);
|
|
732
|
+
}
|
|
733
|
+
return this._parseBody(node, this._parseDeclaration.bind(this));
|
|
734
|
+
}
|
|
720
735
|
_parseLayer() {
|
|
721
736
|
// @layer layer-name {rules}
|
|
722
737
|
// @layer layer-name;
|
|
@@ -273,6 +273,7 @@ export class LESSParser extends cssParser.Parser {
|
|
|
273
273
|
|| this._parseImport()
|
|
274
274
|
|| this._parseSupports(true) // @supports
|
|
275
275
|
|| this._parseLayer() // @layer
|
|
276
|
+
|| this._parsePropertyAtRule() // @property
|
|
276
277
|
|| this._parseDetachedRuleSetMixin() // less detached ruleset mixin
|
|
277
278
|
|| this._parseVariableDeclaration() // Variable declarations
|
|
278
279
|
|| super._parseRuleSetDeclarationAtStatement();
|
|
@@ -215,6 +215,7 @@ export class SCSSParser extends cssParser.Parser {
|
|
|
215
215
|
|| this._parseRuleset(true) // @at-rule
|
|
216
216
|
|| this._parseSupports(true) // @supports
|
|
217
217
|
|| this._parseLayer() // @layer
|
|
218
|
+
|| this._parsePropertyAtRule() // @property
|
|
218
219
|
|| super._parseRuleSetDeclarationAtStatement();
|
|
219
220
|
}
|
|
220
221
|
return this._parseVariableDeclaration() // variable declaration
|
|
@@ -115,7 +115,7 @@ export class CSSNavigation {
|
|
|
115
115
|
resolvedLinks.push(link);
|
|
116
116
|
}
|
|
117
117
|
else {
|
|
118
|
-
const resolvedTarget = await this.
|
|
118
|
+
const resolvedTarget = await this.resolveReference(target, document.uri, documentContext, data.isRawLink);
|
|
119
119
|
if (resolvedTarget !== undefined) {
|
|
120
120
|
link.target = resolvedTarget;
|
|
121
121
|
resolvedLinks.push(link);
|
|
@@ -304,39 +304,46 @@ export class CSSNavigation {
|
|
|
304
304
|
async resolveModuleReference(ref, documentUri, documentContext) {
|
|
305
305
|
if (startsWith(documentUri, 'file://')) {
|
|
306
306
|
const moduleName = getModuleNameFromPath(ref);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
307
|
+
if (moduleName && moduleName !== '.' && moduleName !== '..') {
|
|
308
|
+
const rootFolderUri = documentContext.resolveReference('/', documentUri);
|
|
309
|
+
const documentFolderUri = dirname(documentUri);
|
|
310
|
+
const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri);
|
|
311
|
+
if (modulePath) {
|
|
312
|
+
const pathWithinModule = ref.substring(moduleName.length + 1);
|
|
313
|
+
return joinPath(modulePath, pathWithinModule);
|
|
314
|
+
}
|
|
313
315
|
}
|
|
314
316
|
}
|
|
315
317
|
return undefined;
|
|
316
318
|
}
|
|
317
|
-
async
|
|
318
|
-
|
|
319
|
+
async mapReference(target, isRawLink) {
|
|
320
|
+
return target;
|
|
321
|
+
}
|
|
322
|
+
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
|
|
319
323
|
// Following [css-loader](https://github.com/webpack-contrib/css-loader#url)
|
|
320
324
|
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports)
|
|
321
325
|
// convention, if an import path starts with ~ then use node module resolution
|
|
322
326
|
// *unless* it starts with "~/" as this refers to the user's home directory.
|
|
323
|
-
if (
|
|
324
|
-
|
|
325
|
-
return await this.resolveModuleReference(
|
|
327
|
+
if (target[0] === '~' && target[1] !== '/' && this.fileSystemProvider) {
|
|
328
|
+
target = target.substring(1);
|
|
329
|
+
return this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
|
|
326
330
|
}
|
|
331
|
+
const ref = await this.mapReference(documentContext.resolveReference(target, documentUri), isRawLink);
|
|
327
332
|
// Following [less-loader](https://github.com/webpack-contrib/less-loader#imports)
|
|
328
333
|
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#resolving-import-at-rules)
|
|
329
|
-
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
|
|
334
|
+
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
|
|
330
335
|
// then the loader will try to resolve @import inside node_modules.
|
|
331
336
|
if (this.resolveModuleReferences) {
|
|
332
|
-
if (
|
|
333
|
-
return
|
|
337
|
+
if (ref && await this.fileExists(ref)) {
|
|
338
|
+
return ref;
|
|
334
339
|
}
|
|
335
|
-
|
|
336
|
-
|
|
340
|
+
const moduleReference = await this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
|
|
341
|
+
if (moduleReference) {
|
|
342
|
+
return moduleReference;
|
|
337
343
|
}
|
|
338
344
|
}
|
|
339
|
-
|
|
345
|
+
// fall back. it might not exists
|
|
346
|
+
return ref;
|
|
340
347
|
}
|
|
341
348
|
async resolvePathToModule(_moduleName, documentFolderUri, rootFolderUri) {
|
|
342
349
|
// resolve the module relative to the document. We can't use `require` here as the code is webpacked.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
'use strict';
|
|
6
6
|
import { CSSNavigation } from './cssNavigation';
|
|
7
7
|
import * as nodes from '../parser/cssNodes';
|
|
8
|
-
import { URI } from 'vscode-uri';
|
|
8
|
+
import { URI, Utils } from 'vscode-uri';
|
|
9
9
|
import { startsWith } from '../utils/strings';
|
|
10
10
|
export class SCSSNavigation extends CSSNavigation {
|
|
11
11
|
constructor(fileSystemProvider) {
|
|
@@ -16,67 +16,45 @@ export class SCSSNavigation extends CSSNavigation {
|
|
|
16
16
|
node.type === nodes.NodeType.Use ||
|
|
17
17
|
node.type === nodes.NodeType.Forward);
|
|
18
18
|
}
|
|
19
|
-
async
|
|
20
|
-
if (startsWith(ref, 'sass:')) {
|
|
21
|
-
return undefined; // sass library
|
|
22
|
-
}
|
|
23
|
-
const target = await super.resolveRelativeReference(ref, documentUri, documentContext, isRawLink);
|
|
19
|
+
async mapReference(target, isRawLink) {
|
|
24
20
|
if (this.fileSystemProvider && target && isRawLink) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (let j = 0; j < pathVariations.length; j++) {
|
|
30
|
-
if (await this.fileExists(pathVariations[j])) {
|
|
31
|
-
return pathVariations[j];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
21
|
+
const pathVariations = toPathVariations(target);
|
|
22
|
+
for (const variation of pathVariations) {
|
|
23
|
+
if (await this.fileExists(variation)) {
|
|
24
|
+
return variation;
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
// ignore
|
|
38
|
-
}
|
|
39
27
|
}
|
|
40
28
|
return target;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
// No variation for links that ends with suffix
|
|
47
|
-
if (uri.path.endsWith('.scss') || uri.path.endsWith('.css')) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
// If a link is like a/, try resolving a/index.scss and a/_index.scss
|
|
51
|
-
if (uri.path.endsWith('/')) {
|
|
52
|
-
return [
|
|
53
|
-
uri.with({ path: uri.path + 'index.scss' }).toString(true),
|
|
54
|
-
uri.with({ path: uri.path + '_index.scss' }).toString(true)
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
// Use `uri.path` since it's normalized to use `/` in all platforms
|
|
58
|
-
const pathFragments = uri.path.split('/');
|
|
59
|
-
const basename = pathFragments[pathFragments.length - 1];
|
|
60
|
-
const pathWithoutBasename = uri.path.slice(0, -basename.length);
|
|
61
|
-
// No variation for links such as _a
|
|
62
|
-
if (basename.startsWith('_')) {
|
|
63
|
-
if (uri.path.endsWith('.scss')) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return [uri.with({ path: uri.path + '.scss' }).toString(true)];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const normalizedBasename = basename + '.scss';
|
|
71
|
-
const documentUriWithBasename = (newBasename) => {
|
|
72
|
-
return uri.with({ path: pathWithoutBasename + newBasename }).toString(true);
|
|
73
|
-
};
|
|
74
|
-
const normalizedPath = documentUriWithBasename(normalizedBasename);
|
|
75
|
-
const underScorePath = documentUriWithBasename('_' + normalizedBasename);
|
|
76
|
-
const indexPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/index.scss');
|
|
77
|
-
const indexUnderscoreUri = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/_index.scss');
|
|
78
|
-
const cssPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '.css');
|
|
79
|
-
return [normalizedPath, underScorePath, indexPath, indexUnderscoreUri, cssPath];
|
|
29
|
+
}
|
|
30
|
+
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
|
|
31
|
+
if (startsWith(target, 'sass:')) {
|
|
32
|
+
return undefined; // sass library
|
|
80
33
|
}
|
|
34
|
+
return super.resolveReference(target, documentUri, documentContext, isRawLink);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function toPathVariations(target) {
|
|
38
|
+
// No variation for links that ends with suffix
|
|
39
|
+
if (target.endsWith('.scss') || target.endsWith('.css')) {
|
|
40
|
+
return [target];
|
|
41
|
+
}
|
|
42
|
+
// If a link is like a/, try resolving a/index.scss and a/_index.scss
|
|
43
|
+
if (target.endsWith('/')) {
|
|
44
|
+
return [target + 'index.scss', target + '_index.scss'];
|
|
45
|
+
}
|
|
46
|
+
const targetUri = URI.parse(target);
|
|
47
|
+
const basename = Utils.basename(targetUri);
|
|
48
|
+
const dirname = Utils.dirname(targetUri);
|
|
49
|
+
if (basename.startsWith('_')) {
|
|
50
|
+
// No variation for links such as _a
|
|
51
|
+
return [Utils.joinPath(dirname, basename + '.scss').toString(true)];
|
|
81
52
|
}
|
|
53
|
+
return [
|
|
54
|
+
Utils.joinPath(dirname, basename + '.scss').toString(true),
|
|
55
|
+
Utils.joinPath(dirname, '_' + basename + '.scss').toString(true),
|
|
56
|
+
target + '/index.scss',
|
|
57
|
+
target + '/_index.scss',
|
|
58
|
+
Utils.joinPath(dirname, basename + '.css').toString(true)
|
|
59
|
+
];
|
|
82
60
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*--------------------------------------------------------------------------------------------*/
|
|
14
14
|
'use strict';
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.Layer = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.UnicodeRange = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
|
|
16
|
+
exports.ParseErrorCollector = exports.Marker = exports.Level = exports.Module = exports.GuardCondition = exports.LessGuard = exports.ListEntry = exports.UnknownAtRule = exports.MixinDeclaration = exports.MixinReference = exports.MixinContentDeclaration = exports.MixinContentReference = exports.ExtendsReference = exports.Variable = exports.Interpolation = exports.VariableDeclaration = exports.NumericValue = exports.RatioValue = exports.HexColorValue = exports.Operator = exports.AttributeSelector = exports.Term = exports.BinaryExpression = exports.Expression = exports.PageBoxMarginBox = exports.Page = exports.SupportsCondition = exports.MediaFeature = exports.MediaCondition = exports.MediaQuery = exports.Medialist = exports.Document = exports.PropertyAtRule = exports.Layer = exports.Supports = exports.Media = exports.Namespace = exports.ForwardVisibility = exports.Forward = exports.ModuleConfiguration = exports.Use = exports.Import = exports.KeyframeSelector = exports.Keyframe = exports.NestedProperties = exports.FontFace = exports.ViewPort = exports.FunctionDeclaration = exports.ElseStatement = exports.WhileStatement = exports.EachStatement = exports.ForStatement = exports.IfStatement = exports.FunctionArgument = exports.FunctionParameter = exports.Function = exports.Invocation = exports.Property = exports.CustomPropertyDeclaration = exports.Declaration = exports.CustomPropertySet = exports.AbstractDeclaration = exports.AtApplyRule = exports.SimpleSelector = exports.Selector = exports.RuleSet = exports.BodyDeclaration = exports.Declarations = exports.Stylesheet = exports.Identifier = exports.UnicodeRange = exports.Nodelist = exports.Node = exports.getParentDeclaration = exports.getNodePath = exports.getNodeAtOffset = exports.ReferenceType = exports.NodeType = void 0;
|
|
17
17
|
const strings_1 = require("../utils/strings");
|
|
18
18
|
/// <summary>
|
|
19
19
|
/// Nodes for the css 2.1 specification. See for reference:
|
|
@@ -107,6 +107,7 @@
|
|
|
107
107
|
NodeType[NodeType["Layer"] = 83] = "Layer";
|
|
108
108
|
NodeType[NodeType["LayerNameList"] = 84] = "LayerNameList";
|
|
109
109
|
NodeType[NodeType["LayerName"] = 85] = "LayerName";
|
|
110
|
+
NodeType[NodeType["PropertyAtRule"] = 86] = "PropertyAtRule";
|
|
110
111
|
})(NodeType = exports.NodeType || (exports.NodeType = {}));
|
|
111
112
|
var ReferenceType;
|
|
112
113
|
(function (ReferenceType) {
|
|
@@ -119,6 +120,7 @@
|
|
|
119
120
|
ReferenceType[ReferenceType["Module"] = 6] = "Module";
|
|
120
121
|
ReferenceType[ReferenceType["Forward"] = 7] = "Forward";
|
|
121
122
|
ReferenceType[ReferenceType["ForwardVisibility"] = 8] = "ForwardVisibility";
|
|
123
|
+
ReferenceType[ReferenceType["Property"] = 9] = "Property";
|
|
122
124
|
})(ReferenceType = exports.ReferenceType || (exports.ReferenceType = {}));
|
|
123
125
|
function getNodeAtOffset(node, offset) {
|
|
124
126
|
let candidate = null;
|
|
@@ -947,6 +949,26 @@
|
|
|
947
949
|
}
|
|
948
950
|
}
|
|
949
951
|
exports.Layer = Layer;
|
|
952
|
+
class PropertyAtRule extends BodyDeclaration {
|
|
953
|
+
constructor(offset, length) {
|
|
954
|
+
super(offset, length);
|
|
955
|
+
}
|
|
956
|
+
get type() {
|
|
957
|
+
return NodeType.PropertyAtRule;
|
|
958
|
+
}
|
|
959
|
+
setName(node) {
|
|
960
|
+
if (node) {
|
|
961
|
+
node.attachTo(this);
|
|
962
|
+
this.name = node;
|
|
963
|
+
return true;
|
|
964
|
+
}
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
getName() {
|
|
968
|
+
return this.name;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
exports.PropertyAtRule = PropertyAtRule;
|
|
950
972
|
class Document extends BodyDeclaration {
|
|
951
973
|
constructor(offset, length) {
|
|
952
974
|
super(offset, length);
|
|
@@ -283,6 +283,7 @@
|
|
|
283
283
|
|| this._parseKeyframe()
|
|
284
284
|
|| this._parseSupports(isNested)
|
|
285
285
|
|| this._parseLayer()
|
|
286
|
+
|| this._parsePropertyAtRule()
|
|
286
287
|
|| this._parseViewPort()
|
|
287
288
|
|| this._parseNamespace()
|
|
288
289
|
|| this._parseDocument()
|
|
@@ -728,6 +729,20 @@
|
|
|
728
729
|
}
|
|
729
730
|
return this._parseBody(node, this._parseRuleSetDeclaration.bind(this));
|
|
730
731
|
}
|
|
732
|
+
_parsePropertyAtRule() {
|
|
733
|
+
// @property <custom-property-name> {
|
|
734
|
+
// <declaration-list>
|
|
735
|
+
// }
|
|
736
|
+
if (!this.peekKeyword('@property')) {
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
const node = this.create(nodes.PropertyAtRule);
|
|
740
|
+
this.consumeToken(); // @layer
|
|
741
|
+
if (!this.peekRegExp(cssScanner_1.TokenType.Ident, /^--/) || !node.setName(this._parseIdent([nodes.ReferenceType.Property]))) {
|
|
742
|
+
return this.finish(node, cssErrors_1.ParseError.IdentifierExpected);
|
|
743
|
+
}
|
|
744
|
+
return this._parseBody(node, this._parseDeclaration.bind(this));
|
|
745
|
+
}
|
|
731
746
|
_parseLayer() {
|
|
732
747
|
// @layer layer-name {rules}
|
|
733
748
|
// @layer layer-name;
|
|
@@ -284,6 +284,7 @@
|
|
|
284
284
|
|| this._parseImport()
|
|
285
285
|
|| this._parseSupports(true) // @supports
|
|
286
286
|
|| this._parseLayer() // @layer
|
|
287
|
+
|| this._parsePropertyAtRule() // @property
|
|
287
288
|
|| this._parseDetachedRuleSetMixin() // less detached ruleset mixin
|
|
288
289
|
|| this._parseVariableDeclaration() // Variable declarations
|
|
289
290
|
|| super._parseRuleSetDeclarationAtStatement();
|
|
@@ -226,6 +226,7 @@
|
|
|
226
226
|
|| this._parseRuleset(true) // @at-rule
|
|
227
227
|
|| this._parseSupports(true) // @supports
|
|
228
228
|
|| this._parseLayer() // @layer
|
|
229
|
+
|| this._parsePropertyAtRule() // @property
|
|
229
230
|
|| super._parseRuleSetDeclarationAtStatement();
|
|
230
231
|
}
|
|
231
232
|
return this._parseVariableDeclaration() // variable declaration
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
resolvedLinks.push(link);
|
|
127
127
|
}
|
|
128
128
|
else {
|
|
129
|
-
const resolvedTarget = await this.
|
|
129
|
+
const resolvedTarget = await this.resolveReference(target, document.uri, documentContext, data.isRawLink);
|
|
130
130
|
if (resolvedTarget !== undefined) {
|
|
131
131
|
link.target = resolvedTarget;
|
|
132
132
|
resolvedLinks.push(link);
|
|
@@ -315,39 +315,46 @@
|
|
|
315
315
|
async resolveModuleReference(ref, documentUri, documentContext) {
|
|
316
316
|
if ((0, strings_1.startsWith)(documentUri, 'file://')) {
|
|
317
317
|
const moduleName = getModuleNameFromPath(ref);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
318
|
+
if (moduleName && moduleName !== '.' && moduleName !== '..') {
|
|
319
|
+
const rootFolderUri = documentContext.resolveReference('/', documentUri);
|
|
320
|
+
const documentFolderUri = (0, resources_1.dirname)(documentUri);
|
|
321
|
+
const modulePath = await this.resolvePathToModule(moduleName, documentFolderUri, rootFolderUri);
|
|
322
|
+
if (modulePath) {
|
|
323
|
+
const pathWithinModule = ref.substring(moduleName.length + 1);
|
|
324
|
+
return (0, resources_1.joinPath)(modulePath, pathWithinModule);
|
|
325
|
+
}
|
|
324
326
|
}
|
|
325
327
|
}
|
|
326
328
|
return undefined;
|
|
327
329
|
}
|
|
328
|
-
async
|
|
329
|
-
|
|
330
|
+
async mapReference(target, isRawLink) {
|
|
331
|
+
return target;
|
|
332
|
+
}
|
|
333
|
+
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
|
|
330
334
|
// Following [css-loader](https://github.com/webpack-contrib/css-loader#url)
|
|
331
335
|
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#imports)
|
|
332
336
|
// convention, if an import path starts with ~ then use node module resolution
|
|
333
337
|
// *unless* it starts with "~/" as this refers to the user's home directory.
|
|
334
|
-
if (
|
|
335
|
-
|
|
336
|
-
return await this.resolveModuleReference(
|
|
338
|
+
if (target[0] === '~' && target[1] !== '/' && this.fileSystemProvider) {
|
|
339
|
+
target = target.substring(1);
|
|
340
|
+
return this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
|
|
337
341
|
}
|
|
342
|
+
const ref = await this.mapReference(documentContext.resolveReference(target, documentUri), isRawLink);
|
|
338
343
|
// Following [less-loader](https://github.com/webpack-contrib/less-loader#imports)
|
|
339
344
|
// and [sass-loader's](https://github.com/webpack-contrib/sass-loader#resolving-import-at-rules)
|
|
340
|
-
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
|
|
345
|
+
// new resolving import at-rules (~ is deprecated). The loader will first try to resolve @import as a relative path. If it cannot be resolved,
|
|
341
346
|
// then the loader will try to resolve @import inside node_modules.
|
|
342
347
|
if (this.resolveModuleReferences) {
|
|
343
|
-
if (
|
|
344
|
-
return
|
|
348
|
+
if (ref && await this.fileExists(ref)) {
|
|
349
|
+
return ref;
|
|
345
350
|
}
|
|
346
|
-
|
|
347
|
-
|
|
351
|
+
const moduleReference = await this.mapReference(await this.resolveModuleReference(target, documentUri, documentContext), isRawLink);
|
|
352
|
+
if (moduleReference) {
|
|
353
|
+
return moduleReference;
|
|
348
354
|
}
|
|
349
355
|
}
|
|
350
|
-
|
|
356
|
+
// fall back. it might not exists
|
|
357
|
+
return ref;
|
|
351
358
|
}
|
|
352
359
|
async resolvePathToModule(_moduleName, documentFolderUri, rootFolderUri) {
|
|
353
360
|
// resolve the module relative to the document. We can't use `require` here as the code is webpacked.
|
|
@@ -27,69 +27,47 @@
|
|
|
27
27
|
node.type === nodes.NodeType.Use ||
|
|
28
28
|
node.type === nodes.NodeType.Forward);
|
|
29
29
|
}
|
|
30
|
-
async
|
|
31
|
-
if ((0, strings_1.startsWith)(ref, 'sass:')) {
|
|
32
|
-
return undefined; // sass library
|
|
33
|
-
}
|
|
34
|
-
const target = await super.resolveRelativeReference(ref, documentUri, documentContext, isRawLink);
|
|
30
|
+
async mapReference(target, isRawLink) {
|
|
35
31
|
if (this.fileSystemProvider && target && isRawLink) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
for (let j = 0; j < pathVariations.length; j++) {
|
|
41
|
-
if (await this.fileExists(pathVariations[j])) {
|
|
42
|
-
return pathVariations[j];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
32
|
+
const pathVariations = toPathVariations(target);
|
|
33
|
+
for (const variation of pathVariations) {
|
|
34
|
+
if (await this.fileExists(variation)) {
|
|
35
|
+
return variation;
|
|
45
36
|
}
|
|
46
37
|
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
// ignore
|
|
49
|
-
}
|
|
50
38
|
}
|
|
51
39
|
return target;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
// No variation for links that ends with suffix
|
|
58
|
-
if (uri.path.endsWith('.scss') || uri.path.endsWith('.css')) {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
// If a link is like a/, try resolving a/index.scss and a/_index.scss
|
|
62
|
-
if (uri.path.endsWith('/')) {
|
|
63
|
-
return [
|
|
64
|
-
uri.with({ path: uri.path + 'index.scss' }).toString(true),
|
|
65
|
-
uri.with({ path: uri.path + '_index.scss' }).toString(true)
|
|
66
|
-
];
|
|
67
|
-
}
|
|
68
|
-
// Use `uri.path` since it's normalized to use `/` in all platforms
|
|
69
|
-
const pathFragments = uri.path.split('/');
|
|
70
|
-
const basename = pathFragments[pathFragments.length - 1];
|
|
71
|
-
const pathWithoutBasename = uri.path.slice(0, -basename.length);
|
|
72
|
-
// No variation for links such as _a
|
|
73
|
-
if (basename.startsWith('_')) {
|
|
74
|
-
if (uri.path.endsWith('.scss')) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return [uri.with({ path: uri.path + '.scss' }).toString(true)];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const normalizedBasename = basename + '.scss';
|
|
82
|
-
const documentUriWithBasename = (newBasename) => {
|
|
83
|
-
return uri.with({ path: pathWithoutBasename + newBasename }).toString(true);
|
|
84
|
-
};
|
|
85
|
-
const normalizedPath = documentUriWithBasename(normalizedBasename);
|
|
86
|
-
const underScorePath = documentUriWithBasename('_' + normalizedBasename);
|
|
87
|
-
const indexPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/index.scss');
|
|
88
|
-
const indexUnderscoreUri = documentUriWithBasename(normalizedBasename.slice(0, -5) + '/_index.scss');
|
|
89
|
-
const cssPath = documentUriWithBasename(normalizedBasename.slice(0, -5) + '.css');
|
|
90
|
-
return [normalizedPath, underScorePath, indexPath, indexUnderscoreUri, cssPath];
|
|
40
|
+
}
|
|
41
|
+
async resolveReference(target, documentUri, documentContext, isRawLink = false) {
|
|
42
|
+
if ((0, strings_1.startsWith)(target, 'sass:')) {
|
|
43
|
+
return undefined; // sass library
|
|
91
44
|
}
|
|
45
|
+
return super.resolveReference(target, documentUri, documentContext, isRawLink);
|
|
92
46
|
}
|
|
93
47
|
}
|
|
94
48
|
exports.SCSSNavigation = SCSSNavigation;
|
|
49
|
+
function toPathVariations(target) {
|
|
50
|
+
// No variation for links that ends with suffix
|
|
51
|
+
if (target.endsWith('.scss') || target.endsWith('.css')) {
|
|
52
|
+
return [target];
|
|
53
|
+
}
|
|
54
|
+
// If a link is like a/, try resolving a/index.scss and a/_index.scss
|
|
55
|
+
if (target.endsWith('/')) {
|
|
56
|
+
return [target + 'index.scss', target + '_index.scss'];
|
|
57
|
+
}
|
|
58
|
+
const targetUri = vscode_uri_1.URI.parse(target);
|
|
59
|
+
const basename = vscode_uri_1.Utils.basename(targetUri);
|
|
60
|
+
const dirname = vscode_uri_1.Utils.dirname(targetUri);
|
|
61
|
+
if (basename.startsWith('_')) {
|
|
62
|
+
// No variation for links such as _a
|
|
63
|
+
return [vscode_uri_1.Utils.joinPath(dirname, basename + '.scss').toString(true)];
|
|
64
|
+
}
|
|
65
|
+
return [
|
|
66
|
+
vscode_uri_1.Utils.joinPath(dirname, basename + '.scss').toString(true),
|
|
67
|
+
vscode_uri_1.Utils.joinPath(dirname, '_' + basename + '.scss').toString(true),
|
|
68
|
+
target + '/index.scss',
|
|
69
|
+
target + '/_index.scss',
|
|
70
|
+
vscode_uri_1.Utils.joinPath(dirname, basename + '.css').toString(true)
|
|
71
|
+
];
|
|
72
|
+
}
|
|
95
73
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vscode-css-languageservice",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.1",
|
|
4
4
|
"description": "Language service for CSS, LESS and SCSS",
|
|
5
5
|
"main": "./lib/umd/cssLanguageService.js",
|
|
6
6
|
"typings": "./lib/umd/cssLanguageService",
|
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/mocha": "^9.1.1",
|
|
19
19
|
"@types/node": "16.x",
|
|
20
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
21
|
-
"@typescript-eslint/parser": "^5.
|
|
20
|
+
"@typescript-eslint/eslint-plugin": "^5.37.0",
|
|
21
|
+
"@typescript-eslint/parser": "^5.37.0",
|
|
22
22
|
"@vscode/web-custom-data": "^0.4.2",
|
|
23
|
-
"eslint": "^8.23.
|
|
23
|
+
"eslint": "^8.23.1",
|
|
24
24
|
"js-beautify": "^1.14.6",
|
|
25
25
|
"mocha": "^10.0.0",
|
|
26
26
|
"rimraf": "^3.0.2",
|
|
27
27
|
"source-map-support": "^0.5.21",
|
|
28
|
-
"typescript": "^4.8.
|
|
28
|
+
"typescript": "^4.8.3"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"vscode-languageserver-textdocument": "^1.0.7",
|
|
32
32
|
"vscode-languageserver-types": "^3.17.2",
|
|
33
33
|
"vscode-nls": "^5.2.0",
|
|
34
|
-
"vscode-uri": "^3.0.
|
|
34
|
+
"vscode-uri": "^3.0.4"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"prepublishOnly": "npm run clean && npm run compile-esm && npm run test && npm run remove-sourcemap-refs",
|