Skip to content

Conversation

@stevearc
Copy link
Contributor

@stevearc stevearc commented Jan 9, 2020

I believe that this will fix #927

I was seeing an issue where the gutter diagnostic signs would often stick around even after the errors had been cleared.

The issue was that our order of operations was to

  1. Fetch the current state of signs
    let signs_prev: Vec<_> = self.update(|state| {
  2. Calculate the diff between old signs and new signs
    let mut signs_to_add = vec![];
    let mut signs_to_delete = vec![];
  3. Send the signs diff to vim
    self.vim()?
    .set_signs(&filename, &signs_to_add, &signs_to_delete)?;
  4. Apply the signs diff to the state

The update is calculated from the state read in step 1, but only applied in step 4. And it's sent to vim in between. So if there are two threads that run as follows:

Thread A: 1---2---3---4
Thread B: --1---2---3---4

Thread B will calculate a diff that doesn't take into account the operations from Thread A. They will both send signs to vim, and both try to store their signs in the state. Vim stores those signs by ID, but the state stores them by line number. If two of these new signs have the same line number, only one of them will end up in the state, effectively leaking the other sign.

My fix is to move all of these steps into a single self.update block, so that it's all one atomic operation. Since we're reading and updating as a single transaction, it should be impossible to get into a bad state now.

This made the most sense to me, but I'm not sure if it's the right approach. Happy to refactor if there's a better way to fix it :)

@autozimu autozimu merged commit 93f58dd into autozimu:next Jan 14, 2020
@autozimu
Copy link
Owner

LGTM. Thanks!

@stevearc stevearc deleted the stevearc-gutter branch January 14, 2020 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vim8 gutter is not cleared correctly

2 participants