Fix crash: posting Vim message from thread

Vim is not thread-safe so posting a message to Vim from a non-GUI thread causes
a crash *sometimes*. I was aware of this problem before, but didn't catch this
instance of it in code review.

Fixes #479.
This commit is contained in:
Strahinja Val Markovic 2013-07-30 11:18:37 -07:00
parent f347885555
commit 4374da616e
2 changed files with 7 additions and 4 deletions

View File

@ -167,10 +167,9 @@ class CsharpCompleter( ThreadedCompleter ):
try: try:
response = urllib2.urlopen( target, parameters ) response = urllib2.urlopen( target, parameters )
return json.loads( response.read() ) return json.loads( response.read() )
except Exception as e: except Exception:
if not silent: # TODO: Add logging for this case. We can't post a Vim message because Vim
vimsupport.PostVimMessage( # crashes when that's done from a no-GUI thread.
'OmniSharp : Could not connect to ' + target + ': ' + str( e ) )
return None return None

View File

@ -79,6 +79,10 @@ def NumLinesInBuffer( buffer ):
def PostVimMessage( message ): def PostVimMessage( message ):
# TODO: Check are we on the main thread or not, and if not, force a crash
# here. This should make it impossible to accidentally call this from a
# non-GUI thread which *sometimes* crashes Vim because Vim is not thread-safe.
# A consistent crash should force us to notice the error.
vim.command( "echohl WarningMsg | echomsg '{0}' | echohl None" vim.command( "echohl WarningMsg | echomsg '{0}' | echohl None"
.format( EscapeForVim( message ) ) ) .format( EscapeForVim( message ) ) )