Skip to content

Commit 8a16869

Browse files
committed
Fix dictionary completion issue for jedi-language-server
that would have led to "Code Editor out of Sync" error
1 parent 4def87c commit 8a16869

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/jupyterlab-lsp/src/features/completion/completion_handler.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,15 @@ export class LSPConnector
354354
this.console.debug('Transformed');
355355
// required to make the repetitive trigger characters like :: or ::: work for R with R languageserver,
356356
// see https://github.com/krassowski/jupyterlab-lsp/issues/436
357-
const prefix_offset = token.value.length;
357+
let prefix_offset = token.value.length;
358+
// completion of dictionaries for Python with jedi-language-server was
359+
// causing an issue for dic['<tab>'] case; to avoid this let's make
360+
// sure that prefix.length >= prefix.offset
361+
if (all_non_prefixed && prefix_offset > prefix.length) {
362+
prefix_offset = prefix.length;
363+
}
358364

359-
return {
365+
let response = {
360366
// note in the ContextCompleter it was:
361367
// start: token.offset,
362368
// end: token.offset + token.value.length,
@@ -370,6 +376,14 @@ export class LSPConnector
370376
end: token.offset + prefix.length,
371377
items: items
372378
};
379+
if (response.start > response.end) {
380+
console.warn(
381+
'Response contains start beyond end; this should not happen!',
382+
response
383+
);
384+
}
385+
386+
return response;
373387
}
374388

375389
protected icon_for(type: string): LabIcon {

0 commit comments

Comments
 (0)