首页 > 解决方案 > Eclipse plugin to remove validation from existing editor

问题描述

I'm creating an Eclipse RCP application that handle a custom file format which is very similar to HTML so for the most part I can use the regular HTML editor that comes with Eclipse to take advantage of its features like syntax highlight and content assist, but this custom format includes some characters/tags that are invalid in HTML, for example <#= my text #> so when adding that to a file, like the following line:

<body><#= my text #></body>

the editor's validator will display this error:

Invalid character used in text string (<#= my text #>).

So I was wondering if it is possible to modify the behavior of an existing editor/validator to remove some specific validations and maybe add other ones.

标签: javaeclipse-plugineclipse-rcp

解决方案


是的,尽管这听起来像是理想情况下从 JSP 编辑器的一个分支开始,从它的解析器一直向上......

如果您使用org.eclipse.core.contenttype.contentTypes扩展点定义了一个新的内容类型(使用您的新文件扩展名),然后为源验证扩展点提供一个验证器org.eclipse.wst.sse.ui.sourcevalidation,明确地为您的内容类型,应跳过 HTML 验证器以尊重更多为您的内容类型定义的特定内容。https://github.com/eclipse/webtools.sourceediting/blob/0c532000ad09e53c9fb8ddfb1c3f1def983f57c0/core/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/reconcile/DocumentRegionProcessor。 java#L266显示了它在哪里寻找特定于内容类型的验证器,并且比它在基本(不太具体)内容类型中定义的任何验证器更喜欢那些。


推荐阅读