mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 23:02:35 +03:00
GH-262 Launch NeoVimServer using login shell.
This commit is contained in:
parent
2de1e90c4c
commit
137831e367
@ -70,6 +70,7 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
|||||||
_remoteServerName = remoteServerName;
|
_remoteServerName = remoteServerName;
|
||||||
|
|
||||||
_localServerThread = [[NSThread alloc] initWithTarget:self selector:@selector(runLocalServer) object:nil];
|
_localServerThread = [[NSThread alloc] initWithTarget:self selector:@selector(runLocalServer) object:nil];
|
||||||
|
_localServerThread.name = localServerName;
|
||||||
[_localServerThread start];
|
[_localServerThread start];
|
||||||
|
|
||||||
#ifndef DEBUG_NEOVIM_SERVER_STANDALONE
|
#ifndef DEBUG_NEOVIM_SERVER_STANDALONE
|
||||||
@ -159,6 +160,10 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)quit {
|
||||||
|
server_quit();
|
||||||
|
}
|
||||||
|
|
||||||
- (NSData *)handleMessageWithId:(SInt32)msgid data:(NSData *)data {
|
- (NSData *)handleMessageWithId:(SInt32)msgid data:(NSData *)data {
|
||||||
switch (msgid) {
|
switch (msgid) {
|
||||||
|
|
||||||
@ -200,7 +205,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
|||||||
}
|
}
|
||||||
|
|
||||||
case NeoVimAgentMsgIdQuit:
|
case NeoVimAgentMsgIdQuit:
|
||||||
server_quit();
|
// exit() after returning the response such that the agent can get the response and so does not log a warning.
|
||||||
|
[self performSelector:@selector(quit) onThread:_localServerThread withObject:nil waitUntilDone:NO];
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
case NeoVimAgentMsgIdGetDirtyDocs: {
|
case NeoVimAgentMsgIdGetDirtyDocs: {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#import "NeoVimAgent.h"
|
#import "NeoVimAgent.h"
|
||||||
#import "NeoVimMsgIds.h"
|
#import "NeoVimMsgIds.h"
|
||||||
#import "NeoVimUiBridgeProtocol.h"
|
#import "NeoVimUiBridgeProtocol.h"
|
||||||
#import "Logging.h"
|
#import "Logger.h"
|
||||||
#import "NeoVimBuffer.h"
|
#import "NeoVimBuffer.h"
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +72,9 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
|||||||
|
|
||||||
// We cannot use -dealloc for this since -dealloc is not called until the run loop in the thread stops.
|
// We cannot use -dealloc for this since -dealloc is not called until the run loop in the thread stops.
|
||||||
- (void)quit {
|
- (void)quit {
|
||||||
[self sendMessageWithId:NeoVimAgentMsgIdQuit data:nil expectsReply:NO];
|
// Wait till we get the response from the server.
|
||||||
|
// If we don't wait here, then the NSTask.terminate msg below could get caught by neovim which causes a warning log.
|
||||||
|
[self sendMessageWithId:NeoVimAgentMsgIdQuit data:nil expectsReply:YES];
|
||||||
|
|
||||||
if (CFMessagePortIsValid(_remoteServerPort)) {
|
if (CFMessagePortIsValid(_remoteServerPort)) {
|
||||||
CFMessagePortInvalidate(_remoteServerPort);
|
CFMessagePortInvalidate(_remoteServerPort);
|
||||||
@ -86,26 +88,47 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
|||||||
|
|
||||||
CFRunLoopStop(_localServerRunLoop);
|
CFRunLoopStop(_localServerRunLoop);
|
||||||
[_localServerThread cancel];
|
[_localServerThread cancel];
|
||||||
|
|
||||||
|
// Just to be sure...
|
||||||
|
[_neoVimServerTask interrupt];
|
||||||
|
[_neoVimServerTask terminate];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)launchNeoVimUsingLoginShell {
|
||||||
|
NSString *shellPath = [NSProcessInfo processInfo].environment[@"SHELL"];
|
||||||
|
if (shellPath == nil) {
|
||||||
|
shellPath = @"/bin/bash";
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableArray *shellArgs = [NSMutableArray new];
|
||||||
|
if (![shellPath.lastPathComponent isEqualToString:@"tcsh"]) {
|
||||||
|
[shellArgs addObject:@"-l"];
|
||||||
|
}
|
||||||
|
[shellArgs addObjectsFromArray:@[
|
||||||
|
@"-c",
|
||||||
|
[NSString stringWithFormat:@"eval \"%@ %@ %@\"",
|
||||||
|
[self neoVimServerExecutablePath],
|
||||||
|
[self localServerName],
|
||||||
|
[self remoteServerName]]
|
||||||
|
]];
|
||||||
|
|
||||||
|
_neoVimServerTask = [[NSTask alloc] init];
|
||||||
|
_neoVimServerTask.currentDirectoryPath = NSHomeDirectory();
|
||||||
|
_neoVimServerTask.launchPath = shellPath;
|
||||||
|
_neoVimServerTask.arguments = shellArgs;
|
||||||
|
[_neoVimServerTask launch];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (bool)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];
|
||||||
|
|
||||||
_neoVimServerTask = [[NSTask alloc] init];
|
[self launchNeoVimUsingLoginShell];
|
||||||
|
|
||||||
NSMutableDictionary *env = [NSMutableDictionary dictionaryWithDictionary:[NSProcessInfo processInfo].environment];
|
// Wait until neovim is ready (max. 10s).
|
||||||
env[@"PATH"] = path;
|
NSDate *deadline = [[NSDate date] dateByAddingTimeInterval:qTimeout];
|
||||||
|
|
||||||
_neoVimServerTask.environment = env;
|
|
||||||
_neoVimServerTask.currentDirectoryPath = NSHomeDirectory();
|
|
||||||
_neoVimServerTask.launchPath = [self neoVimServerExecutablePath];
|
|
||||||
_neoVimServerTask.arguments = @[ [self localServerName], [self remoteServerName] ];
|
|
||||||
[_neoVimServerTask launch];
|
|
||||||
|
|
||||||
// Wait until neovim is ready.
|
|
||||||
while (!_neoVimIsReady
|
while (!_neoVimIsReady
|
||||||
&& [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
|
&& [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:deadline]);
|
||||||
|
|
||||||
return !_isInitErrorPresent;
|
return !_isInitErrorPresent;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
1929BEB90DCDAF7A2B68C886 /* ColorUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BA6128BFDD54CA92F46E /* ColorUtils.swift */; };
|
1929BEB90DCDAF7A2B68C886 /* ColorUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BA6128BFDD54CA92F46E /* ColorUtils.swift */; };
|
||||||
1929BF81A40B4154D3EA33CE /* server_ui.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B93013228985F509C8F6 /* server_ui.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
|
1929BF81A40B4154D3EA33CE /* server_ui.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B93013228985F509C8F6 /* server_ui.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
|
||||||
4B029F1A1D45E349004EE0D3 /* PrefWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B029F1C1D45E349004EE0D3 /* PrefWindow.xib */; };
|
4B029F1A1D45E349004EE0D3 /* PrefWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B029F1C1D45E349004EE0D3 /* PrefWindow.xib */; };
|
||||||
4B0BCC941D70320C00D3CE65 /* Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0BCC931D70320C00D3CE65 /* Logging.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
4B0BCC941D70320C00D3CE65 /* Logger.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0BCC931D70320C00D3CE65 /* Logger.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||||
4B0C905B1D5DED69007753A3 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */; };
|
4B0C905B1D5DED69007753A3 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */; };
|
||||||
4B0E22581D5DEDC700C072E6 /* NeoVimBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0C90591D5DED69007753A3 /* NeoVimBuffer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
4B0E22581D5DEDC700C072E6 /* NeoVimBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B0C90591D5DED69007753A3 /* NeoVimBuffer.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
4B0E22591D5DF62E00C072E6 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */; };
|
4B0E22591D5DF62E00C072E6 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */; };
|
||||||
@ -185,7 +185,7 @@
|
|||||||
1929BE69CF9AB1A10D0DD4F2 /* CocoaCategories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoaCategories.h; sourceTree = "<group>"; };
|
1929BE69CF9AB1A10D0DD4F2 /* CocoaCategories.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoaCategories.h; sourceTree = "<group>"; };
|
||||||
1929BF00B466B40629C2AABE /* NeoVimView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NeoVimView.swift; sourceTree = "<group>"; };
|
1929BF00B466B40629C2AABE /* NeoVimView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NeoVimView.swift; sourceTree = "<group>"; };
|
||||||
4B029F1B1D45E349004EE0D3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PrefWindow.xib; sourceTree = "<group>"; };
|
4B029F1B1D45E349004EE0D3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PrefWindow.xib; sourceTree = "<group>"; };
|
||||||
4B0BCC931D70320C00D3CE65 /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Logging.h; path = VimR/Logging.h; sourceTree = SOURCE_ROOT; };
|
4B0BCC931D70320C00D3CE65 /* Logger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Logger.h; path = VimR/Logger.h; sourceTree = SOURCE_ROOT; };
|
||||||
4B0C90591D5DED69007753A3 /* NeoVimBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NeoVimBuffer.h; sourceTree = "<group>"; };
|
4B0C90591D5DED69007753A3 /* NeoVimBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NeoVimBuffer.h; sourceTree = "<group>"; };
|
||||||
4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimBuffer.m; sourceTree = "<group>"; };
|
4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimBuffer.m; sourceTree = "<group>"; };
|
||||||
4B1BB3521D16C5E500CA4FEF /* InputTestView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputTestView.swift; sourceTree = "<group>"; };
|
4B1BB3521D16C5E500CA4FEF /* InputTestView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputTestView.swift; sourceTree = "<group>"; };
|
||||||
@ -480,7 +480,7 @@
|
|||||||
4BEE79131D16D1C60012EDAA /* NeoVimView */ = {
|
4BEE79131D16D1C60012EDAA /* NeoVimView */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
4B0BCC931D70320C00D3CE65 /* Logging.h */,
|
4B0BCC931D70320C00D3CE65 /* Logger.h */,
|
||||||
1929BF00B466B40629C2AABE /* NeoVimView.swift */,
|
1929BF00B466B40629C2AABE /* NeoVimView.swift */,
|
||||||
4B401B191D046E0600D99EDC /* NeoVimViewDelegate.swift */,
|
4B401B191D046E0600D99EDC /* NeoVimViewDelegate.swift */,
|
||||||
4B570DC01D303CAF006EDC21 /* NeoVimAgent.h */,
|
4B570DC01D303CAF006EDC21 /* NeoVimAgent.h */,
|
||||||
@ -503,7 +503,7 @@
|
|||||||
4B0E22581D5DEDC700C072E6 /* NeoVimBuffer.h in Headers */,
|
4B0E22581D5DEDC700C072E6 /* NeoVimBuffer.h in Headers */,
|
||||||
4BDCFAEA1D31486E00F62670 /* NeoVimMsgIds.h in Headers */,
|
4BDCFAEA1D31486E00F62670 /* NeoVimMsgIds.h in Headers */,
|
||||||
4B2A2BFA1D0351810074CE9A /* SwiftNeoVim.h in Headers */,
|
4B2A2BFA1D0351810074CE9A /* SwiftNeoVim.h in Headers */,
|
||||||
4B0BCC941D70320C00D3CE65 /* Logging.h in Headers */,
|
4B0BCC941D70320C00D3CE65 /* Logger.h in Headers */,
|
||||||
4BDF64241D08CAB000D47E1D /* MMCoreTextView.h in Headers */,
|
4BDF64241D08CAB000D47E1D /* MMCoreTextView.h in Headers */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user