@xml-tools/simple-schema
Version:
XML Simple Schema
31 lines (26 loc) • 714 B
JavaScript
const { difference, map } = require("lodash");
/**
* @param {XMLElement} elementNode
* @param {XSSElement} xssElement
*
* @returns {CompletionSuggestion[]}
*/
function attributeNameCompletion(elementNode, xssElement) {
const possibleSuggestions = map(xssElement.attributes, (_) => _.key);
const existingAttribNames = map(elementNode.attributes, (_) => _.key);
const possibleNewSuggestions = difference(
possibleSuggestions,
existingAttribNames
);
const suggestions = map(possibleNewSuggestions, (_) => {
return {
text: _,
label: _,
commitCharacter: "=",
};
});
return suggestions;
}
module.exports = {
attributeNameCompletion: attributeNameCompletion,
};