如何在 Eclipse 编辑器插件中显示语法错误

How to show syntax errors in an eclipse editor plugin(如何在 Eclipse 编辑器插件中显示语法错误)

本文介绍了如何在 Eclipse 编辑器插件中显示语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在 Eclipse 编辑器插件中指示语法错误(例如,非法的标记序列),就像在 Eclipse Java 编辑器中一样,即通过红色扭曲的下划线、滚动条上可以跳转到的红色标记以及将鼠标悬停在其中一个上时会显示说明性消息?

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?

我正在为自定义文件格式(特别是 Shark3D 游戏引擎的蛇文件格式")编写一个 Eclipse 编辑器插件.我已经实现了一个扫描器来获得语法高亮和一个大纲.

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.

  • 对于下划线,我是否只是让扫描仪返回一个带有弯曲下划线"TextAttributeIToken 而不是正常的,或者是否有特定的机制标记语法错误?
  • 如何实现滚动条标记?IAnnotationModel 是这里的相关接口吗?如果是这样,我在哪里注册实现以便标记出现?
  • 我只找到了 SourceViewerConfiguration.getAnnotationHover(),它可以让我实现悬停行为,但仅限于注释",我想这意味着滚动条标记 - 我该怎么做实现文本本身的悬停行为?
  • 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?

我很乐意提供具体建议以及涵盖此内容的教程的 URL - eclipse 帮助文档和示例似乎没有.

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.

标记是最好的解决方案.如何使用它们的工作示例可以在 org.eclipse.ui.examples.readmetool.AddReadmeMarkerAction

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

推荐答案

你应该使用 Markers.

You should be using Markers.

一个来自The Java Developer's Guide to Eclipse"的例子如下:

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 编辑器插件中显示语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Eclipse 编辑器插件中显示语法错误