Fix missing inherited getters in enumeratePropertyCompletions #17

Merged
sirxemic merged 1 commit from fix-missing-autocompletions into main 2026-02-08 11:24:19 +01:00
sirxemic commented 2026-02-07 23:46:08 +01:00 (Migrated from github.com)

Take this example:

class Base {
  a = { b: 10 }
  get foo() { return this.a.b }
}

class ChildClass extends Base {}

const scope = { test: new ChildClass() }

When using scopeCompletionSource(scope) as an extension, the autocompletion of test. will list a but not the inherited getter foo. This is because when calling obj[name] while iterating over the properties of Object.getPrototypeOf(obj), this refers to the prototype and not the instance. So this.a returns undefined and thus this.a.b throws an error.

Hopefully the issue becomes clear by just looking at the fix.

Take this example: ```js class Base { a = { b: 10 } get foo() { return this.a.b } } class ChildClass extends Base {} const scope = { test: new ChildClass() } ``` When using `scopeCompletionSource(scope)` as an extension, the autocompletion of `test.` will list `a` but not the inherited getter `foo`. This is because when calling `obj[name]` while iterating over the properties of `Object.getPrototypeOf(obj)`, `this` refers to the prototype and not the instance. So `this.a` returns `undefined` and thus `this.a.b` throws an error. Hopefully the issue becomes clear by just looking at the fix.
marijnh commented 2026-02-08 11:24:30 +01:00 (Migrated from github.com)

That makes sense. Thanks!

That makes sense. Thanks!
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/lang-javascript!17
No description provided.