gpt4 book ai didi

java - 我需要 IMarker 的 char_start 和 char_end

转载 作者:行者123 更新时间:2023-12-01 15:06:18 24 4
gpt4 key购买 nike

我正在创建 IMarkers,我有行号,但需要 char_start 和 char_end。创建标记后,标记所连接的文件可能无法在编辑器中打开。如何在不打开文件的情况下获取 char_start 和 char_end 偏移量?现在标记突出显示整行,但我希望它忽略前导空白。

最佳答案

我自己解决了这个问题。我确信有一种更有效的方法可以做到这一点,但这对于我的目的来说暂时有效。

IPath path = Path.fromOSString(file);
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);

ITextFileBufferManager iTextFileBufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer iTextFileBuffer = null;
IDocument iDoc = null;
try {
iTextFileBufferManager.connect(iFile.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
iTextFileBuffer = iTextFileBufferManager.getTextFileBuffer(iFile.getFullPath(), LocationKind.IFILE);
iDoc = iTextFileBuffer.getDocument();

iTextFileBufferManager.disconnect(iFile.getFullPath(), LocationKind.IFILE, new NullProgressMonitor());
} catch (Exception e) {
e.printStackTrace();
}

int start = iDoc.getLineOffset(iline - 1);
int end = iDoc.getLineLength(iline - 1);

//this next section was done to remove the leading white spaces
while(iDoc.getChar(start) == ' ' || iDoc.getChar(start) == '\t'){
start++;
end--;
}

final int charStart = start;
final int charEnd = start + end;

关于java - 我需要 IMarker 的 char_start 和 char_end,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12903224/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com