@@ -234,7 +234,9 @@ public int getRankScore() {
234234 rankScore = CompletionProposalTools .getScoreOfFilterMatch (getDocumentFilter (),
235235 getFilterString ());
236236 } catch (BadLocationException e ) {
237- LanguageServerPlugin .logError (e );
237+ // Document was changed while we computed completion proposals, which made the
238+ // offset invalid. We can stop any further computation as the result will be
239+ // discarded anyway.
238240 rankScore = -1 ;
239241 }
240242 this .rankScore = rankScore ;
@@ -257,7 +259,9 @@ public int getRankCategory() {
257259 rankCategory = CompletionProposalTools .getCategoryOfFilterMatch (getDocumentFilter (),
258260 getFilterString ());
259261 } catch (BadLocationException e ) {
260- LanguageServerPlugin .logError (e );
262+ // Document was changed while we computed completion proposals, which made the
263+ // offset invalid. We can stop any further computation as the result will be
264+ // discarded anyway.
261265 rankCategory = CompletionProposalTools .CATEGORY_NO_MATCH ;
262266 }
263267 this .rankCategory = rankCategory ;
@@ -442,27 +446,25 @@ private void updateCompletionItem(@Nullable CompletionItem resolvedItem) {
442446
443447 @ Override
444448 public int getPrefixCompletionStart (IDocument document , int completionOffset ) {
445- Either < TextEdit , InsertReplaceEdit > textEdit = item . getTextEdit ();
446- if ( textEdit != null ) {
447- try {
449+ try {
450+ Either < TextEdit , InsertReplaceEdit > textEdit = item . getTextEdit ();
451+ if ( textEdit != null ) {
448452 return LSPEclipseUtils .toOffset (getTextEditRange ().getStart (), document );
449- } catch (BadLocationException e ) {
450- LanguageServerPlugin .logError (e );
451453 }
452- }
453- final String insertText = getInsertText ();
454- final int insertTextLength = insertText .length ();
455- try {
456- String subDoc = document .get (
457- Math .max (0 , completionOffset - insertTextLength ),
454+
455+ final String insertText = getInsertText ();
456+ final int insertTextLength = insertText .length ();
457+ String subDoc = document .get (Math .max (0 , completionOffset - insertTextLength ),
458458 Math .min (insertTextLength , completionOffset ));
459459 for (int i = 0 ; i < insertTextLength && i < completionOffset ; i ++) {
460460 if (insertText .regionMatches (true , 0 , subDoc , i , subDoc .length () - i )) {
461461 return completionOffset - subDoc .substring (i ).length ();
462462 }
463463 }
464464 } catch (BadLocationException e ) {
465- LanguageServerPlugin .logError (e );
465+ // Document was changed while we computed completion proposals, which made the
466+ // offset invalid. We can stop any further computation as the result will be
467+ // discarded anyway.
466468 }
467469 return completionOffset ;
468470 }
0 commit comments