Skip to content

Commit 7b31ac4

Browse files
committed
Fix some issues with bnd instruction autocompleter:
- If line is comment, don't propose any autocompletion - Do not autocomplete if line already contains an instruction - Do not provide auto-completion for continuation lines
1 parent 8304f4a commit 7b31ac4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

ui/org.eclipse.pde.bnd.ui/src/org/eclipse/pde/bnd/ui/autocomplete/BndCompletionProcessor.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
4949
try {
5050
IDocument document = viewer.getDocument();
5151
IRegion lineInfo = document.getLineInformationOfOffset(offset);
52+
if (isCommentLine(document, lineInfo) || isInstructionLine(document, lineInfo)
53+
|| isContinuationLine(document, lineInfo, false)) {
54+
// do not even try proposals
55+
return new ICompletionProposal[0];
56+
}
5257
if (lineInfo.getOffset() != offset) {
5358
String pre = document.get(0, offset);
5459
Matcher matcher = PREFIX_PATTERN.matcher(pre);
@@ -78,6 +83,44 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
7883
}
7984
}
8085

86+
private boolean isContinuationLine(IDocument document, IRegion lineInfo, boolean onlyCurrent) {
87+
int o = lineInfo.getOffset();
88+
int l = lineInfo.getLength();
89+
try {
90+
String line = document.get(o, l);
91+
if (line.trim().endsWith("\\")) {
92+
// the line itself is a continuation line
93+
return true;
94+
} else if (onlyCurrent) {
95+
return false;
96+
}
97+
return isContinuationLine(document, document.getLineInformationOfOffset(o - 1), true);
98+
} catch (BadLocationException e) {
99+
return false;
100+
}
101+
}
102+
103+
private boolean isInstructionLine(IDocument document, IRegion lineInfo) {
104+
int o = lineInfo.getOffset();
105+
int l = lineInfo.getLength();
106+
try {
107+
String line = document.get(o, l);
108+
return line.indexOf(':') > -1 || line.indexOf('=') > -1;
109+
} catch (BadLocationException e) {
110+
return false;
111+
}
112+
}
113+
114+
protected boolean isCommentLine(IDocument document, IRegion lineInfo) {
115+
int o = lineInfo.getOffset();
116+
int l = lineInfo.getLength();
117+
try {
118+
return document.get(o, l).startsWith("#");
119+
} catch (BadLocationException e) {
120+
return false;
121+
}
122+
}
123+
81124
private static ICompletionProposal[] proposals(String prefix, int offset) {
82125
ArrayList<ICompletionProposal> results = new ArrayList<>(Syntax.HELP.size());
83126
for (Syntax s : Syntax.HELP.values()) {

0 commit comments

Comments
 (0)