diff --git a/MsgPackRpc/MsgPackRpc.xcodeproj/project.pbxproj b/MsgPackRpc/MsgPackRpc.xcodeproj/project.pbxproj
index dcf75e6c..74901004 100644
--- a/MsgPackRpc/MsgPackRpc.xcodeproj/project.pbxproj
+++ b/MsgPackRpc/MsgPackRpc.xcodeproj/project.pbxproj
@@ -236,7 +236,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- MACOSX_DEPLOYMENT_TARGET = 10.12;
+ MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
@@ -290,7 +290,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- MACOSX_DEPLOYMENT_TARGET = 10.12;
+ MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
diff --git a/MsgPackRpc/MsgPackRpc/MsgPackRpc.swift b/MsgPackRpc/MsgPackRpc/MsgPackRpc.swift
index dfbe572e..a9c06723 100644
--- a/MsgPackRpc/MsgPackRpc/MsgPackRpc.swift
+++ b/MsgPackRpc/MsgPackRpc/MsgPackRpc.swift
@@ -32,7 +32,6 @@ public class Connection {
self.session = session
session.dataCallback = { data in (try? unpackAll(data))?.forEach(self.processResponse) }
- session.run()
}
public convenience init?(unixDomainSocketPath path: String) {
@@ -43,6 +42,10 @@ public class Connection {
self.init(with: session)
}
+ public func run() {
+ self.session.run()
+ }
+
@discardableResult
public func request(type: Int = 0,
msgid: UInt32,
diff --git a/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.h b/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.h
index 4e168ed1..d67721c5 100644
--- a/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.h
+++ b/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.h
@@ -12,6 +12,8 @@
@property CFTimeInterval timeout;
@property (nonatomic, copy, nullable) void (^dataCallback)(NSData * __nonnull);
+@property (readonly, getter=isRunning) bool running;
+
- (void)run;
- (CFSocketError)writeData:(NSData * __nonnull)data;
diff --git a/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.m b/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.m
index c5d389fd..fd0fc8be 100644
--- a/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.m
+++ b/MsgPackRpc/MsgPackRpc/UnixDomainSocketConnection.m
@@ -45,12 +45,18 @@ static void socket_call_back(
int _native_socket;
struct sockaddr_un _sockaddr;
+ NSString *_path;
+
CFRunLoopRef _run_loop;
CFRunLoopSourceRef _run_loop_source;
NSThread *_thread;
}
+- (bool)isRunning {
+ return [_thread isExecuting];
+}
+
- (instancetype)initWithPath:(NSString *)path {
self = [super init];
if (self == nil) {
@@ -58,40 +64,7 @@ static void socket_call_back(
}
_timeout = 5;
-
- if ((_native_socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
- NSLog(@"Error: Unix domain socket NULL!");
- return nil;
- }
-
- _sockaddr.sun_family = AF_UNIX;
- strcpy(_sockaddr.sun_path, [path cStringUsingEncoding:NSUTF8StringEncoding]);
- if (connect(_native_socket, (struct sockaddr *) &_sockaddr, (socklen_t) SUN_LEN(&_sockaddr)) == -1) {
- NSLog(@"Error: Could not connect to the socket!");
- close(_native_socket);
- return nil;
- }
-
- CFSocketContext context;
- context.copyDescription = NULL;
- context.release = NULL;
- context.retain = NULL;
- context.version = 0;
- context.info = (__bridge void *) self;
-
- _socket = CFSocketCreateWithNative(
- NULL,
- _native_socket,
- kCFSocketConnectCallBack | kCFSocketDataCallBack,
- socket_call_back,
- &context
- );
-
- if (_socket == nil) {
- NSLog(@"Error: CFSocket is NULL!");
- close(_native_socket);
- return nil;
- }
+ _path = path;
return self;
}
@@ -113,15 +86,51 @@ static void socket_call_back(
}
- (void)run {
+ if ((_native_socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+ NSLog(@"Error: Unix domain socket NULL!");
+ [NSException raise:@"UnixDomainSocketConnectionException" format:@"Unix domain socket NULL!"];
+ }
+
+ _sockaddr.sun_family = AF_UNIX;
+ strcpy(_sockaddr.sun_path, [_path cStringUsingEncoding:NSUTF8StringEncoding]);
+ if (connect(_native_socket, (struct sockaddr *) &_sockaddr, (socklen_t) SUN_LEN(&_sockaddr)) == -1) {
+ NSLog(@"Error: Could not connect to the socket!");
+ close(_native_socket);
+ [NSException raise:@"UnixDomainSocketConnectionException" format:@"Could not connect to socket!"];
+ }
+
+ CFSocketContext context;
+ context.copyDescription = NULL;
+ context.release = NULL;
+ context.retain = NULL;
+ context.version = 0;
+ context.info = (__bridge void *) self;
+
+ _socket = CFSocketCreateWithNative(
+ NULL,
+ _native_socket,
+ kCFSocketConnectCallBack | kCFSocketDataCallBack,
+ socket_call_back,
+ &context
+ );
+
+ if (_socket == nil) {
+ NSLog(@"Error: CFSocket is NULL!");
+ close(_native_socket);
+ [NSException raise:@"UnixDomainSocketConnectionException" format:@"CFSocket is NULL!"];
+ }
+
_run_loop_source = CFSocketCreateRunLoopSource(NULL, _socket, 0);
- _thread = [[NSThread alloc] initWithBlock:^{
- _run_loop = CFRunLoopGetCurrent();
- CFRunLoopAddSource(_run_loop, _run_loop_source, kCFRunLoopDefaultMode);
- CFRunLoopRun();
- }];
+ _thread = [[NSThread alloc] initWithTarget:self selector:@selector(threadMain) object:nil];
[_thread start];
}
+- (void)threadMain {
+ _run_loop = CFRunLoopGetCurrent();
+ CFRunLoopAddSource(_run_loop, _run_loop_source, kCFRunLoopDefaultMode);
+ CFRunLoopRun();
+}
+
- (CFSocketError)writeData:(NSData *)data {
return CFSocketSendData(_socket, NULL, (__bridge CFDataRef) data, _timeout);
}
diff --git a/NvimMsgPack.playground/Contents.swift b/NvimMsgPack.playground/Contents.swift
index 6b82c181..33acf8ea 100644
--- a/NvimMsgPack.playground/Contents.swift
+++ b/NvimMsgPack.playground/Contents.swift
@@ -12,3 +12,5 @@ guard let nvim = Nvim(at: "/tmp/nvim.sock") else {
print(nvim.listRuntimePaths())
let bufs = nvim.listBufs().value
print(String(describing: bufs?.map({ nvim.bufGetName(buffer: $0) })))
+let buf = bufs![0]
+nvim.bufGetChangedtick(buffer: buf)
diff --git a/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj b/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj
index 4eeeac11..fc689d7e 100644
--- a/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj
+++ b/NvimMsgPack/NvimMsgPack.xcodeproj/project.pbxproj
@@ -232,7 +232,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- MACOSX_DEPLOYMENT_TARGET = 10.12;
+ MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
@@ -286,7 +286,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- MACOSX_DEPLOYMENT_TARGET = 10.12;
+ MACOSX_DEPLOYMENT_TARGET = 10.10;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
diff --git a/NvimMsgPack/NvimMsgPack.xcodeproj/xcshareddata/xcschemes/NvimMsgPack.xcscheme b/NvimMsgPack/NvimMsgPack.xcodeproj/xcshareddata/xcschemes/NvimMsgPack.xcscheme
index 9e408548..09e660c9 100644
--- a/NvimMsgPack/NvimMsgPack.xcodeproj/xcshareddata/xcschemes/NvimMsgPack.xcscheme
+++ b/NvimMsgPack/NvimMsgPack.xcodeproj/xcshareddata/xcschemes/NvimMsgPack.xcscheme
@@ -6,6 +6,20 @@
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
+
+
+
+
+
+
+
+
diff --git a/NvimMsgPack/NvimMsgPack/Nvim.swift b/NvimMsgPack/NvimMsgPack/Nvim.swift
index 07b1c863..9a3d318d 100644
--- a/NvimMsgPack/NvimMsgPack/Nvim.swift
+++ b/NvimMsgPack/NvimMsgPack/Nvim.swift
@@ -134,6 +134,10 @@ public class Nvim {
self.connection = connection
}
+ public func run() {
+ self.connection.run()
+ }
+
public func rpc(method: String,
params: [MsgPackRpc.Value],
expectsReturnValue: Bool) -> Result {
@@ -181,6 +185,10 @@ public class Nvim {
self.session = session
}
+ public func connect() {
+ self.session.run()
+ }
+
public func rpc(method: String,
params: [Nvim.Value],
expectsReturnValue: Bool = true) -> Nvim.Response {
diff --git a/NvimMsgPack/NvimMsgPack/NvimMethods.swift b/NvimMsgPack/NvimMsgPack/NvimMethods.swift
index 35a8f0e3..0bb70d3f 100644
--- a/NvimMsgPack/NvimMsgPack/NvimMethods.swift
+++ b/NvimMsgPack/NvimMsgPack/NvimMethods.swift
@@ -3,7 +3,7 @@
import MsgPackRpc
-extension Nvim.Error {
+public extension Nvim.Error {
public enum ErrorType: Int {
@@ -13,7 +13,7 @@ extension Nvim.Error {
}
}
-extension Nvim {
+public extension Nvim {
public func bufLineCount(
buffer: Nvim.Buffer,
diff --git a/SwiftNeoVim/NeoVimAgent.m b/SwiftNeoVim/NeoVimAgent.m
index 5ead0d1b..efc950ed 100644
--- a/SwiftNeoVim/NeoVimAgent.m
+++ b/SwiftNeoVim/NeoVimAgent.m
@@ -210,7 +210,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local __unused, SInt32 m
_neoVimServerTask.arguments = shellArgs;
[_neoVimServerTask launch];
- NSString *cmd = [NSString stringWithFormat:@"exec \"%@\" '%@' '%@'",
+ NSString *cmd = [NSString stringWithFormat:@"NVIM_LISTEN_ADDRESS=%@ exec \"%@\" '%@' '%@'",
+ [NSString stringWithFormat:@"/tmp/vimr_%@.sock", _uuid],
[self neoVimServerExecutablePath],
[self localServerName],
[self remoteServerName]];
diff --git a/SwiftNeoVim/NeoVimView+Resize.swift b/SwiftNeoVim/NeoVimView+Resize.swift
index c67c32ca..582fe43f 100644
--- a/SwiftNeoVim/NeoVimView+Resize.swift
+++ b/SwiftNeoVim/NeoVimView+Resize.swift
@@ -57,6 +57,8 @@ extension NeoVimView {
self.logger.info("=== Starting neovim...")
let noErrorDuringInitialization = self.agent.runLocalServerAndNeoVim(withWidth: size.width, height: size.height)
+ self.nvim.connect()
+
self.agent.vimCommand("set mouse=a")
self.agent.vimCommand("set title")
self.agent.vimCommand("set termguicolors")
diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift
index 56ef96df..247846f4 100644
--- a/SwiftNeoVim/NeoVimView.swift
+++ b/SwiftNeoVim/NeoVimView.swift
@@ -4,6 +4,7 @@
*/
import Cocoa
+import NvimMsgPack
public class NeoVimView: NSView,
NeoVimUiBridgeProtocol,
@@ -151,6 +152,11 @@ public class NeoVimView: NSView,
public init(frame rect: NSRect, config: Config) {
self.drawer = TextDrawer(font: self._font)
self.agent = NeoVimAgent(uuid: self.uuid)
+ guard let nvim = Nvim(at: "/tmp/vimr_\(self.uuid).sock") else {
+ preconditionFailure("Nvim could not be instantiated")
+ }
+
+ self.nvim = nvim
super.init(frame: .zero)
self.registerForDraggedTypes([NSPasteboard.PasteboardType(String(kUTTypeFileURL))])
@@ -199,6 +205,7 @@ public class NeoVimView: NSView,
with: URL(fileURLWithPath: "/tmp/nvv-bridge.log"),
shouldLogDebug: nil)
let agent: NeoVimAgent
+ let nvim: Nvim
let grid = Grid()
let drawer: TextDrawer
@@ -235,7 +242,7 @@ public class NeoVimView: NSView,
var _cwd = URL(fileURLWithPath: NSHomeDirectory())
var shouldDrawCursor = false
var isInitialResize = true
-
+
// cache the tabs for Touch Bar use
var tabsCache = [NeoVimTab]()
diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj
index 23b4a7fc..8d464631 100644
--- a/VimR.xcodeproj/project.pbxproj
+++ b/VimR.xcodeproj/project.pbxproj
@@ -165,6 +165,10 @@
4B854A1D1D31447C00E08DE1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B854A1C1D31447C00E08DE1 /* main.m */; };
4B8AC0441DBCB3A2007CCC9B /* NeoVimObjectsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8AC0431DBCB3A1007CCC9B /* NeoVimObjectsExtensions.swift */; };
4B8C7C761F05A04400F25BE8 /* CocoaMarkdown.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B183E0D1E06E2940079E8A8 /* CocoaMarkdown.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
+ 4B90EFC91FCD6CE2008A39E0 /* MsgPackRpc.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B90EFCA1FCD6CE2008A39E0 /* MsgPackRpc.framework */; };
+ 4B90EFCB1FCD6CE5008A39E0 /* NvimMsgPack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B90EFCC1FCD6CE5008A39E0 /* NvimMsgPack.framework */; };
+ 4B90EFCD1FCD6CEB008A39E0 /* MsgPackRpc.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B90EFCA1FCD6CE2008A39E0 /* MsgPackRpc.framework */; };
+ 4B90EFCE1FCD6CEE008A39E0 /* NvimMsgPack.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B90EFCC1FCD6CE5008A39E0 /* NvimMsgPack.framework */; };
4B91FFF41DEB772200447068 /* CocoaFontAwesome.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4B337FBA1DEB76F20020ADD2 /* CocoaFontAwesome.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4B91FFF61DEB772B00447068 /* CocoaFontAwesome.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4B337FBA1DEB76F20020ADD2 /* CocoaFontAwesome.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4B96384C1ED9793B001C556F /* NeoVimAutoCommandEvent.generated.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B96384B1ED9793B001C556F /* NeoVimAutoCommandEvent.generated.m */; };
@@ -512,6 +516,8 @@
4B854A1A1D31447C00E08DE1 /* NeoVimServer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = NeoVimServer; sourceTree = BUILT_PRODUCTS_DIR; };
4B854A1C1D31447C00E08DE1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
4B8AC0431DBCB3A1007CCC9B /* NeoVimObjectsExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NeoVimObjectsExtensions.swift; sourceTree = ""; };
+ 4B90EFCA1FCD6CE2008A39E0 /* MsgPackRpc.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = MsgPackRpc.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ 4B90EFCC1FCD6CE5008A39E0 /* NvimMsgPack.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = NvimMsgPack.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4B96384B1ED9793B001C556F /* NeoVimAutoCommandEvent.generated.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimAutoCommandEvent.generated.m; sourceTree = ""; };
4B96384D1ED9797F001C556F /* NeoVimUiBridgeProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimUiBridgeProtocol.m; sourceTree = ""; };
4B96384F1ED979BD001C556F /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; };
@@ -566,6 +572,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 4B90EFCE1FCD6CEE008A39E0 /* NvimMsgPack.framework in Frameworks */,
+ 4B90EFCD1FCD6CEB008A39E0 /* MsgPackRpc.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -608,6 +616,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 4B90EFCB1FCD6CE5008A39E0 /* NvimMsgPack.framework in Frameworks */,
+ 4B90EFC91FCD6CE2008A39E0 /* MsgPackRpc.framework in Frameworks */,
4B2A2BFE1D0351810074CE9A /* SwiftNeoVim.framework in Frameworks */,
4BDD056A1DB0CAB700D1B405 /* Sparkle.framework in Frameworks */,
4B337FBB1DEB76F20020ADD2 /* CocoaFontAwesome.framework in Frameworks */,
@@ -834,6 +844,8 @@
4B5012001EBA791000F76C46 /* Frameworks */ = {
isa = PBXGroup;
children = (
+ 4B90EFCC1FCD6CE5008A39E0 /* NvimMsgPack.framework */,
+ 4B90EFCA1FCD6CE2008A39E0 /* MsgPackRpc.framework */,
4BB7F3911F9D260B00624F61 /* Swifter.framework */,
4B5011F71EBA67EB00F76C46 /* RxTest.framework */,
4B183E0D1E06E2940079E8A8 /* CocoaMarkdown.framework */,
diff --git a/VimR.xcodeproj/xcshareddata/xcschemes/SwiftNeoVim.xcscheme b/VimR.xcodeproj/xcshareddata/xcschemes/SwiftNeoVim.xcscheme
index 7b410c10..fe19b5bd 100644
--- a/VimR.xcodeproj/xcshareddata/xcschemes/SwiftNeoVim.xcscheme
+++ b/VimR.xcodeproj/xcshareddata/xcschemes/SwiftNeoVim.xcscheme
@@ -6,6 +6,34 @@
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+