如何在eclipse编辑器插件中显示语法错误 [英] How to show syntax errors in an eclipse editor plugin
问题描述
我正在为自定义文件格式(特别是Shark3D游戏的snake文件格式)编写一个eclipse编辑器插件发动机)。我已经实现了一个扫描器来获取语法高亮和大纲。
- 对于下划线,我只需让扫描仪返回一个
IToken
wriggly underlineTextAttribute
而不是正常的,还是有一个特殊的机制来标记语法错误? - 如何实现滚动条标记?是否有
IAnnotationModel
相关界面?如果是这样,我在哪里注册实现,以便标记出现? - 我只找到
SourceViewerConfiguration.getAnnotationHover()
,这将允许我实现悬停行为,但只有注释,我认为是滚动条标记 - 如何实现文本本身的悬停行为?
我会快乐的具体建议以及涵盖这一点的教程的网址 - eclipse帮助文档和示例似乎没有。
编辑:
标记是最好的解决方案。有关如何使用它们的工作示例可以在 org.eclipse.ui.examples.readmetool.AddReadmeMarkerAction
你应该使用标记。
从Java开发人员Eclipse指南派生的示例如下:
< extension point =org.eclipse.core.resources.markers
id =snakesyntax
name =Snake syntax error>
< super type =org.eclipse.core.resources.problemmarker/>
< super type =org.eclipse.core.resources.textmarker/>
< persistent value =true/>
< extension>
IMarker marker = res.createMarker(com.ibm.tool.resources.snakesyntax);
marker.setAttribute(IMarker.SEVERITY,0);
marker.setAttribute(IMarker.CHAR_START,startOfSyntaxError);
marker.setAttribute(IMarker.CHAR_END,endOfSyntaxError);
marker.setAttribute(IMarker.LOCATION,Snake file);
marker.setAttribute(IMarker.MESSAGE,Syntax error);
How can I indicate syntax errors (e.g. an illegal sequence of tokens) in an eclipse editor plugin just like in the eclipse Java editor, i.e. by red wriggly underlines, a red marker on the scrollbar that you can jump to, and an explanatory message when you hover over either one?
I'm writing an eclipse editor plugin for a custom file format (specifically, the "snake file format" of the Shark3D game engine). I have implemented a scanner to get syntax highlighting, and an outline.
- For the underlines, do I simply have the scanner return an
IToken
with a "wriggly underline"TextAttribute
instead of the normal one, or is there a specific mechanism for marking syntax errors? - How do I implement the scrollbar markers? Is
IAnnotationModel
the relevant interface here? If so, where do I register the implementation so that the markers appear? - I've only found
SourceViewerConfiguration.getAnnotationHover()
, which would allow me to implement the hover behaviour, but only for the "annotation", which I suppose means the scrollbar markers - how do I implement the hover behaviour for the text itself?
I'd be happy specific advice as well as an URL of a tutorial that covers this - the eclipse help documents and examples don't seem to.
Edit:
Markers are the best solutions to this. A working example of how to use them can be found in the plugin example code in org.eclipse.ui.examples.readmetool.AddReadmeMarkerAction
You should be using Markers.
An example derived from "The Java Developer's Guide to Eclipse" follows:
<extension point="org.eclipse.core.resources.markers"
id="snakesyntax"
name="Snake syntax error">
<super type="org.eclipse.core.resources.problemmarker" />
<super type="org.eclipse.core.resources.textmarker" />
<persistent value="true" />
<extension>
IMarker marker = res.createMarker("com.ibm.tool.resources.snakesyntax");
marker.setAttribute(IMarker.SEVERITY, 0);
marker.setAttribute(IMarker.CHAR_START, startOfSyntaxError);
marker.setAttribute(IMarker.CHAR_END, endOfSyntaxError);
marker.setAttribute(IMarker.LOCATION, "Snake file");
marker.setAttribute(IMarker.MESSAGE, "Syntax error");
这篇关于如何在eclipse编辑器插件中显示语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!