Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Multiple instances of Event class for the same event cause events being missed #2323

Open
onivim/oni-types
#4
@GeorgeTG

Description

@GeorgeTG

Oni Version: 0.3.4 and 0.3.5 from latest git
Neovim Version (Linux only): 0.3.0
Operating System: Arch-Linux

Describe your issue

When navigating with j,k a lot of errors are thrown in the console window because editorManager.activeEditor.activeBuffer. is null.
This happens because NeovimEditor's lastBufferId is null which in turn happens because
onBufEnter event is seemingly never called.

Now that is the part things get complicated.

Event handling happens through oni-types Event class.
So the oni-types Event class instantiates a new EventEmitter for each instance of the Event class.
Because of this for subscribe and dispatch to work, the same instance of the Event class must be used by the subscriber(s) and the dispatcher(s) basically meaning that all events must be singletons, although no measures are taken to enforce this.
(This behaviour also eliminates the need for the name parameter, since it is ignored and not used anyway.)
Of course if the name argument was provided for all events a single EventEmitter would be enough and the whole problem would be "patched", but the core of the problem is not the Event system by itself.

In the current state of the code, some events have two instances. One instance is dispatching, while the Editor is subscribed to the other. As of now I'm pretty sure that this happens with atleast all NeovimAutoCommands/Editor related Events.
A NeovimAutoCommands instance is created only in NeovimInstance.

Now things get even more complicated and confusing.
Two NeovimInstance instances are created that result in two NeovimProcessSpawner::startNeovim calls which basically runs nvim two times and I'm not sure if this is intended. Again it looks like NeovimInstance should be a singleton, but it isn't.

The first NeovimInstance is created in NeovimEditor which is a SuperClass of OniEditor and is instantiated in startEditors.
The second one is created in SharedNeovimInstance which is a NeovimInstance wrapper.
Now both startEditors and SharedNeovimInstance reside in App.ts so I guess the intended behaviour would be to pass the SharedNeovimInstance's NeovimInstance to startEditors or something similar.

I would make a PR but I'm not sure how to proceed since the intended behaviour is not that clear with this.

Expected behaviour

Events handled and program working smoothly.

Actual behaviour

Hundreds of errors spamming the console and at least all NeovimAutoCommand events are missed.

Steps to reproduce

Open any file, navigate with j,k in visual mode, with developer tools open.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions