From f410996996189fb384ebf9641a1477b5115d9e6e Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 21 Dec 2016 12:21:36 -0500 Subject: [PATCH] Add a lock util Realized that messages could be sent over the same stream while we're waiting for a response for the previous message. This is not good. Made a lock util to help with that. I see this happening a lot once we start trying to do completion type items, so that's where I came up with this part. --- autoload/langserver/lock.vim | 16 ++++++++++++++++ tests/test_lock.vader | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 autoload/langserver/lock.vim create mode 100644 tests/test_lock.vader diff --git a/autoload/langserver/lock.vim b/autoload/langserver/lock.vim new file mode 100644 index 0000000..83c6cdb --- /dev/null +++ b/autoload/langserver/lock.vim @@ -0,0 +1,16 @@ + +function! s:dict_lock() dict + let self.locked = v:true +endfunction + +function! s:dict_unlock() dict + let self.locked = v:false +endfunction + +function! langserver#lock#semaphore() abort + let l:ret = {} + let l:ret.locked = v:false + let l:ret.lock = function('s:dict_lock') + let l:ret.unlock = function('s:dict_unlock') + return l:ret +endfunction diff --git a/tests/test_lock.vader b/tests/test_lock.vader new file mode 100644 index 0000000..b6cdad1 --- /dev/null +++ b/tests/test_lock.vader @@ -0,0 +1,10 @@ +Execute (Test Lock): + let my_lock = langserver#lock#semaphore() + + AssertEqual v:false, my_lock.locked + + call my_lock.lock() + AssertEqual v:true, my_lock.locked + + call my_lock.unlock() + AssertEqual v:false, my_lock.locked