Community
Participate
Working Groups
I'm developping a plugin for AngularJS https://github.com/angelozerr/angularjs-eclipse which is based on WTP. I have implemented validation for Angular which ignores (ng-* attributes, etc) with Java code without using your feature https://bugs.eclipse.org/bugs/show_bug.cgi?id=415980 But there is some limitation and it should be fantastic if WTP provides an extension point like this : --------------------------------------------------- public interface IHTMLIgnoreValidator { boolean shouldValidateAttributeName(IProject project, Element target, String attrName); boolean shouldValidateElementName((IProject project, Element target); } --------------------------------------------------- For more information please read https://github.com/angelozerr/angularjs-eclipse/issues/80#issuecomment-53044063 https://bugs.eclipse.org/bugs/show_bug.cgi?id=415980
(In reply to Angelo ZERR from comment #0) > I have implemented validation for Angular which ignores (ng-* attributes, > etc) with Java code without using your feature... Why not?
> I have implemented validation for Angular which ignores (ng-* attributes, > etc) with Java code without using your feature... > Why not? Because AngularJS validation is complex. Here several cases : * when user Convert her project to AngularJS project, he doesn't want to ignore at hand each attributes. * with your feature, you can ignore attribute which starts with ng-, but if you have ------------------------------------ <html ng-app="MyApp" ng-xxxx="" > ------------------------------------ => ng-app must be ignored => ng-xxxx must be marked as warn. * you cannot ignore errors for HTML element which are Angular directive. For instance ng-pluralize element name must not be marked as undefined : ----------------------------------- <ng-pluralize /> ----------------------------------- * directive element like ng-pluralize have some attributes like count. So if we have ----------------------------------- <ng-pluralize count="10" xxxxx="" /> ----------------------------------- => ng-pluralize warn must be ignored => count warn must be ignored => xxxx must be marked as warn. if you write : ----------------------------------- <a count="10" /> ----------------------------------- => count must be marked as warn. * attribute, element which are Angular directive can be dynamic (custom directive). You can define angular directive with JS code : ----------------------------------- var app = angular.module('store',[ ]); app.directive('productTitle',function(){ return { restrict: 'E', templateUrl: 'product-title.html' }; }); ----------------------------------- After that, it can write ----------------------------------- <product-title /> ----------------------------------- User doesn't want to ignore at hand "product-tile". AngularJS Eclipse manage automaticly those validation. The basic idea is to override HTMLValidationReporter#report (see https://github.com/angelozerr/angularjs-eclipse/blob/master/org.eclipse.angularjs.core/src/org/eclipse/angularjs/core/validation/HTMLAngularValidationReporter.java) to manage thoses cases, but there is some limitation (like ngPluralize/@count that I cannot validate and I need to create a special validator for AngularJS for each content type (HTML, JSP, PHP, etc)).
New Gerrit change created: https://git.eclipse.org/r/63093
Hi Victor, Many thanks for our work. In AngularJS Eclipse, I need IProject to know if the given project has angular nature to know if angular validation must be done or not. I have seen that IHTMLCustomTagValidator (https://git.eclipse.org/r/#/c/63093/1/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/validate/extension/IHTMLCustomTagValidator.java) provides "boolean canValidate(IDOMElement target)", but even if we can get the IProject from the IDOMElement (by using the location of DOM-SSE), perhaps we could have a new method "boolean canValidate(IFile file)" which is called the first time when validation must be done. In my case, I will implement to know if IFile belong to an angular project.
Angelo, We've splitted the extension interface into two: one for tag validation and yet another one for attributes validation. Having two extansions instead of a single one might be not too handy but anyway tags and attributes have being validated by different independent validators in WTP, so otherwise you'll get two instances of the same validator loaded. As such we think it's better to split the interfaces in order to indicate it and now we have two interfaces: IHTMLCustomTagValidator and IHTMLCustomAttributeValidator. Also, it's not good for WTP Syntax and Attribute Name Validators (those which call these extensions) to translate IStructuredDocument into IFile for minimum three reasons: - WTP as-you-type validation doesn't work with files. It works with IndexedRegion's. - It's not good (in terms of performance) to search for IFile every time we need to validate a tag or an attribute. - There may be no IFile existing for a document (f.i. for external files opened in Editor). So, we've added IStructuredDocument parameter into init methods of IHTMLCustomTagValidator and IHTMLCustomAttributeValidator interfaces. As such, an extension is able to search for either document's source location or even IFile for the document if exists by itself in order to initialize itself. This init(IStructuredDocument) method is to be called only once upon the creation of extension instance, and the instance of document shouldn't be changed after the initialization. So the document, or document's source location/IFile found can be cached once for all the future document validation operations. You can see the following method as an example on how to search for Source Location or IFile by a given document: https://github.com/jbosstools/jbosstools-jst/blob/master/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java#L756 And as you can see in this example, 'null' may be the legal result when searching for an IFile.
For the latest code of the proposal see the Patch Set 2 at https://git.eclipse.org/r/#/c/63093/
Hi Victor, Your API seems very good! I tell me if it works too for JSP. I mean if I declare yours custom validators for HTML, is it working too for JSP too? In AngularJS Eclipse, I had to create an Angular validator for HTML and JSP (with a lot of copy/paste of JSP code of WTP because the JSP validator was not easy to extend, very ugly code!). If it works with JSP, it means that I could remove my Angular Validator dor JSP, HTML and just using your custom validator (I love this idea!) I tell me too if WTP could provide your helper method https://github.com/jbosstools/jbosstools-jst/blob/master/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/PageContextFactory.java#L756 I have a similar utilities method for rmy project based on WTP (AngularJS Eclipse, WTP/XML Search, WTP Web Resources and if for JSON Editor (not sure with that). It should be very cool if WTP could provide this IFile getResource(IDocument document) method. Regard's Angelo
Hi Angelo. Unfortunately, this extensions will work only for HTML files. But I think this extensions can also be adopted for JSP files. But I'd rather wait for review of this extensions. I think it will be good to contribute IFile getResource(IDocument document) method to some utility class, but I need Alexey Kazakov's approoval for this.
Hi Konstantin Many hanks for your information! > Unfortunately, this extensions will work only for HTML files. But I think this extensions can also be adopted for JSP files. But I'd rather wait for review of this extensions. It should be very cool if JSP could works too. In teh case of AngularJS Eclipse I will benefit with: * remove my custom WTP Validator for HTML and JSP * develelop just custom validators to support angular attributes/elements for JSP and HTML both. > I think it will be good to contribute IFile getResource(IDocument document) method to some utility class, Cool! > but I need Alexey Kazakov's approoval for this. Yes sure
>> I think it will be good to contribute IFile getResource(IDocument document) method to some utility class, but I need Alexey Kazakov's approoval for this. I don't mind at all. If WTP guys accept this contribution we can do it.
Update about validation of JSP files: if JSP file have piece of html code, external validator which I contribute to gerrit will be used for validating this fragment. Basically when JSP file validator finds some HTML code, it asks for HTML validator adapters, which is HTML syntax and attribute validator, extension for which is waiting for gerrit review. So everything is better than I expected :) Today I will push Patch Set 3 with getResource utility method.
Great Konstantin! Do you know when your patch could be pushed to master?
>> Do you know when your patch could be pushed to master? I wish to know this too. It's actually a question to Victor, he should ping IBM guys to make a review
> I wish to know this too. It's actually a question to Victor, he should ping IBM guys to make a review Cool! I'm waiting for your push to start implementing custom validator with Angular and give you feedback.
Overall, I think the patch is looking really great. I'm excited to see what people end up doing with the extensible validators.
Nick, could you please give your (+1) (I've requested for your review) in order to let us target this enhancement for m6? Thanks in advance.
It's got my +1 here and on Gerrit.
Hi everybody, I have started to implement custom validator for Angular and I cannot use it to validate attributes because it seems that custom validator is called only for NOT HTML5 element. If i write: ------------------------------------ <nothtml5 ng-app="MyApp" > ------------------------------------ I can validate ng-app attribute. If i write: ------------------------------------ <html ng-app="MyApp" > ------------------------------------ My custom attribute validator is not called, and I cannot ignore the error for ng-app. Regard's Angelo
The angular attribute validation is done for : * HTML elements. ex : <body ng-app="" xxxx="" > (here ng-app is OK and xxxx should be marked as error) * Not HTML element: ex : <ng-pluralize src="" xxxx="" (here src is OK and xxxx should be marked as error) So I have 2 problems with custom attribute validator: 1) I cannot ignore error for body/@ng-app because it is never called. 2) If 1) is implemented, I will not able to delegate validation error (ErrorState.UNDEFINED_NAME_ERROR) for body/@xxxx because in the case of angular ng-app can be exists in any HTML elements. If my IHTMLCustomAttributeValidator#canValidate returns every time tru (because I want to validate body/@ng-app or ng-pluralize/@src, it means that ErrorState.UNDEFINED_NAME_ERROR will never called because of validated flag. See HTMLAttributeValidator# validate(IndexedRegion node): ------------------------------------------------------- boolean validated = false; for (IHTMLCustomAttributeValidator v : externalValidators) { if (v.canValidate((IDOMElement) target)) { validated = true; ValidationMessage result = v.validateAttribute((IDOMElement) target, attrName); if (result != null) { // report only one validation result or nothing if all reports are null reporter.report(result); break; } } } if (!validated) { if (!hasNestedRegion(((IDOMNode) a).getNameRegion())) { Segment seg = getErrorSegment((IDOMNode) a, REGION_NAME); if (seg != null) reporter.report(new ErrorInfoImpl(ErrorState.UNDEFINED_NAME_ERROR, seg, a)); } } -------------------
Hi Angelo. 1. Thank you for this notice, I forgot about the case when you have unknown attribute in known tag. Good news is that this is easy to fix. I think on Friday I will update a code in Gerrit. 2. I don't catch the problem. As I understand, you need to have smth like http://snag.gy/GTays.jpg where warning message is about Undefined name?
(In reply to Konstantin Marmalyukov from comment #20) > Hi Angelo. > > 1. Thank you for this notice, I forgot about the case when you have unknown > attribute in known tag. Good news is that this is easy to fix. I think on > Friday I will update a code in Gerrit. Cool! > > 2. I don't catch the problem. As I understand, you need to have smth like > http://snag.gy/GTays.jpg where warning message is about Undefined name? In this case, I could mark the xxxx attribute as error with my custom validator like "xxxx is not a directive parameter of ng-pluralize", because ng-pluralize belongs to angular. The problem is for <body xxxx="". I would liek to avoid marking error for xxxx because xxxx could be a valid attribute with an another custom validator.
Konstantin, here use cases that you could use for tests. You could have: * test without custom validators * test with HTMLAngularAttributeValidator * test with HTMLAngularAttributeValidator + HTMLDojoAttributeValidator Test could use this HTML: --------------------------------------- <body ng-app="" dojo-type="" xxxx="" > <ng-pluralize src="" xxxx="" > --------------------------------------- When I say "ErrorState.UNDEFINED_NAME_ERROR" it means that it's not the custom validator which marks the error but the HTMLAttributeValidator. 1) test without custom validators * body/ng-app is marked as error with ErrorState.UNDEFINED_NAME_ERROR * body/dojo-type is marked as error with ErrorState.UNDEFINED_NAME_ERROR * body/xxxx is marked as error with ErrorState.UNDEFINED_NAME_ERROR * ng-pluralize/@src is marked as error with ErrorState.UNDEFINED_NAME_ERROR * ng-pluralize/@xxxx is marked as error with ErrorState.UNDEFINED_NAME_ERROR 2) test with HTMLAngularAttributeValidator: * body/ng-app is OK * body/dojo-type is marked as error with ErrorState.UNDEFINED_NAME_ERROR * body/xxxx is marked as error with ErrorState.UNDEFINED_NAME_ERROR * ng-pluralize/@src is OK * ng-pluralize/@xxxx is marked as error with HTMLAngularAttributeValidator 3) test with HTMLAngularAttributeValidator + HTMLDojoAttributeValidator * body/ng-app is OK * body/dojo-type is OK * body/xxxx is marked as error with ErrorState.UNDEFINED_NAME_ERROR * ng-pluralize/@src is OK * ng-pluralize/@xxxx is marked as error with HTMLAngularAttributeValidator
After a talk with Angelo and Konstantine, we decided to do the following changes: 1) allow attribute validation from known tags 2) add (String)attrName parameter into IHTMLCustomAttributeValidator.canValidate() method (so it'll be aligned with an according validateAttribute() method and this will allow to make sure that a validation is to be done for a given attribute) 3) add try-catche for each "external" call in order to make it more robust
Hi Angelo. I push patch set 3 to Gerrit, where I make an updates which Victor mentions above. Could you please try it?
Hi Konstantin > I push patch set 3 to Gerrit, where I make an updates which Victor mentions above. Could you please try it? Yes everything works great! You can see my angular custom validator at https://github.com/angelozerr/angularjs-eclipse/tree/master/org.eclipse.angularjs.core.neon/src/org/eclipse/angularjs/internal/core/validation This custom validator is very powerful. For the moment I use it to : * ignore error for ng-app attribute * ignore error for ng-pluralize element * add error for unknown directive parameter (ex: ng-pluralize/@src is OK but ng-pluralize/@xxxx is marked as "Unknown directive parameter") Wow, I love your work:) I will improve my angular custom validator to validate ng-app value, etc. Many thanks for your great work!
Hi everybody, I would like to know when this feature will be pushed on master? I would like to implement custom validator for my new project angular2-eclipse. Thanks!
I've created the CQ in order to make it possible to push the contribution's code to webtools.sourceediting.
The CQ for the contribution is: https://dev.eclipse.org/ipzilla/show_bug.cgi?id=10999
Gerrit change https://git.eclipse.org/r/63093 was merged to [master]. Commit: http://git.eclipse.org/c/sourceediting/webtools.sourceediting.git/commit/?id=5497b3a7e599091d1e9a78605cb43ddf5aedae7b
New Gerrit change created: https://git.eclipse.org/r/67849
Pushed to master: http://git.eclipse.org/c/sourceediting/webtools.sourceediting.git/commit/?id=5497b3a7e599091d1e9a78605cb43ddf5aedae7b
The webtools.jsf project has to be updated in order to fix the build. See: https://git.eclipse.org/r/67849
Gerrit change https://git.eclipse.org/r/67849 was merged to [master]. Commit: http://git.eclipse.org/c/jsf/webtools.jsf.git/commit/?id=32ea42012281dac7b4e302b32c16ee425bb23d39