|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2016 Red Hat Inc. and others. |
| 2 | + * Copyright (c) 2016, 2025 Red Hat Inc. and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials
|
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0
|
@@ -42,16 +42,21 @@ public BarContentAssistProcessor(String completeString) {
|
42 | 42 |
|
43 | 43 | @Override
|
44 | 44 | public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
|
45 |
| - for (int offsetInProposal = Math.min(this.completeString.length(), viewer.getDocument().getLength()); offsetInProposal > 0; offsetInProposal--) { |
46 |
| - String maybeMatchingString = this.completeString.substring(0, offsetInProposal); |
47 |
| - try { |
48 |
| - int lastIndex = offset - offsetInProposal + this.completeString.length(); |
49 |
| - if (offset >= offsetInProposal && viewer.getDocument().get(offset - offsetInProposal, maybeMatchingString.length()).equals(maybeMatchingString)) { |
50 |
| - CompletionProposal proposal = new CompletionProposal(this.completeString.substring(offsetInProposal), offset, 0, lastIndex); |
51 |
| - return new ICompletionProposal[] { proposal }; |
| 45 | + if (viewer.getDocument() != null) { |
| 46 | + for (int offsetInProposal = Math.min(this.completeString.length(), |
| 47 | + viewer.getDocument().getLength()); offsetInProposal > 0; offsetInProposal--) { |
| 48 | + String maybeMatchingString = this.completeString.substring(0, offsetInProposal); |
| 49 | + try { |
| 50 | + int lastIndex = offset - offsetInProposal + this.completeString.length(); |
| 51 | + if (offset >= offsetInProposal && viewer.getDocument() |
| 52 | + .get(offset - offsetInProposal, maybeMatchingString.length()).equals(maybeMatchingString)) { |
| 53 | + CompletionProposal proposal = new CompletionProposal( |
| 54 | + this.completeString.substring(offsetInProposal), offset, 0, lastIndex); |
| 55 | + return new ICompletionProposal[] { proposal }; |
| 56 | + } |
| 57 | + } catch (BadLocationException e) { |
| 58 | + e.printStackTrace(); |
52 | 59 | }
|
53 |
| - } catch (BadLocationException e) { |
54 |
| - e.printStackTrace(); |
55 | 60 | }
|
56 | 61 | }
|
57 | 62 | return new ICompletionProposal[0];
|
|
0 commit comments