import { find , includes } from "lodash" ; import { XMLAttribute } from "@xml-tools/ast" ; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types" ; import { findSymbol } from "@ui5-language-assistant/semantic-model" ; import { isXMLNamespaceKey } from "@xml-tools/common" ; import { UnknownNamespaceInXmlnsAttributeValueIssue } from "../../../api" ; export function validateUnknownXmlnsNamespace ( attribute , model ) { const attributeName = attribute . key ; if ( attributeName === null || ! isXMLNamespaceKey ( { key : attributeName , includeEmptyPrefix : true } ) ) { return [ ] ; } const attributeValue = attribute . value ; const attributeValueToken = attribute . syntax . value ; if ( attributeValueToken === undefined || attributeValue === null ) { return [ ] ; } const allowedListedNamespaces = [ "sap.ui.dt" ] ; if ( includes ( allowedListedNamespaces , attributeValue ) ) { return [ ] ; } const reservedNamespaceRoots = model . namespaces [ "sap" ] ?. namespaces ; if ( find ( reservedNamespaceRoots , ( _ , fqn ) => attributeValue . startsWith ( fqn + "." ) ) === undefined ) { return [ ] ; } if ( findSymbol ( model , attributeValue ) === undefined ) { return [ { kind : "UnknownNamespaceInXmlnsAttributeValue" , message : `Unknown namespace: ${ attributeValueToken . image }` , offsetRange : { start : attributeValueToken . startOffset , end : attributeValueToken . endOffset , } , severity : "warn" , } , ] ; } return [ ] ; }