private getPropertyCompletions()

in language-service/src/services/yamlCompletion.ts [245:299]


    private getPropertyCompletions(schema: SchemaService.ResolvedSchema, doc: SingleYAMLDocument, node: Parser.ASTNode, addValue: boolean, collector: CompletionsCollector, separatorAfter: string): void {
        const nodeProperties: Parser.PropertyASTNode[] = (<Parser.ObjectASTNode>node).properties;
        const hasMatchingProperty = (key: string, propSchema: JSONSchema): boolean => {
            return nodeProperties.some((propertyNode: Parser.PropertyASTNode): boolean => {
                let propertyKey: string = propertyNode.key.value;

                if (propertyKey === key) {
                    return true;
                }

                const ignoreCase: boolean = Parser.ASTNode.getIgnoreKeyCase(propSchema);
                if (ignoreCase) {
                    propertyKey = propertyKey.toUpperCase();

                    if (propertyKey === key.toUpperCase()) {
                        return true;
                    }
                }

                if (Array.isArray(propSchema.aliases)) {
                    return propSchema.aliases.some((alias: string): boolean => {
                        const testAlias: string = ignoreCase ? alias.toUpperCase() : alias;
                        return testAlias === propertyKey;
                    });
                }
                return false;
            });
        }

        const matchingSchemas = doc.getMatchingSchemas(schema.schema);
        matchingSchemas.forEach((s) => {
            if (s.node === node && !s.inverted) {
                const schemaProperties = s.schema.properties;
                if (schemaProperties) {
                    Object.keys(schemaProperties).forEach((key: string) => {
                        //check for more than one property because the placeholder will always be in the list
                        if (s.node['properties'].length > 1 || this.arrayIsEmptyOrContainsKey(s.schema.firstProperty, key)) {
                            const propertySchema = schemaProperties[key];
                            if (!propertySchema.deprecationMessage &&
                                !propertySchema["doNotSuggest"] &&
                                !hasMatchingProperty(key, propertySchema)) {
                                collector.add({
                                    kind: CompletionItemKind.Property,
                                    label: key,
                                    insertText: this.getInsertTextForProperty(key, propertySchema, addValue, separatorAfter),
                                    insertTextFormat: InsertTextFormat.Snippet,
                                    documentation: propertySchema.description || ''
                                });
                            }
                        }
                    });
                }
            }
        });
    }