in src/services/cssCompletion.ts [98:185]
public doComplete(document: TextDocument, position: Position, styleSheet: nodes.Stylesheet, documentSettings: CompletionSettings | undefined): CompletionList {
this.offset = document.offsetAt(position);
this.position = position;
this.currentWord = getCurrentWord(document, this.offset);
this.defaultReplaceRange = Range.create(Position.create(this.position.line, this.position.character - this.currentWord.length), this.position);
this.textDocument = document;
this.styleSheet = styleSheet;
this.documentSettings = documentSettings;
try {
const result: CompletionList = { isIncomplete: false, items: [] };
this.nodePath = nodes.getNodePath(this.styleSheet, this.offset);
for (let i = this.nodePath.length - 1; i >= 0; i--) {
const node = this.nodePath[i];
if (node instanceof nodes.Property) {
this.getCompletionsForDeclarationProperty(node.getParent() as nodes.Declaration, result);
} else if (node instanceof nodes.Expression) {
if (node.parent instanceof nodes.Interpolation) {
this.getVariableProposals(null, result);
} else {
this.getCompletionsForExpression(<nodes.Expression>node, result);
}
} else if (node instanceof nodes.SimpleSelector) {
const parentRef = node.findAParent(nodes.NodeType.ExtendsReference, nodes.NodeType.Ruleset);
if (parentRef) {
if (parentRef.type === nodes.NodeType.ExtendsReference) {
this.getCompletionsForExtendsReference(<nodes.ExtendsReference>parentRef, node, result);
} else {
const parentRuleSet = <nodes.RuleSet>parentRef;
this.getCompletionsForSelector(parentRuleSet, parentRuleSet && parentRuleSet.isNested(), result);
}
}
} else if (node instanceof nodes.FunctionArgument) {
this.getCompletionsForFunctionArgument(<nodes.FunctionArgument>node, <nodes.Function>node.getParent(), result);
} else if (node instanceof nodes.Declarations) {
this.getCompletionsForDeclarations(<nodes.Declarations>node, result);
} else if (node instanceof nodes.VariableDeclaration) {
this.getCompletionsForVariableDeclaration(<nodes.VariableDeclaration>node, result);
} else if (node instanceof nodes.RuleSet) {
this.getCompletionsForRuleSet(<nodes.RuleSet>node, result);
} else if (node instanceof nodes.Interpolation) {
this.getCompletionsForInterpolation(<nodes.Interpolation>node, result);
} else if (node instanceof nodes.FunctionDeclaration) {
this.getCompletionsForFunctionDeclaration(<nodes.FunctionDeclaration>node, result);
} else if (node instanceof nodes.MixinReference) {
this.getCompletionsForMixinReference(<nodes.MixinReference>node, result);
} else if (node instanceof nodes.Function) {
this.getCompletionsForFunctionArgument(null, <nodes.Function>node, result);
} else if (node instanceof nodes.Supports) {
this.getCompletionsForSupports(<nodes.Supports>node, result);
} else if (node instanceof nodes.SupportsCondition) {
this.getCompletionsForSupportsCondition(<nodes.SupportsCondition>node, result);
} else if (node instanceof nodes.ExtendsReference) {
this.getCompletionsForExtendsReference(<nodes.ExtendsReference>node, null, result);
} else if (node.type === nodes.NodeType.URILiteral) {
this.getCompletionForUriLiteralValue(node, result);
} else if (node.parent === null) {
this.getCompletionForTopLevel(result);
} else if (node.type === nodes.NodeType.StringLiteral && this.isImportPathParent(node.parent.type)) {
this.getCompletionForImportPath(node, result);
// } else if (node instanceof nodes.Variable) {
// this.getCompletionsForVariableDeclaration()
} else {
continue;
}
if (result.items.length > 0 || this.offset > node.offset) {
return this.finalize(result);
}
}
this.getCompletionsForStylesheet(result);
if (result.items.length === 0) {
if (this.variablePrefix && this.currentWord.indexOf(this.variablePrefix) === 0) {
this.getVariableProposals(null, result);
}
}
return this.finalize(result);
} finally {
// don't hold on any state, clear symbolContext
this.position = null!;
this.currentWord = null!;
this.textDocument = null!;
this.styleSheet = null!;
this.symbolContext = null!;
this.defaultReplaceRange = null!;
this.nodePath = null!;
}
}