Skip to content

Commit f6e7034

Browse files
authored
[css] Random red highlighting on code (#397)
1 parent 028c5be commit f6e7034

File tree

3 files changed

+41
-56
lines changed

3 files changed

+41
-56
lines changed

src/parser/cssNodes.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export enum NodeType {
9999
LayerNameList,
100100
LayerName,
101101
PropertyAtRule,
102-
Container
102+
Container,
103+
ModuleConfig,
103104
}
104105

105106
export enum ReferenceType {
@@ -1042,16 +1043,17 @@ export class Import extends Node {
10421043
export class Use extends Node {
10431044

10441045
public identifier?: Identifier;
1045-
public parameters?: Nodelist;
1046+
public parameters?: Node;
10461047

10471048
public get type(): NodeType {
10481049
return NodeType.Use;
10491050
}
10501051

1051-
public getParameters(): Nodelist {
1052-
if (!this.parameters) {
1053-
this.parameters = new Nodelist(this);
1054-
}
1052+
public setParameters(value: Node | null): value is Node{
1053+
return this.setNode('parameters', value);
1054+
}
1055+
1056+
public getParameters(): Node | undefined {
10551057
return this.parameters;
10561058
}
10571059

@@ -1097,8 +1099,7 @@ export class ModuleConfiguration extends Node {
10971099
export class Forward extends Node {
10981100

10991101
public identifier?: Node;
1100-
public members?: Nodelist;
1101-
public parameters?: Nodelist;
1102+
public parameters?: Node;
11021103

11031104
public get type(): NodeType {
11041105
return NodeType.Forward;
@@ -1112,17 +1113,11 @@ export class Forward extends Node {
11121113
return this.identifier;
11131114
}
11141115

1115-
public getMembers(): Nodelist {
1116-
if (!this.members) {
1117-
this.members = new Nodelist(this);
1118-
}
1119-
return this.members;
1116+
public setParameters(value: Node | null): value is Node{
1117+
return this.setNode('parameters', value);
11201118
}
11211119

1122-
public getParameters(): Nodelist {
1123-
if (!this.parameters) {
1124-
this.parameters = new Nodelist(this);
1125-
}
1120+
public getParameters(): Node | undefined {
11261121
return this.parameters;
11271122
}
11281123

src/parser/scssParser.ts

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class SCSSParser extends cssParser.Parser {
104104
return this._parseInterpolation() || super._parseMediaCondition();
105105
}
106106

107-
public _parseMediaFeatureRangeOperator() : boolean {
107+
public _parseMediaFeatureRangeOperator(): boolean {
108108
return this.accept(scssScanner.SmallerEqualsOperator) || this.accept(scssScanner.GreaterEqualsOperator) || super._parseMediaFeatureRangeOperator();
109109
}
110110

@@ -816,33 +816,41 @@ export class SCSSParser extends cssParser.Parser {
816816
}
817817

818818
if (this.acceptIdent('with')) {
819-
if (!this.accept(TokenType.ParenthesisL)) {
819+
if (!node.setParameters(this._parseModuleConfig())) {
820820
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.ParenthesisR]);
821821
}
822+
}
823+
}
822824

823-
// First variable statement, no comma.
824-
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
825-
return this.finish(node, ParseError.VariableNameExpected);
826-
}
825+
if (!this.accept(TokenType.SemiColon) && !this.accept(TokenType.EOF)) {
826+
return this.finish(node, ParseError.SemiColonExpected);
827+
}
827828

828-
while (this.accept(TokenType.Comma)) {
829-
if (this.peek(TokenType.ParenthesisR)) {
830-
break;
831-
}
832-
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
833-
return this.finish(node, ParseError.VariableNameExpected);
834-
}
835-
}
829+
return this.finish(node);
830+
}
836831

837-
if (!this.accept(TokenType.ParenthesisR)) {
838-
return this.finish(node, ParseError.RightParenthesisExpected);
839-
}
832+
public _parseModuleConfig(): nodes.Node | null {
833+
const node = this.createNode(nodes.NodeType.ModuleConfig);
834+
if (!this.accept(TokenType.ParenthesisL)) {
835+
return null;
836+
}
840837

838+
// First variable statement, no comma.
839+
if (!node.addChild(this._parseModuleConfigDeclaration())) {
840+
return this.finish(node, ParseError.VariableNameExpected);
841+
}
842+
843+
while (this.accept(TokenType.Comma)) {
844+
if (this.peek(TokenType.ParenthesisR)) {
845+
break;
846+
}
847+
if (!node.addChild(this._parseModuleConfigDeclaration())) {
848+
return this.finish(node, ParseError.VariableNameExpected);
841849
}
842850
}
843851

844-
if (!this.accept(TokenType.SemiColon) && !this.accept(TokenType.EOF)) {
845-
return this.finish(node, ParseError.SemiColonExpected);
852+
if (!this.accept(TokenType.ParenthesisR)) {
853+
return this.finish(node, ParseError.RightParenthesisExpected);
846854
}
847855

848856
return this.finish(node);
@@ -894,28 +902,10 @@ export class SCSSParser extends cssParser.Parser {
894902
}
895903

896904
if (this.acceptIdent('with')) {
897-
if (!this.accept(TokenType.ParenthesisL)) {
905+
if (!node.setParameters(this._parseModuleConfig())) {
898906
return this.finish(node, ParseError.LeftParenthesisExpected, [TokenType.ParenthesisR]);
899907
}
900908

901-
// First variable statement, no comma.
902-
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
903-
return this.finish(node, ParseError.VariableNameExpected);
904-
}
905-
906-
while (this.accept(TokenType.Comma)) {
907-
if (this.peek(TokenType.ParenthesisR)) {
908-
break;
909-
}
910-
if (!node.getParameters().addChild(this._parseModuleConfigDeclaration())) {
911-
return this.finish(node, ParseError.VariableNameExpected);
912-
}
913-
}
914-
915-
if (!this.accept(TokenType.ParenthesisR)) {
916-
return this.finish(node, ParseError.RightParenthesisExpected);
917-
}
918-
919909
} else if (this.peekIdent('hide') || this.peekIdent('show')) {
920910
if (!node.addChild(this._parseForwardVisibility())) {
921911
return this.finish(node, ParseError.IdentifierOrVariableExpected);

src/services/cssNavigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class CSSNavigation {
6767
private getHighlightNode(document: TextDocument, position: Position, stylesheet: nodes.Stylesheet): nodes.Node | undefined {
6868
const offset = document.offsetAt(position);
6969
let node = nodes.getNodeAtOffset(stylesheet, offset);
70-
if (!node || node.type === nodes.NodeType.Stylesheet || node.type === nodes.NodeType.Declarations) {
70+
if (!node || node.type === nodes.NodeType.Stylesheet || node.type === nodes.NodeType.Declarations || node.type === nodes.NodeType.ModuleConfig) {
7171
return;
7272
}
7373
if (node.type === nodes.NodeType.Identifier && node.parent && node.parent.type === nodes.NodeType.ClassSelector) {

0 commit comments

Comments
 (0)