Skip to content

Commit 14046c4

Browse files
committed
Fix highlights not updating when switching documents
1 parent cfac3fc commit 14046c4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/jupyterlab-lsp/src/features/highlights.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ export class HighlightsFeature extends Feature {
7070
>;
7171
private _virtualPosition: IVirtualPosition;
7272
private _versionSent: number;
73-
private _lastToken: CodeEditor.IToken | null = null;
73+
private _lastToken: {
74+
token: CodeEditor.IToken;
75+
adapter: WidgetLSPAdapter<any>;
76+
} | null = null;
7477

7578
constructor(options: HighlightsFeature.IOptions) {
7679
super(options);
@@ -297,10 +300,12 @@ export class HighlightsFeature extends Feature {
297300
const token = editor.getTokenAt(offset);
298301

299302
// if token has not changed, no need to update highlight, unless it is an empty token
300-
// which would indicate that the cursor is at the first character
303+
// which would indicate that the cursor is at the first character; we also need to check
304+
// adapter in case if user switched between documents/notebooks.
301305
if (
302306
this._lastToken &&
303-
token.value === this._lastToken.value &&
307+
token.value === this._lastToken.token.value &&
308+
adapter === this._lastToken.adapter &&
304309
token.value !== ''
305310
) {
306311
this.console.log(
@@ -352,7 +357,10 @@ export class HighlightsFeature extends Feature {
352357
}
353358

354359
this.handleHighlight(highlights, adapter, document);
355-
this._lastToken = token;
360+
this._lastToken = {
361+
token,
362+
adapter
363+
};
356364
} catch (e) {
357365
this.console.warn('Could not get highlights:', e);
358366
}

0 commit comments

Comments
 (0)