From 43e96079bd0ca0c24a5ff6ddad665e9973acf143 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 22 Oct 2016 17:25:43 +0200 Subject: [PATCH 1/6] Reformat and use @import --- NeoVimServer/CocoaCategories.h | 2 +- NeoVimServer/NeoVimBuffer.h | 2 +- NeoVimServer/NeoVimMsgIds.h | 2 +- NeoVimServer/NeoVimServer.h | 3 ++- NeoVimServer/main.m | 12 +++++++----- NeoVimServer/server_globals.h | 2 +- NeoVimServer/server_ui.m | 3 ++- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/NeoVimServer/CocoaCategories.h b/NeoVimServer/CocoaCategories.h index 85fcd1fd..e55226d8 100644 --- a/NeoVimServer/CocoaCategories.h +++ b/NeoVimServer/CocoaCategories.h @@ -3,7 +3,7 @@ * See LICENSE */ -#import +@import Foundation; @interface NSObject (NeoVimServer) diff --git a/NeoVimServer/NeoVimBuffer.h b/NeoVimServer/NeoVimBuffer.h index 35e79821..e1ed5ad5 100644 --- a/NeoVimServer/NeoVimBuffer.h +++ b/NeoVimServer/NeoVimBuffer.h @@ -3,7 +3,7 @@ * See LICENSE */ -#import +@import Foundation; NS_ASSUME_NONNULL_BEGIN diff --git a/NeoVimServer/NeoVimMsgIds.h b/NeoVimServer/NeoVimMsgIds.h index 05c2fc6f..4357c4a3 100644 --- a/NeoVimServer/NeoVimMsgIds.h +++ b/NeoVimServer/NeoVimMsgIds.h @@ -3,7 +3,7 @@ * See LICENSE */ -#import +@import Foundation; typedef NS_ENUM(NSUInteger, NeoVimServerMsgId) { diff --git a/NeoVimServer/NeoVimServer.h b/NeoVimServer/NeoVimServer.h index 41c492c0..b34b29f7 100644 --- a/NeoVimServer/NeoVimServer.h +++ b/NeoVimServer/NeoVimServer.h @@ -3,7 +3,8 @@ * See LICENSE */ -#import +@import Foundation; + #import "NeoVimMsgIds.h" diff --git a/NeoVimServer/main.m b/NeoVimServer/main.m index 5bfe7a12..9a8c319a 100644 --- a/NeoVimServer/main.m +++ b/NeoVimServer/main.m @@ -3,18 +3,20 @@ * See LICENSE */ -#import +@import Foundation; + +#import +#import + #import "NeoVimServer.h" #import "server_globals.h" #import "Logging.h" #import "CocoaCategories.h" -#import -#import NeoVimServer *_neovim_server; -// Ensure no parent-less NeoVimServer processes are left when the main app crashes. +// Ensure that no parent-less NeoVimServer processes are left when the main app crashes. // From http://mac-os-x.10953.n7.nabble.com/Ensure-NSTask-terminates-when-parent-application-does-td31477.html static void observe_parent_termination(void *arg) { pid_t ppid = getppid(); // get parent pid @@ -35,7 +37,7 @@ static void observe_parent_termination(void *arg) { kevent(kq, &procEvent, 1, &procEvent, 1, 0); } - DLOG("Exiting NeoVimServer: Parent terminated."); + ILOG("Exiting NeoVimServer: Parent terminated."); exit(0); } diff --git a/NeoVimServer/server_globals.h b/NeoVimServer/server_globals.h index 8adf5617..5286c8cb 100644 --- a/NeoVimServer/server_globals.h +++ b/NeoVimServer/server_globals.h @@ -3,7 +3,7 @@ * See LICENSE */ -#import +@import Foundation; @class NeoVimServer; diff --git a/NeoVimServer/server_ui.m b/NeoVimServer/server_ui.m index d606c412..d1f8bd65 100644 --- a/NeoVimServer/server_ui.m +++ b/NeoVimServer/server_ui.m @@ -3,7 +3,8 @@ * See LICENSE */ -#import +@import Foundation; + #import "Logging.h" #import "server_globals.h" #import "NeoVimServer.h" From 21cf7c3fd5e93d779c42329c073039abcde8a594 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 22 Oct 2016 17:35:36 +0200 Subject: [PATCH 2/6] Rename properties --- NeoVimServer/NeoVimBuffer.h | 6 +++--- NeoVimServer/NeoVimBuffer.m | 18 +++++++++--------- SwiftNeoVim/NeoVimView.swift | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/NeoVimServer/NeoVimBuffer.h b/NeoVimServer/NeoVimBuffer.h index e1ed5ad5..8e41cbfb 100644 --- a/NeoVimServer/NeoVimBuffer.h +++ b/NeoVimServer/NeoVimBuffer.h @@ -11,9 +11,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSUInteger handle; @property (nonatomic, retain, nullable) NSString *fileName; -@property (nonatomic, readonly, getter=isDirty) bool dirty; -@property (nonatomic, readonly, getter=isCurrent) bool current; -@property (nonatomic, readonly, getter=isTransient) bool transient; +@property (nonatomic, readonly) bool isDirty; +@property (nonatomic, readonly) bool isCurrent; +@property (nonatomic, readonly) bool isTransient; - (instancetype)initWithHandle:(NSUInteger)handle fileName:(NSString * _Nullable)fileName diff --git a/NeoVimServer/NeoVimBuffer.m b/NeoVimServer/NeoVimBuffer.m index 0fbfb49f..ff5b45a0 100644 --- a/NeoVimServer/NeoVimBuffer.m +++ b/NeoVimServer/NeoVimBuffer.m @@ -18,8 +18,8 @@ _handle = handle; _fileName = fileName; - _dirty = dirty; - _current = current; + _isDirty = dirty; + _isCurrent = current; return self; } @@ -30,8 +30,8 @@ NSNumber *objHandle = [coder decodeObjectForKey:@"handle"]; _handle = objHandle.unsignedIntegerValue; _fileName = [coder decodeObjectForKey:@"fileName"]; - _dirty = [coder decodeBoolForKey:@"dirty"]; - _current = [coder decodeBoolForKey:@"current"]; + _isDirty = [coder decodeBoolForKey:@"dirty"]; + _isCurrent = [coder decodeBoolForKey:@"current"]; } return self; @@ -40,22 +40,22 @@ - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:@(self.handle) forKey:@"handle"]; [coder encodeObject:self.fileName forKey:@"fileName"]; - [coder encodeBool:self.dirty forKey:@"dirty"]; - [coder encodeBool:self.current forKey:@"current"]; + [coder encodeBool:self.isDirty forKey:@"dirty"]; + [coder encodeBool:self.isCurrent forKey:@"current"]; } - (NSString *)description { NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])]; [description appendFormat:@"self.handle=%lu", self.handle]; [description appendFormat:@", self.fileName=%@", self.fileName]; - [description appendFormat:@", self.dirty=%d", self.dirty]; - [description appendFormat:@", self.current=%d", self.current]; + [description appendFormat:@", self.dirty=%d", self.isDirty]; + [description appendFormat:@", self.current=%d", self.isCurrent]; [description appendString:@">"]; return description; } - (bool)isTransient { - if (self.dirty) { + if (self.isDirty) { return NO; } diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index 486ee140..2d11c4cd 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -204,7 +204,7 @@ extension NeoVimView { - returns: nil when for exampls a quickfix panel is open. */ public func currentBuffer() -> NeoVimBuffer? { - return self.agent.buffers().filter { $0.current }.first + return self.agent.buffers().filter { $0.isCurrent }.first } public func hasDirtyDocs() -> Bool { @@ -213,7 +213,7 @@ extension NeoVimView { public func isCurrentBufferDirty() -> Bool { let curBuf = self.currentBuffer() - return curBuf?.dirty ?? true + return curBuf?.isDirty ?? true } public func newTab() { @@ -221,7 +221,7 @@ extension NeoVimView { } public func open(urls: [URL]) { - let currentBufferIsTransient = self.agent.buffers().filter { $0.current }.first?.transient ?? false + let currentBufferIsTransient = self.agent.buffers().filter { $0.isCurrent }.first?.isTransient ?? false urls.enumerated().forEach { (idx, url) in if idx == 0 && currentBufferIsTransient { From 3171a0f229e839c8acc7fb4b76d73c931e5d8bb6 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 22 Oct 2016 17:37:53 +0200 Subject: [PATCH 3/6] Remove unused enum --- NeoVimServer/NeoVimMsgIds.h | 1 - 1 file changed, 1 deletion(-) diff --git a/NeoVimServer/NeoVimMsgIds.h b/NeoVimServer/NeoVimMsgIds.h index 4357c4a3..b3b4a719 100644 --- a/NeoVimServer/NeoVimMsgIds.h +++ b/NeoVimServer/NeoVimMsgIds.h @@ -31,7 +31,6 @@ typedef NS_ENUM(NSUInteger, NeoVimServerMsgId) { NeoVimServerMsgIdSetForeground, NeoVimServerMsgIdSetBackground, NeoVimServerMsgIdSetSpecial, - NeoVimServerMsgIdSuspend, NeoVimServerMsgIdSetTitle, NeoVimServerMsgIdSetIcon, NeoVimServerMsgIdDirtyStatusChanged, From 1750af1ce588ce47c01f8867ff776c157524cdba Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 22 Oct 2016 22:20:22 +0200 Subject: [PATCH 4/6] GH-309 Add some more neovim objects --- NeoVimServer/NeoVimBuffer.h | 4 +-- NeoVimServer/NeoVimBuffer.m | 6 ++-- NeoVimServer/NeoVimMsgIds.h | 1 + NeoVimServer/NeoVimServer.m | 4 +++ NeoVimServer/NeoVimTab.h | 25 ++++++++++++++ NeoVimServer/NeoVimTab.m | 48 ++++++++++++++++++++++++++ NeoVimServer/NeoVimWindow.h | 28 ++++++++++++++++ NeoVimServer/NeoVimWindow.m | 48 ++++++++++++++++++++++++++ NeoVimServer/server_globals.h | 1 + NeoVimServer/server_ui.m | 61 ++++++++++++++++++++++++++++------ SwiftNeoVim/NeoVimAgent.h | 2 ++ SwiftNeoVim/NeoVimAgent.m | 11 ++++++ SwiftNeoVim/NeoVimView.swift | 2 +- SwiftNeoVim/SwiftNeoVim.h | 4 ++- VimR.xcodeproj/project.pbxproj | 48 ++++++++++++++++++++------ 15 files changed, 265 insertions(+), 28 deletions(-) create mode 100644 NeoVimServer/NeoVimTab.h create mode 100644 NeoVimServer/NeoVimTab.m create mode 100644 NeoVimServer/NeoVimWindow.h create mode 100644 NeoVimServer/NeoVimWindow.m diff --git a/NeoVimServer/NeoVimBuffer.h b/NeoVimServer/NeoVimBuffer.h index 8e41cbfb..88673f71 100644 --- a/NeoVimServer/NeoVimBuffer.h +++ b/NeoVimServer/NeoVimBuffer.h @@ -9,13 +9,13 @@ NS_ASSUME_NONNULL_BEGIN @interface NeoVimBuffer : NSObject -@property (nonatomic, readonly) NSUInteger handle; +@property (nonatomic, readonly) NSInteger handle; @property (nonatomic, retain, nullable) NSString *fileName; @property (nonatomic, readonly) bool isDirty; @property (nonatomic, readonly) bool isCurrent; @property (nonatomic, readonly) bool isTransient; -- (instancetype)initWithHandle:(NSUInteger)handle +- (instancetype)initWithHandle:(NSInteger)handle fileName:(NSString * _Nullable)fileName dirty:(bool)dirty current:(bool)current; diff --git a/NeoVimServer/NeoVimBuffer.m b/NeoVimServer/NeoVimBuffer.m index ff5b45a0..f8f92ec8 100644 --- a/NeoVimServer/NeoVimBuffer.m +++ b/NeoVimServer/NeoVimBuffer.m @@ -7,7 +7,7 @@ @implementation NeoVimBuffer -- (instancetype)initWithHandle:(NSUInteger)handle +- (instancetype)initWithHandle:(NSInteger)handle fileName:(NSString *)fileName dirty:(bool)dirty current:(bool)current { @@ -28,7 +28,7 @@ self = [super init]; if (self) { NSNumber *objHandle = [coder decodeObjectForKey:@"handle"]; - _handle = objHandle.unsignedIntegerValue; + _handle = objHandle.integerValue; _fileName = [coder decodeObjectForKey:@"fileName"]; _isDirty = [coder decodeBoolForKey:@"dirty"]; _isCurrent = [coder decodeBoolForKey:@"current"]; @@ -46,7 +46,7 @@ - (NSString *)description { NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])]; - [description appendFormat:@"self.handle=%lu", self.handle]; + [description appendFormat:@"self.handle=%li", self.handle]; [description appendFormat:@", self.fileName=%@", self.fileName]; [description appendFormat:@", self.dirty=%d", self.isDirty]; [description appendFormat:@", self.current=%d", self.isCurrent]; diff --git a/NeoVimServer/NeoVimMsgIds.h b/NeoVimServer/NeoVimMsgIds.h index b3b4a719..ef61806e 100644 --- a/NeoVimServer/NeoVimMsgIds.h +++ b/NeoVimServer/NeoVimMsgIds.h @@ -56,6 +56,7 @@ typedef NS_ENUM(NSUInteger, NeoVimAgentMsgId) { NeoVimAgentMsgIdGetDirtyDocs, NeoVimAgentMsgIdGetEscapeFileNames, NeoVimAgentMsgIdGetBuffers, + NeoVimAgentMsgIdGetTabs, #ifdef DEBUG NeoVimAgentDebug1, diff --git a/NeoVimServer/NeoVimServer.m b/NeoVimServer/NeoVimServer.m index 8b856ca8..36aec44c 100644 --- a/NeoVimServer/NeoVimServer.m +++ b/NeoVimServer/NeoVimServer.m @@ -241,6 +241,10 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD return [NSKeyedArchiver archivedDataWithRootObject:server_buffers()]; } + case NeoVimAgentMsgIdGetTabs: { + return [NSKeyedArchiver archivedDataWithRootObject:server_tabs()]; + } + default: return nil; } diff --git a/NeoVimServer/NeoVimTab.h b/NeoVimServer/NeoVimTab.h new file mode 100644 index 00000000..9b4f4563 --- /dev/null +++ b/NeoVimServer/NeoVimTab.h @@ -0,0 +1,25 @@ +/** + * Tae Won Ha - http://taewon.de - @hataewon + * See LICENSE + */ + +@import Foundation; + + +@class NeoVimWindow; + + +NS_ASSUME_NONNULL_BEGIN + +@interface NeoVimTab : NSObject + +@property (nonatomic, readonly) NSInteger handle; +@property (nonatomic, readonly) NSArray *windows; + +- (instancetype)initWithHandle:(NSInteger)handle windows:(NSArray *)windows; + +- (NSString *)description; + +@end + +NS_ASSUME_NONNULL_END diff --git a/NeoVimServer/NeoVimTab.m b/NeoVimServer/NeoVimTab.m new file mode 100644 index 00000000..6c0adbfc --- /dev/null +++ b/NeoVimServer/NeoVimTab.m @@ -0,0 +1,48 @@ +/** + * Tae Won Ha - http://taewon.de - @hataewon + * See LICENSE + */ + +#import "NeoVimTab.h" +#import "NeoVimWindow.h" + + +@implementation NeoVimTab + +- (instancetype)initWithHandle:(NSInteger)handle windows:(NSArray *)windows { + self = [super init]; + if (self == nil) { + return nil; + } + + _handle = handle; + _windows = windows; + + return self; +} + +- (NSString *)description { + NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])]; + [description appendFormat:@"self.handle=%li", self.handle]; + [description appendFormat:@", self.windows=%@", self.windows]; + [description appendString:@">"]; + return description; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [coder encodeObject:@(self.handle) forKey:@"handle"]; + [coder encodeObject:self.windows forKey:@"windows"]; +} + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super init]; + if (self) { + NSNumber *objHandle = [coder decodeObjectForKey:@"handle"]; + _handle = objHandle.integerValue; + _windows = [coder decodeObjectForKey:@"windows"]; + } + + return self; +} + +@end diff --git a/NeoVimServer/NeoVimWindow.h b/NeoVimServer/NeoVimWindow.h new file mode 100644 index 00000000..a34ce804 --- /dev/null +++ b/NeoVimServer/NeoVimWindow.h @@ -0,0 +1,28 @@ +/** + * Tae Won Ha - http://taewon.de - @hataewon + * See LICENSE + */ + +@import Foundation; + + +@class NeoVimBuffer; + + +NS_ASSUME_NONNULL_BEGIN + +@interface NeoVimWindow : NSObject + +@property (nonatomic, readonly) NSInteger handle; +@property (nonatomic, readonly) NeoVimBuffer *buffer; + +- (instancetype)initWithHandle:(NSInteger)handle buffer:(NeoVimBuffer *)buffer; + +- (instancetype)initWithCoder:(NSCoder *)coder; +- (void)encodeWithCoder:(NSCoder *)coder; + +- (NSString *)description; + +@end + +NS_ASSUME_NONNULL_END diff --git a/NeoVimServer/NeoVimWindow.m b/NeoVimServer/NeoVimWindow.m new file mode 100644 index 00000000..d8e874de --- /dev/null +++ b/NeoVimServer/NeoVimWindow.m @@ -0,0 +1,48 @@ +// +// Created by Tae Won Ha on 22/10/16. +// Copyright (c) 2016 Tae Won Ha. All rights reserved. +// + +#import "NeoVimWindow.h" +#import "NeoVimBuffer.h" + + +@implementation NeoVimWindow + +- (instancetype)initWithHandle:(NSInteger)handle buffer:(NeoVimBuffer *)buffer { + self = [super init]; + if (self == nil) { + return nil; + } + + _handle = handle; + _buffer = buffer; + + return self; +} + +- (NSString *)description { + NSMutableString *description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])]; + [description appendFormat:@"self.handle=%li", self.handle]; + [description appendFormat:@", self.buffer=%@", self.buffer]; + [description appendString:@">"]; + return description; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [coder encodeObject:@(self.handle) forKey:@"handle"]; + [coder encodeObject:self.buffer forKey:@"buffer"]; +} + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super init]; + if (self) { + NSNumber *objHandle = [coder decodeObjectForKey:@"handle"]; + _handle = objHandle.integerValue; + _buffer = [coder decodeObjectForKey:@"buffer"]; + } + + return self; +} + +@end diff --git a/NeoVimServer/server_globals.h b/NeoVimServer/server_globals.h index 5286c8cb..826ea2f8 100644 --- a/NeoVimServer/server_globals.h +++ b/NeoVimServer/server_globals.h @@ -20,4 +20,5 @@ extern void server_vim_input_marked_text(NSString *markedText); extern bool server_has_dirty_docs(); extern NSString *server_escaped_filename(NSString *filename); extern NSArray *server_buffers(); +extern NSArray *server_tabs(); extern void server_quit(); diff --git a/NeoVimServer/server_ui.m b/NeoVimServer/server_ui.m index d1f8bd65..7e580222 100644 --- a/NeoVimServer/server_ui.m +++ b/NeoVimServer/server_ui.m @@ -10,6 +10,8 @@ #import "NeoVimServer.h" #import "NeoVimUiBridgeProtocol.h" #import "NeoVimBuffer.h" +#import "NeoVimWindow.h" +#import "NeoVimTab.h" #import "CocoaCategories.h" // FileInfo and Boolean are #defined by Carbon and NeoVim: Since we don't need the Carbon versions of them, we rename @@ -721,28 +723,65 @@ NSString *server_escaped_filename(NSString *filename) { return result; } +static NeoVimBuffer *buffer_for(buf_T *buf) { + if (buf->b_p_bl == 0) { + return nil; + } + + NSString *fileName = nil; + if (buf->b_ffname != NULL) { + fileName = [NSString stringWithCString:(const char *) buf->b_ffname encoding:NSUTF8StringEncoding]; + } + + bool current = curbuf == buf; + + NeoVimBuffer *buffer = [[NeoVimBuffer alloc] initWithHandle:buf->handle + fileName:fileName + dirty:buf->b_changed + current:current]; + + return [buffer autorelease]; +} + NSArray *server_buffers() { NSMutableArray *result = [[NSMutableArray new] autorelease]; FOR_ALL_BUFFERS(buf) { - if (buf->b_p_bl == 0) { + NeoVimBuffer *buffer = buffer_for(buf); + if (buffer == nil) { continue; } - NSString *fileName = nil; - if (buf->b_ffname != NULL) { - fileName = [NSString stringWithCString:(const char *) buf->b_ffname encoding:NSUTF8StringEncoding]; - } - bool current = curbuf == buf; - NeoVimBuffer *buffer = [[NeoVimBuffer alloc] initWithHandle:(NSUInteger) buf->handle - fileName:fileName - dirty:buf->b_changed - current:current]; [result addObject:buffer]; - [buffer release]; } return result; } +NSArray *server_tabs() { + NSMutableArray *tabs = [[NSMutableArray new] autorelease]; + FOR_ALL_TABS(t) { + NSMutableArray *windows = [NSMutableArray new]; + + FOR_ALL_WINDOWS_IN_TAB(win, t) { + NeoVimBuffer *buffer = buffer_for(win->w_buffer); + if (buffer == nil) { + continue; + } + + NeoVimWindow *window = [[NeoVimWindow alloc] initWithHandle:win->handle buffer:buffer]; + [windows addObject:window]; + [window release]; + } + + NeoVimTab *tab = [[NeoVimTab alloc] initWithHandle:t->handle windows:windows]; + [windows release]; + + [tabs addObject:tab]; + [tab release]; + } + + return tabs; +} + void server_quit() { DLOG("NeoVimServer exiting..."); exit(0); diff --git a/SwiftNeoVim/NeoVimAgent.h b/SwiftNeoVim/NeoVimAgent.h index dedfa037..3e8a3d83 100644 --- a/SwiftNeoVim/NeoVimAgent.h +++ b/SwiftNeoVim/NeoVimAgent.h @@ -8,6 +8,7 @@ @protocol NeoVimUiBridgeProtocol; @class NeoVimBuffer; +@class NeoVimTab; NS_ASSUME_NONNULL_BEGIN @@ -35,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)escapedFileName:(NSString *)fileName; - (NSArray *)escapedFileNames:(NSArray *)fileNames; - (NSArray *)buffers; +- (NSArray *)tabs; @end diff --git a/SwiftNeoVim/NeoVimAgent.m b/SwiftNeoVim/NeoVimAgent.m index 2c1c2c75..16a4f3a3 100644 --- a/SwiftNeoVim/NeoVimAgent.m +++ b/SwiftNeoVim/NeoVimAgent.m @@ -8,6 +8,7 @@ #import "NeoVimUiBridgeProtocol.h" #import "Logger.h" #import "NeoVimBuffer.h" +#import "NeoVimWindow.h" static const double qTimeout = 10; @@ -245,6 +246,16 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD return [NSKeyedUnarchiver unarchiveObjectWithData:response]; } +- (NSArray *)tabs { + NSData *response = [self sendMessageWithId:NeoVimAgentMsgIdGetTabs data:nil expectsReply:YES]; + if (response == nil) { + log4Warn("The response for the msg %lu was nil.", NeoVimAgentMsgIdGetTabs); + return @[]; + } + + return [NSKeyedUnarchiver unarchiveObjectWithData:response]; +} + - (void)runLocalServer { @autoreleasepool { CFMessagePortContext localContext = { diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index 2d11c4cd..d6652cfb 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -181,7 +181,7 @@ public class NeoVimView: NSView, NSUserInterfaceValidations { @IBAction public func debug1(_ sender: AnyObject!) { NSLog("DEBUG 1 - Start") - NSLog("\(self.agent.buffers())") + NSLog("\(self.agent.tabs())") NSLog("DEBUG 1 - End") } } diff --git a/SwiftNeoVim/SwiftNeoVim.h b/SwiftNeoVim/SwiftNeoVim.h index 4040d76a..072519a1 100644 --- a/SwiftNeoVim/SwiftNeoVim.h +++ b/SwiftNeoVim/SwiftNeoVim.h @@ -16,4 +16,6 @@ FOUNDATION_EXPORT const unsigned char SwiftNeoVimVersionString[]; #import #import #import -#import \ No newline at end of file +#import +#import +#import diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj index 69af9ca6..4bbfbe2c 100644 --- a/VimR.xcodeproj/project.pbxproj +++ b/VimR.xcodeproj/project.pbxproj @@ -40,9 +40,6 @@ 4B0677431DA170D5001A2588 /* WorkspaceTool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6423991D8EFE3000FC78C8 /* WorkspaceTool.swift */; }; 4B0677441DA170D5001A2588 /* WorkspaceToolButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB489411D952CF6005BB0E8 /* WorkspaceToolButton.swift */; }; 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 */; }; - 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 */; }; 4B22F7F01D7C029400929B0E /* ScorerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B22F7EF1D7C029400929B0E /* ScorerTest.swift */; }; 4B22F7F21D7C6B9000929B0E /* ImageAndTextTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B22F7F11D7C6B9000929B0E /* ImageAndTextTableCell.swift */; }; 4B238BE11D3BF24200CBDD98 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B238BE01D3BF24200CBDD98 /* Application.swift */; }; @@ -113,6 +110,15 @@ 4BDCFAEF1D315CF200F62670 /* NeoVimServer in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B854A1A1D31447C00E08DE1 /* NeoVimServer */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 4BDD056A1DB0CAB700D1B405 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BDD05691DB0CAB700D1B405 /* Sparkle.framework */; }; 4BDD056B1DB0CACB00D1B405 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4BDD05691DB0CAB700D1B405 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 4BDD05851DBBC50000D1B405 /* NeoVimBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDD057F1DBBC50000D1B405 /* NeoVimBuffer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4BDD05861DBBC50000D1B405 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDD05801DBBC50000D1B405 /* NeoVimBuffer.m */; }; + 4BDD05871DBBC50000D1B405 /* NeoVimBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDD05801DBBC50000D1B405 /* NeoVimBuffer.m */; }; + 4BDD05881DBBC50000D1B405 /* NeoVimTab.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDD05811DBBC50000D1B405 /* NeoVimTab.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4BDD05891DBBC50000D1B405 /* NeoVimTab.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDD05821DBBC50000D1B405 /* NeoVimTab.m */; }; + 4BDD058A1DBBC50000D1B405 /* NeoVimTab.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDD05821DBBC50000D1B405 /* NeoVimTab.m */; }; + 4BDD058B1DBBC50000D1B405 /* NeoVimWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BDD05831DBBC50000D1B405 /* NeoVimWindow.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4BDD058C1DBBC50000D1B405 /* NeoVimWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDD05841DBBC50000D1B405 /* NeoVimWindow.m */; }; + 4BDD058D1DBBC50000D1B405 /* NeoVimWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BDD05841DBBC50000D1B405 /* NeoVimWindow.m */; }; 4BDF50081D7607BF00D8FBC3 /* EonilFileSystemEvents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BDF50071D7607BF00D8FBC3 /* EonilFileSystemEvents.framework */; }; 4BDF50091D7607BF00D8FBC3 /* EonilFileSystemEvents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BDF50071D7607BF00D8FBC3 /* EonilFileSystemEvents.framework */; }; 4BDF500A1D7607C600D8FBC3 /* EonilFileSystemEvents.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BDF50071D7607BF00D8FBC3 /* EonilFileSystemEvents.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -266,8 +272,6 @@ 4B029F1B1D45E349004EE0D3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/PrefWindow.xib; sourceTree = ""; }; 4B0677361D99D9C3001A2588 /* FileBrowserComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileBrowserComponent.swift; sourceTree = ""; }; 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 = ""; }; - 4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NeoVimBuffer.m; sourceTree = ""; }; 4B1BB3521D16C5E500CA4FEF /* InputTestView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputTestView.swift; sourceTree = ""; }; 4B22F7EF1D7C029400929B0E /* ScorerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScorerTest.swift; sourceTree = ""; }; 4B22F7F11D7C6B9000929B0E /* ImageAndTextTableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageAndTextTableCell.swift; sourceTree = ""; }; @@ -330,6 +334,12 @@ 4BDCFAD41D3145E500F62670 /* libvterm.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvterm.a; path = neovim/.deps/usr/lib/libvterm.a; sourceTree = SOURCE_ROOT; }; 4BDCFAE91D3147A300F62670 /* NeoVimMsgIds.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NeoVimMsgIds.h; sourceTree = ""; }; 4BDD05691DB0CAB700D1B405 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = Carthage/Build/Mac/Sparkle.framework; sourceTree = SOURCE_ROOT; }; + 4BDD057F1DBBC50000D1B405 /* NeoVimBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NeoVimBuffer.h; path = NeoVimServer/NeoVimBuffer.h; sourceTree = SOURCE_ROOT; }; + 4BDD05801DBBC50000D1B405 /* NeoVimBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NeoVimBuffer.m; path = NeoVimServer/NeoVimBuffer.m; sourceTree = SOURCE_ROOT; }; + 4BDD05811DBBC50000D1B405 /* NeoVimTab.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NeoVimTab.h; path = NeoVimServer/NeoVimTab.h; sourceTree = SOURCE_ROOT; }; + 4BDD05821DBBC50000D1B405 /* NeoVimTab.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NeoVimTab.m; path = NeoVimServer/NeoVimTab.m; sourceTree = SOURCE_ROOT; }; + 4BDD05831DBBC50000D1B405 /* NeoVimWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NeoVimWindow.h; path = NeoVimServer/NeoVimWindow.h; sourceTree = SOURCE_ROOT; }; + 4BDD05841DBBC50000D1B405 /* NeoVimWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NeoVimWindow.m; path = NeoVimServer/NeoVimWindow.m; sourceTree = SOURCE_ROOT; }; 4BDF50071D7607BF00D8FBC3 /* EonilFileSystemEvents.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = EonilFileSystemEvents.framework; path = Carthage/Build/Mac/EonilFileSystemEvents.framework; sourceTree = SOURCE_ROOT; }; 4BDF500B1D760A3500D8FBC3 /* FileUtilsTest */ = {isa = PBXFileReference; lastKnownFileType = folder; path = FileUtilsTest; sourceTree = ""; }; 4BDF50131D7617EA00D8FBC3 /* OpenQuicklyWindowComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenQuicklyWindowComponent.swift; sourceTree = ""; }; @@ -429,6 +439,19 @@ path = resources; sourceTree = ""; }; + 1929BFC86BF38D341F2DDCBD /* NeoVim Objects */ = { + isa = PBXGroup; + children = ( + 4BDD057F1DBBC50000D1B405 /* NeoVimBuffer.h */, + 4BDD05801DBBC50000D1B405 /* NeoVimBuffer.m */, + 4BDD05811DBBC50000D1B405 /* NeoVimTab.h */, + 4BDD05821DBBC50000D1B405 /* NeoVimTab.m */, + 4BDD05831DBBC50000D1B405 /* NeoVimWindow.h */, + 4BDD05841DBBC50000D1B405 /* NeoVimWindow.m */, + ); + path = "NeoVim Objects"; + sourceTree = ""; + }; 4B0677351D99D9A2001A2588 /* File Browser */ = { isa = PBXGroup; children = ( @@ -545,8 +568,6 @@ 4BCF638F1D323CFD00F15CE4 /* nvim */, 4BDCFADC1D3145EA00F62670 /* lib */, 4BDCFAE91D3147A300F62670 /* NeoVimMsgIds.h */, - 4B0C90591D5DED69007753A3 /* NeoVimBuffer.h */, - 4B0C905A1D5DED69007753A3 /* NeoVimBuffer.m */, 4BDCFAC91D31449700F62670 /* NeoVimServer.h */, 4BDCFACA1D31449700F62670 /* NeoVimServer.m */, 4B854A1C1D31447C00E08DE1 /* main.m */, @@ -555,6 +576,7 @@ 1929B15B7EDC9B0F40E5E95C /* Logging.h */, 1929B5C3F2F1CA4113DABFFD /* CocoaCategories.m */, 1929BE69CF9AB1A10D0DD4F2 /* CocoaCategories.h */, + 1929BFC86BF38D341F2DDCBD /* NeoVim Objects */, ); path = NeoVimServer; sourceTree = ""; @@ -716,7 +738,9 @@ 4B2A2C091D0352CB0074CE9A /* NeoVimUiBridgeProtocol.h in Headers */, 4B570DC21D303CAF006EDC21 /* NeoVimAgent.h in Headers */, 4BDF641C1D0887C100D47E1D /* TextDrawer.h in Headers */, - 4B0E22581D5DEDC700C072E6 /* NeoVimBuffer.h in Headers */, + 4BDD058B1DBBC50000D1B405 /* NeoVimWindow.h in Headers */, + 4BDD05851DBBC50000D1B405 /* NeoVimBuffer.h in Headers */, + 4BDD05881DBBC50000D1B405 /* NeoVimTab.h in Headers */, 4BDCFAEA1D31486E00F62670 /* NeoVimMsgIds.h in Headers */, 4B2A2BFA1D0351810074CE9A /* SwiftNeoVim.h in Headers */, 4B0BCC941D70320C00D3CE65 /* Logger.h in Headers */, @@ -971,16 +995,18 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4BDD05891DBBC50000D1B405 /* NeoVimTab.m in Sources */, 4BEE79171D16D3800012EDAA /* CellAttributes.swift in Sources */, + 4BDD05861DBBC50000D1B405 /* NeoVimBuffer.m in Sources */, 4BF6E29C1D34153C0053FA76 /* KeyUtils.swift in Sources */, 4BCADE081D11ED12004DAD0F /* CocoaExtensions.swift in Sources */, 4B401B1A1D046E0600D99EDC /* NeoVimViewDelegate.swift in Sources */, 1929B728262BAA14FC93F6AC /* NeoVimView.swift in Sources */, - 4B0E22591D5DF62E00C072E6 /* NeoVimBuffer.m in Sources */, 4B570DC31D303CAF006EDC21 /* NeoVimAgent.m in Sources */, 4BEE79151D16D2100012EDAA /* DispatchUtils.swift in Sources */, 4BDF641D1D0887C100D47E1D /* TextDrawer.m in Sources */, 4BDF64251D08CAB000D47E1D /* MMCoreTextView.m in Sources */, + 4BDD058C1DBBC50000D1B405 /* NeoVimWindow.m in Sources */, 1929BEB90DCDAF7A2B68C886 /* ColorUtils.swift in Sources */, 4B4192181D0C52D700A0BEB2 /* Grid.swift in Sources */, ); @@ -1012,9 +1038,11 @@ buildActionMask = 2147483647; files = ( 4BDCFACB1D31449700F62670 /* NeoVimServer.m in Sources */, + 4BDD058A1DBBC50000D1B405 /* NeoVimTab.m in Sources */, 4B854A1D1D31447C00E08DE1 /* main.m in Sources */, 1929BF81A40B4154D3EA33CE /* server_ui.m in Sources */, - 4B0C905B1D5DED69007753A3 /* NeoVimBuffer.m in Sources */, + 4BDD058D1DBBC50000D1B405 /* NeoVimWindow.m in Sources */, + 4BDD05871DBBC50000D1B405 /* NeoVimBuffer.m in Sources */, 1929B1E05C116514C1D3A384 /* CocoaCategories.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From 3f7c51cdcb4b9bc8780bae0592ecd31e9f08b952 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sun, 23 Oct 2016 11:43:21 +0200 Subject: [PATCH 5/6] GH-309 Add isEqual to NeoVimBuffer --- NeoVimServer/NeoVimBuffer.h | 8 ++++++++ NeoVimServer/NeoVimBuffer.m | 23 +++++++++++++++++++++++ SwiftNeoVim/NeoVimObjectsExtensions.swift | 14 ++++++++++++++ SwiftNeoVim/NeoVimView.swift | 3 ++- VimR.xcodeproj/project.pbxproj | 4 ++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 SwiftNeoVim/NeoVimObjectsExtensions.swift diff --git a/NeoVimServer/NeoVimBuffer.h b/NeoVimServer/NeoVimBuffer.h index 88673f71..dfe9cce8 100644 --- a/NeoVimServer/NeoVimBuffer.h +++ b/NeoVimServer/NeoVimBuffer.h @@ -28,3 +28,11 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +@interface NeoVimBuffer (Equality) + +- (BOOL)isEqual:(id _Nullable)other; +- (BOOL)isEqualToBuffer:(NeoVimBuffer * _Nullable)buffer; +- (NSUInteger)hash; + +@end diff --git a/NeoVimServer/NeoVimBuffer.m b/NeoVimServer/NeoVimBuffer.m index f8f92ec8..c65a2e9c 100644 --- a/NeoVimServer/NeoVimBuffer.m +++ b/NeoVimServer/NeoVimBuffer.m @@ -37,6 +37,29 @@ return self; } +- (BOOL)isEqual:(id)other { + if (other == self) + return YES; + if (!other || ![[other class] isEqual:[self class]]) + return NO; + + return [self isEqualToBuffer:other]; +} + +- (BOOL)isEqualToBuffer:(NeoVimBuffer *)buffer { + if (self == buffer) + return YES; + if (buffer == nil) + return NO; + if (self.handle != buffer.handle) + return NO; + return YES; +} + +- (NSUInteger)hash { + return (NSUInteger) self.handle; +} + - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:@(self.handle) forKey:@"handle"]; [coder encodeObject:self.fileName forKey:@"fileName"]; diff --git a/SwiftNeoVim/NeoVimObjectsExtensions.swift b/SwiftNeoVim/NeoVimObjectsExtensions.swift new file mode 100644 index 00000000..08bc6730 --- /dev/null +++ b/SwiftNeoVim/NeoVimObjectsExtensions.swift @@ -0,0 +1,14 @@ +/** + * Tae Won Ha - http://taewon.de - @hataewon + * See LICENSE + */ + +import Foundation + + +extension NeoVimTab { + + public func allBuffers() -> [NeoVimBuffer] { + return Array(Set(self.windows.map { $0.buffer })) + } +} diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index d6652cfb..061732f8 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -181,7 +181,8 @@ public class NeoVimView: NSView, NSUserInterfaceValidations { @IBAction public func debug1(_ sender: AnyObject!) { NSLog("DEBUG 1 - Start") - NSLog("\(self.agent.tabs())") + let buffers = self.agent.tabs().map { $0.allBuffers() }.flatMap { $0 } + NSLog("\(Set(buffers))") NSLog("DEBUG 1 - End") } } diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj index 4bbfbe2c..95c5390b 100644 --- a/VimR.xcodeproj/project.pbxproj +++ b/VimR.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 4B6A709C1D6507A000E12030 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B56F29B1D29926600C1F92E /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4B6B0A781DA2A1A500212D6D /* FileOutlineView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6B0A771DA2A1A500212D6D /* FileOutlineView.swift */; }; 4B854A1D1D31447C00E08DE1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B854A1C1D31447C00E08DE1 /* main.m */; }; + 4B8AC0441DBCB3A2007CCC9B /* NeoVimObjectsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8AC0431DBCB3A1007CCC9B /* NeoVimObjectsExtensions.swift */; }; 4B97E2CC1D33F53D00FC0660 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B97E2CE1D33F53D00FC0660 /* MainWindow.xib */; }; 4B9A15241D2993DA009F9F67 /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B56F29B1D29926600C1F92E /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 4B9A15261D2993DF009F9F67 /* SwiftNeoVim.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4B2A2BF71D0351810074CE9A /* SwiftNeoVim.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -312,6 +313,7 @@ 4B6B0A771DA2A1A500212D6D /* FileOutlineView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileOutlineView.swift; sourceTree = ""; }; 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 = ""; }; 4B97E2CD1D33F53D00FC0660 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainWindow.xib; sourceTree = ""; }; 4BAD81D41D80B5D8004F91AE /* OpenQuicklyFileViewRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenQuicklyFileViewRow.swift; sourceTree = ""; }; 4BAD84E71D7CA8FC00A79CC3 /* OpenQuicklyFilterOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenQuicklyFilterOperation.swift; sourceTree = ""; }; @@ -518,6 +520,7 @@ 4B1BB3521D16C5E500CA4FEF /* InputTestView.swift */, 4BEE79141D16D2100012EDAA /* DispatchUtils.swift */, 4BF6E29B1D34153C0053FA76 /* KeyUtils.swift */, + 4B8AC0431DBCB3A1007CCC9B /* NeoVimObjectsExtensions.swift */, ); path = SwiftNeoVim; sourceTree = ""; @@ -1008,6 +1011,7 @@ 4BDF64251D08CAB000D47E1D /* MMCoreTextView.m in Sources */, 4BDD058C1DBBC50000D1B405 /* NeoVimWindow.m in Sources */, 1929BEB90DCDAF7A2B68C886 /* ColorUtils.swift in Sources */, + 4B8AC0441DBCB3A2007CCC9B /* NeoVimObjectsExtensions.swift in Sources */, 4B4192181D0C52D700A0BEB2 /* Grid.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; From 3769633d24854c9c7ba298c9d3fb68e6321849e3 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sun, 23 Oct 2016 19:42:51 +0200 Subject: [PATCH 6/6] GH-309 Select the neovim window when the file is already open --- NeoVimServer/NeoVimMsgIds.h | 1 + NeoVimServer/NeoVimServer.m | 6 ++++++ NeoVimServer/server_globals.h | 1 + NeoVimServer/server_ui.m | 20 ++++++++++++++++++++ SwiftNeoVim/NeoVimAgent.h | 2 ++ SwiftNeoVim/NeoVimAgent.m | 6 ++++++ SwiftNeoVim/NeoVimView.swift | 16 +++++++++++++++- 7 files changed, 51 insertions(+), 1 deletion(-) diff --git a/NeoVimServer/NeoVimMsgIds.h b/NeoVimServer/NeoVimMsgIds.h index ef61806e..a0215634 100644 --- a/NeoVimServer/NeoVimMsgIds.h +++ b/NeoVimServer/NeoVimMsgIds.h @@ -51,6 +51,7 @@ typedef NS_ENUM(NSUInteger, NeoVimAgentMsgId) { NeoVimAgentMsgIdInputMarked, NeoVimAgentMsgIdDelete, NeoVimAgentMsgIdResize, + NeoVimAgentMsgIdSelectWindow, NeoVimAgentMsgIdQuit, NeoVimAgentMsgIdGetDirtyDocs, diff --git a/NeoVimServer/NeoVimServer.m b/NeoVimServer/NeoVimServer.m index 36aec44c..c63214c4 100644 --- a/NeoVimServer/NeoVimServer.m +++ b/NeoVimServer/NeoVimServer.m @@ -216,6 +216,12 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD return nil; } + case NeoVimAgentMsgIdSelectWindow: { + int *values = data_to_int_array(data, 1); + server_select_win(values[0]); + return nil; + } + case NeoVimAgentMsgIdQuit: // 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]; diff --git a/NeoVimServer/server_globals.h b/NeoVimServer/server_globals.h index 826ea2f8..31eecda5 100644 --- a/NeoVimServer/server_globals.h +++ b/NeoVimServer/server_globals.h @@ -21,4 +21,5 @@ extern bool server_has_dirty_docs(); extern NSString *server_escaped_filename(NSString *filename); extern NSArray *server_buffers(); extern NSArray *server_tabs(); +extern void server_select_win(int window_handle); extern void server_quit(); diff --git a/NeoVimServer/server_ui.m b/NeoVimServer/server_ui.m index 7e580222..7be9c3c4 100644 --- a/NeoVimServer/server_ui.m +++ b/NeoVimServer/server_ui.m @@ -471,6 +471,18 @@ static void neovim_input(void **argv) { } } +static void neovim_select_window(void **argv) { + win_T *window = (win_T *) argv[0]; + + Error err; + nvim_set_current_win(window->handle, &err); + // TODO: handle error + WLOG("Error selecting window with handle %d: %s", window->handle, err.msg); + + // nvim_set_current_win() does not seem to trigger a redraw. + ui_schedule_refresh(); +} + static void send_dirty_status() { bool new_dirty_status = server_has_dirty_docs(); DLOG("dirty status: %d vs. %d", _dirty, new_dirty_status); @@ -782,6 +794,14 @@ NSArray *server_tabs() { return tabs; } +void server_select_win(int window_handle) { + FOR_ALL_TAB_WINDOWS(tab, win) { + if (win->handle == window_handle) { + loop_schedule(&main_loop, event_create(1, neovim_select_window, 1, win)); + } + } +} + void server_quit() { DLOG("NeoVimServer exiting..."); exit(0); diff --git a/SwiftNeoVim/NeoVimAgent.h b/SwiftNeoVim/NeoVimAgent.h index 3e8a3d83..a05b15da 100644 --- a/SwiftNeoVim/NeoVimAgent.h +++ b/SwiftNeoVim/NeoVimAgent.h @@ -9,6 +9,7 @@ @protocol NeoVimUiBridgeProtocol; @class NeoVimBuffer; @class NeoVimTab; +@class NeoVimWindow; NS_ASSUME_NONNULL_BEGIN @@ -37,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSArray *)escapedFileNames:(NSArray *)fileNames; - (NSArray *)buffers; - (NSArray *)tabs; +- (void)selectWindow:(NeoVimWindow *)window; @end diff --git a/SwiftNeoVim/NeoVimAgent.m b/SwiftNeoVim/NeoVimAgent.m index 16a4f3a3..b679eba3 100644 --- a/SwiftNeoVim/NeoVimAgent.m +++ b/SwiftNeoVim/NeoVimAgent.m @@ -225,6 +225,12 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD return [self escapedFileNames:@[ fileName ]][0]; } +- (void)selectWindow:(NeoVimWindow *)window { + int values[] = { (int) window.handle }; + NSData *data = [[NSData alloc] initWithBytes:values length:sizeof(int)]; + [self sendMessageWithId:NeoVimAgentMsgIdSelectWindow data:data expectsReply:NO]; +} + - (NSArray *)escapedFileNames:(NSArray *)fileNames { NSData *data = [NSKeyedArchiver archivedDataWithRootObject:fileNames]; NSData *response = [self sendMessageWithId:NeoVimAgentMsgIdGetEscapeFileNames data:data expectsReply:YES]; diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index 061732f8..b51c31e2 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -222,9 +222,23 @@ extension NeoVimView { } public func open(urls: [URL]) { - let currentBufferIsTransient = self.agent.buffers().filter { $0.isCurrent }.first?.isTransient ?? false + let tabs = self.agent.tabs() + let buffers = tabs.map { $0.allBuffers() }.flatMap { $0 } + let currentBufferIsTransient = buffers.filter { $0.isCurrent }.first?.isTransient ?? false urls.enumerated().forEach { (idx, url) in + let path = url.path + if buffers.filter({ $0.fileName == path }).first != nil { + for window in tabs.map({ $0.windows }).flatMap({ $0 }) { + + if window.buffer.fileName == path { + Swift.print(window) + self.agent.select(window) + return + } + } + } + if idx == 0 && currentBufferIsTransient { self.open(url, cmd: "e") } else {