Skip to content

Commit 7c0ea07

Browse files
committed
Workaround spread syntax upstream
jupyterlab/jupyterlab#15125
1 parent 313349e commit 7c0ea07

File tree

1 file changed

+27
-0
lines changed
  • packages/jupyterlab-lsp/src/features/completion

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ export class CompletionItem implements IExtendedCompletionItem {
6767
this.self = this;
6868
this.source = options.source;
6969
this.icon = options.icon ? options.icon : undefined;
70+
71+
// Upstream is sometimes using spread operator to copy the object (in reconciliator),
72+
// which does not copy getters because these are not enumerable; we should use
73+
// `Object.assign` upstream, but them, but for now marking relevant properties as enumerable is enough
74+
// Ideally this would be fixed and tested e2e in JupyterLab 4.0.7.
75+
// https://github.com/jupyterlab/jupyterlab/issues/15125
76+
makeGetterEnumerable(this, 'insertText');
7077
}
7178

7279
get type() {
@@ -185,3 +192,23 @@ export class CompletionItem implements IExtendedCompletionItem {
185192
);
186193
}
187194
}
195+
196+
function makeGetterEnumerable(instance: object, name: string) {
197+
const generatedDescriptor = findDescriptor(instance, name);
198+
Object.defineProperty(instance, name, {
199+
enumerable: true,
200+
get: generatedDescriptor.get,
201+
set: generatedDescriptor.set
202+
});
203+
}
204+
205+
function findDescriptor(instance: object, name: string) {
206+
while (instance) {
207+
const desc = Object.getOwnPropertyDescriptor(instance, name);
208+
if (desc) {
209+
return desc;
210+
}
211+
instance = Object.getPrototypeOf(instance);
212+
}
213+
throw Error(`No ${name} descriptor found.`);
214+
}

0 commit comments

Comments
 (0)