在eclipse插件中获取行号 [英] get line number within a eclipse Plugin
问题描述
我正在为插件寻找正确的扩展点,以便在编辑器中访问光标位置。目的是在插件视图中为当前的代码行提供其他信息。
我确定这是可能的,因为大纲视图例如突出显示了我现在的功能。
thx
I'm looking for the right extension point for my plugin to access the cursor position in the editor. The aim is to provide additional information to the current code line in a plugin view. I sure it is possible, since the Outline view for example highlights the current function which I'm within. thx
推荐答案
可以使用 textSelection.getOffset()
从您找到的模式,然后使用 org.eclipse.jface.text.IDocument
接口从文档中提取文本,以执行任何您想要的分析。 p>
You can use textSelection.getOffset()
from the pattern you've found and then use the org.eclipse.jface.text.IDocument
interface to extract text from the document to do whatever analysis you want.
ITextEditor textEditor = (ITextEditor)editor;
IDocumentProvider dp = editor.getDocumentProvider();
IDocument doc = dp.getDocument(editor.getEditorInput());
IDocument
有方法来回转换在字符偏移和行之间。
IDocument
has methods to convert back and forth between character offsets and lines.
这篇关于在eclipse插件中获取行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!