Skip to content

Commit

Permalink
Bugfix for eclipse-platform#2453: NPE in BarContentAssistProcessor.
Browse files Browse the repository at this point in the history
  • Loading branch information
nettozahler committed Nov 3, 2024
1 parent c1c681a commit 591b8d4
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ public BarContentAssistProcessor(String completeString) {

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
for (int offsetInProposal = Math.min(this.completeString.length(), viewer.getDocument().getLength()); offsetInProposal > 0; offsetInProposal--) {
final IDocument doc= viewer.getDocument();
if (doc == null) {
return new ICompletionProposal[0];
}
for (int offsetInProposal = Math.min(this.completeString.length(), doc.getLength()); offsetInProposal > 0; offsetInProposal--) {
String maybeMatchingString = this.completeString.substring(0, offsetInProposal);
try {
int lastIndex = offset - offsetInProposal + this.completeString.length();
if (offset >= offsetInProposal && viewer.getDocument().get(offset - offsetInProposal, maybeMatchingString.length()).equals(maybeMatchingString)) {
if (offset >= offsetInProposal && doc.get(offset - offsetInProposal, maybeMatchingString.length()).equals(maybeMatchingString)) {
CompletionProposal proposal = new CompletionProposal(this.completeString.substring(offsetInProposal), offset, 0, lastIndex);
return new ICompletionProposal[] { proposal };
}
Expand Down Expand Up @@ -98,13 +102,13 @@ public IContextInformationValidator getContextInformationValidator() {
return new IContextInformationValidator() {
private ITextViewer viewer;
private int offset;

@Override
public void install(IContextInformation info, ITextViewer infoViewer, int documentOffset) {
this.viewer= infoViewer;
this.offset= documentOffset;
}

@Override
public boolean isContextInformationValid(int offsetToTest) {
try {
Expand All @@ -123,5 +127,4 @@ public boolean isContextInformationValid(int offsetToTest) {
public String getErrorMessage() {
return null;
}

}

0 comments on commit 591b8d4

Please sign in to comment.