Line number and identifier for autocomlpete are evaluated correctly now.

This commit is contained in:
Michael Uhl 2018-12-25 15:25:51 +01:00
parent dc35bb6005
commit dd6d5de33c

View File

@ -43,10 +43,15 @@ public class JafCompletionProcess implements IContentAssistProcessor {
String indent = lastIndent(doc, offset);
ArrayList<ICompletionProposal> result = new ArrayList<>();
/*
for (String ti : editor.resolveTypeInserts()) {
String proposal = ti;
result.add(new CompletionProposal(proposal, offset - prefix.length(), prefix.length(), proposal.length()));
}
*/
String proposal = "Line '" + evaluateLineNumber(doc, offset) + "' identifer '" + lastWord(doc, offset) + "'.";
result.add(new CompletionProposal(proposal, offset - prefix.length(), prefix.length(), proposal.length()));
return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]);
}
@ -62,6 +67,7 @@ public class JafCompletionProcess implements IContentAssistProcessor {
}
private String lastWord(IDocument doc, int offset) {
offset--;
try {
for (int n = offset - 1; n >= 0; n--) {
char c = doc.getChar(n);
@ -74,6 +80,20 @@ public class JafCompletionProcess implements IContentAssistProcessor {
return "";
}
private int evaluateLineNumber(IDocument doc, int offset) {
int lineNbr = 1;
for (int i = offset; i > 0; i--) {
try {
if (doc.getChar(i) == '\n') {
lineNbr++;
}
} catch (BadLocationException e) {
LOG.log(new Status(ERROR, PLUGIN_ID, e.getMessage(), e));
}
}
return lineNbr;
}
private char lastChar(IDocument doc, int offset) {
try {
return doc.getChar(offset -1);