@@ -208,22 +208,21 @@ private void collectHighlights(int caretOffset, long timestamp, @Nullable IProgr
208208 return ;
209209 }
210210
211-
212- // Normalize the cache key to the start of the word/symbol.
213- final int cacheKeyOffset = normalizedOffset (document , caretOffset );
214-
215- // Only cancel previous requests if the target symbol actually changed.
216- if (cacheKeyOffset != lastCacheKeyOffset ) {
217- cancel ();
218- lastCacheKeyOffset = cacheKeyOffset ;
219- }
220-
221211 if (DocumentUtil .getDocumentModificationStamp (document ) != timestamp ) {
222212 return ;
223213 }
224214
225- Position position ;
215+ final Position position ;
216+ final int cacheKeyOffset ;
226217 try {
218+ // Normalize the cache key to the start of the word/symbol.
219+ cacheKeyOffset = normalizedOffset (document , caretOffset );
220+
221+ // Only cancel previous requests if the target symbol actually changed.
222+ if (cacheKeyOffset != lastCacheKeyOffset ) {
223+ cancel ();
224+ lastCacheKeyOffset = cacheKeyOffset ;
225+ }
227226 // Send the original caret offset to the LS to preserve behavior
228227 // expected by tests and servers that distinguish positions within a word.
229228 position = LSPEclipseUtils .toPosition (caretOffset , document );
@@ -323,22 +322,17 @@ private Object getLockObject(IAnnotationModel annotationModel) {
323322 * Compute a stable cache key for the symbol at the given caret offset by
324323 * normalizing to the start of the Unicode identifier under the caret.
325324 */
326- private static int normalizedOffset (final IDocument document , final int offset ) {
327- try {
328- // Walk left to the first non-identifier part, then move right one.
329- int pos = Math .max (0 , offset - 1 );
330- final int docLen = document .getLength ();
331- while (pos >= 0 && pos < docLen ) {
332- if (!Character .isUnicodeIdentifierPart (document .getChar (pos ))) {
333- break ;
334- }
335- pos --;
325+ private static int normalizedOffset (final IDocument document , final int offset ) throws BadLocationException {
326+ // Walk left to the first non-identifier part, then move right one.
327+ int pos = Math .max (0 , offset - 1 );
328+ final int docLen = document .getLength ();
329+ while (pos >= 0 && pos < docLen ) {
330+ if (!Character .isUnicodeIdentifierPart (document .getChar (pos ))) {
331+ break ;
336332 }
337- return Math .min (docLen , pos + 1 );
338- } catch (final BadLocationException ex ) {
339- LanguageServerPlugin .logError (ex .getMessage (), ex );
340- return offset ;
333+ pos --;
341334 }
335+ return Math .min (docLen , pos + 1 );
342336 }
343337
344338 void removeOccurrenceAnnotations () {
0 commit comments