1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 01:32:04 +03:00

GH-251, GH-258 Show a warning when there was an error during the initialization of init.vim

This commit is contained in:
Tae Won Ha 2016-08-25 22:52:31 +02:00
parent fb86c67c73
commit 762c1e7267
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 23 additions and 13 deletions

View File

@ -597,11 +597,8 @@ void server_start_neovim() {
_backspace = [[NSString alloc] initWithString:@"<BS>"]; _backspace = [[NSString alloc] initWithString:@"<BS>"];
NSData *data = nil; bool value = msg_didany > 0;
if (msg_didany > 0) { NSData *data = [[NSData alloc] initWithBytes:&value length:sizeof(bool)];
bool value = true;
data = [[NSData alloc] initWithBytes:&value length:sizeof(bool)];
}
[_neovim_server sendMessageWithId:NeoVimServerMsgIdNeoVimReady data:data]; [_neovim_server sendMessageWithId:NeoVimServerMsgIdNeoVimReady data:data];
[data release]; [data release];
} }

View File

@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithUuid:(NSString *)uuid; - (instancetype)initWithUuid:(NSString *)uuid;
- (void)quit; - (void)quit;
- (void)runLocalServerAndNeoVimWithPath:(NSString *)path; - (bool)runLocalServerAndNeoVimWithPath:(NSString *)path;
- (void)vimCommand:(NSString *)string; - (void)vimCommand:(NSString *)string;

View File

@ -52,7 +52,9 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
CFRunLoopRef _localServerRunLoop; CFRunLoopRef _localServerRunLoop;
NSTask *_neoVimServerTask; NSTask *_neoVimServerTask;
bool _neoVimIsReady; bool _neoVimIsReady;
bool _isInitErrorPresent;
} }
- (instancetype)initWithUuid:(NSString *)uuid { - (instancetype)initWithUuid:(NSString *)uuid {
@ -63,6 +65,7 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
_uuid = uuid; _uuid = uuid;
_neoVimIsReady = NO; _neoVimIsReady = NO;
_isInitErrorPresent = NO;
return self; return self;
} }
@ -85,7 +88,7 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
[_localServerThread cancel]; [_localServerThread cancel];
} }
- (void)runLocalServerAndNeoVimWithPath:(NSString *)path { - (bool)runLocalServerAndNeoVimWithPath:(NSString *)path {
_localServerThread = [[NSThread alloc] initWithTarget:self selector:@selector(runLocalServer) object:nil]; _localServerThread = [[NSThread alloc] initWithTarget:self selector:@selector(runLocalServer) object:nil];
[_localServerThread start]; [_localServerThread start];
@ -103,6 +106,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
// Wait until neovim is ready. // Wait until neovim is ready.
while (!_neoVimIsReady while (!_neoVimIsReady
&& [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]); && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
return !_isInitErrorPresent;
} }
- (void)vimCommand:(NSString *)string { - (void)vimCommand:(NSString *)string {
@ -250,11 +255,10 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
return; return;
case NeoVimServerMsgIdNeoVimReady: { case NeoVimServerMsgIdNeoVimReady: {
_neoVimIsReady = YES; bool *value = data_to_bool_array(data, 1);
_isInitErrorPresent = value[0];
if (data.length > 0) { _neoVimIsReady = YES;
log4Warn("There was an error during the initialization of NeoVim. Use :messages to view the error messages.");
}
return; return;
} }

View File

@ -112,10 +112,19 @@ public class NeoVimView: NSView, NSUserInterfaceValidations {
// We cannot set bridge in init since self is not available before super.init()... // We cannot set bridge in init since self is not available before super.init()...
self.agent.bridge = self self.agent.bridge = self
self.agent.runLocalServerAndNeoVimWithPath(ShellUtils.pathForUserShell()) let noErrorDuringInitialization = self.agent.runLocalServerAndNeoVimWithPath(ShellUtils.pathForUserShell())
// Neovim is ready now: resize neovim to bounds. // Neovim is ready now: resize neovim to bounds.
DispatchUtils.gui { DispatchUtils.gui {
if noErrorDuringInitialization == false {
let alert = NSAlert()
alert.alertStyle = .WarningAlertStyle
alert.messageText = "Error during initialization"
alert.informativeText = "There was an error during the initialization of NeoVim. "
+ "Use :messages to view the error messages."
alert.runModal()
}
self.resizeNeoVimUiTo(size: self.bounds.size) self.resizeNeoVimUiTo(size: self.bounds.size)
} }
} }