From e4c4ea3c4798f4a42599b7cc17398f6fe37d330b Mon Sep 17 00:00:00 2001 From: Nils Reibold Date: Tue, 11 Mar 2025 20:55:30 +0100 Subject: [PATCH] [GH-8313] Allow use of custom HTML-Tags in PHP -register CustomHtmlExtension to x-php5 mimeType -UnknownAttribute hint used to be at wrong position in source when embedded in PHP Example: customs.json ```json { "elements": { "y-customdefined": { "attributes": { "exists": {} } } }, "attributes": {"globaldefined": {}} } ``` PHP script including custom tags, so far none of the tags defined in customs.json will be valid ```php ``` --- .../html/custom/CustomHtmlExtension.java | 5 +++-- .../custom/hints/CheckerElementVisitor.java | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ide/html.custom/src/org/netbeans/modules/html/custom/CustomHtmlExtension.java b/ide/html.custom/src/org/netbeans/modules/html/custom/CustomHtmlExtension.java index 72f433779aab..e6ecfd212d0a 100644 --- a/ide/html.custom/src/org/netbeans/modules/html/custom/CustomHtmlExtension.java +++ b/ide/html.custom/src/org/netbeans/modules/html/custom/CustomHtmlExtension.java @@ -56,7 +56,8 @@ * @author marek */ @MimeRegistrations({ - @MimeRegistration(mimeType = "text/html", service = HtmlExtension.class) + @MimeRegistration(mimeType = "text/html", service = HtmlExtension.class), + @MimeRegistration(mimeType = "text/x-php5", service = HtmlExtension.class) }) public class CustomHtmlExtension extends HtmlExtension { @@ -76,7 +77,7 @@ private Configuration getConfiguration(HtmlSource source) { if (cache == null) { //no cache - create FileObject sourceFileObject = source.getSourceFileObject(); - Project project = sourceFileObject == null ? null : FileOwnerQuery.getOwner(sourceFileObject); + Project project = sourceFileObject == null ? null : FileOwnerQuery.getOwner(sourceFileObject); Configuration conf = project == null ? Configuration.EMPTY : Configuration.get(project); cache = Pair.of(source, conf); return cache.second(); diff --git a/ide/html.custom/src/org/netbeans/modules/html/custom/hints/CheckerElementVisitor.java b/ide/html.custom/src/org/netbeans/modules/html/custom/hints/CheckerElementVisitor.java index 8a7b643b4a1e..07aac041a690 100644 --- a/ide/html.custom/src/org/netbeans/modules/html/custom/hints/CheckerElementVisitor.java +++ b/ide/html.custom/src/org/netbeans/modules/html/custom/hints/CheckerElementVisitor.java @@ -43,10 +43,10 @@ public static ElementVisitor getChecker(RuleContext context, Configuration conf, Collection visitors = new ArrayList<>(); visitors.add(new UnknownAttributesChecker(context, conf, snapshot, hints)); visitors.add(new MissingRequiredAttributeChecker(context, conf, snapshot, hints)); - + return new AggregatedVisitor(visitors); } - + public static class AggregatedVisitor implements ElementVisitor { private final Collection visitors; @@ -54,7 +54,7 @@ public static class AggregatedVisitor implements ElementVisitor { public AggregatedVisitor(Collection visitors) { this.visitors = visitors; } - + @Override public void visit(Element node) { for(ElementVisitor visitor : visitors) { @@ -63,9 +63,9 @@ public void visit(Element node) { } } - + protected abstract static class Checker implements ElementVisitor { - + protected RuleContext context; protected Configuration conf; protected Snapshot snapshot; @@ -116,7 +116,7 @@ public void visit(Element node) { boolean lineHint = false; //use the whole element offsetrange so multiple unknown attributes can be handled - OffsetRange range = new OffsetRange(snapshot.getEmbeddedOffset(ot.from()), snapshot.getEmbeddedOffset(ot.to())); + OffsetRange range = new OffsetRange(snapshot.getOriginalOffset(ot.from()), snapshot.getOriginalOffset(ot.to())); hints.add(new UnknownAttributes(unknownAttributeNames, tagModel.getName(), context, range, lineHint)); } } @@ -125,7 +125,7 @@ public void visit(Element node) { } } - private static class MissingRequiredAttributeChecker extends Checker { + private static class MissingRequiredAttributeChecker extends Checker { public MissingRequiredAttributeChecker(RuleContext context, Configuration conf, Snapshot snapshot, List hints) { super(context, conf, snapshot, hints); @@ -157,6 +157,6 @@ public void visit(Element node) { } } } - - + + }