mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 11:37:32 +03:00
Use API to get tabs
This commit is contained in:
parent
8eb994ffda
commit
28e092ab40
@ -59,7 +59,6 @@ typedef NS_ENUM(NSInteger, NeoVimAgentMsgId) {
|
|||||||
|
|
||||||
NeoVimAgentMsgIdGetPwd,
|
NeoVimAgentMsgIdGetPwd,
|
||||||
NeoVimAgentMsgIdGetEscapeFileNames,
|
NeoVimAgentMsgIdGetEscapeFileNames,
|
||||||
NeoVimAgentMsgIdGetTabs,
|
|
||||||
|
|
||||||
NeoVimAgentMsgIdGetBoolOption,
|
NeoVimAgentMsgIdGetBoolOption,
|
||||||
NeoVimAgentMsgIdSetBoolOption,
|
NeoVimAgentMsgIdSetBoolOption,
|
||||||
|
@ -72,8 +72,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
|||||||
|
|
||||||
case NeoVimAgentMsgIdScroll: return data_sync(data, outputCondition, neovim_scroll);
|
case NeoVimAgentMsgIdScroll: return data_sync(data, outputCondition, neovim_scroll);
|
||||||
|
|
||||||
case NeoVimAgentMsgIdGetTabs: return data_sync(data, outputCondition, neovim_tabs);
|
|
||||||
|
|
||||||
case NeoVimAgentMsgIdGetBoolOption: return data_sync(data, outputCondition, neovim_get_bool_option);
|
case NeoVimAgentMsgIdGetBoolOption: return data_sync(data, outputCondition, neovim_get_bool_option);
|
||||||
|
|
||||||
case NeoVimAgentMsgIdSetBoolOption: return data_sync(data, outputCondition, neovim_set_bool_option);
|
case NeoVimAgentMsgIdSetBoolOption: return data_sync(data, outputCondition, neovim_set_bool_option);
|
||||||
|
@ -15,7 +15,6 @@ extern void start_neovim(NSInteger width, NSInteger height, NSArray<NSString *>
|
|||||||
|
|
||||||
extern void neovim_select_window(void **argv);
|
extern void neovim_select_window(void **argv);
|
||||||
extern void neovim_scroll(void **argv);
|
extern void neovim_scroll(void **argv);
|
||||||
extern void neovim_tabs(void **argv);
|
|
||||||
extern void neovim_vim_command_output(void **argv);
|
extern void neovim_vim_command_output(void **argv);
|
||||||
extern void neovim_set_bool_option(void **argv);
|
extern void neovim_set_bool_option(void **argv);
|
||||||
extern void neovim_get_bool_option(void **argv);
|
extern void neovim_get_bool_option(void **argv);
|
||||||
|
@ -684,32 +684,6 @@ static NSString *escaped_filename(NSString *filename) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NeoVimBuffer *buffer_for(buf_T *buf) {
|
|
||||||
// To be sure...
|
|
||||||
if (buf == NULL) {
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool readonly = (bool) bt_nofile(buf);
|
|
||||||
|
|
||||||
NSString *fileName = nil;
|
|
||||||
if (buf->b_ffname != NULL) {
|
|
||||||
fileName = [NSString stringWithCString:(const char *) buf->b_ffname
|
|
||||||
encoding:NSUTF8StringEncoding];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool current = curbuf == buf;
|
|
||||||
bool dirty = readonly ? false : (bool) buf->b_changed;
|
|
||||||
|
|
||||||
NeoVimBuffer *buffer = [[NeoVimBuffer alloc] initWithHandle:buf->handle
|
|
||||||
unescapedPath:fileName
|
|
||||||
dirty:dirty
|
|
||||||
readOnly:readonly
|
|
||||||
current:current];
|
|
||||||
|
|
||||||
return [buffer autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
void neovim_scroll(void **argv) {
|
void neovim_scroll(void **argv) {
|
||||||
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
|
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
|
||||||
NSInteger *values = (NSInteger *) data.bytes;
|
NSInteger *values = (NSInteger *) data.bytes;
|
||||||
@ -770,41 +744,6 @@ void neovim_select_window(void **argv) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void neovim_tabs(void **argv) {
|
|
||||||
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
|
|
||||||
NSMutableArray *tabs = [[NSMutableArray new] autorelease];
|
|
||||||
FOR_ALL_TABS(t) {
|
|
||||||
NSMutableArray *windows = [NSMutableArray new];
|
|
||||||
|
|
||||||
bool currentTab = curtab ? t->handle == curtab->handle : false;
|
|
||||||
|
|
||||||
FOR_ALL_WINDOWS_IN_TAB(win, t) {
|
|
||||||
NeoVimBuffer *buffer = buffer_for(win->w_buffer);
|
|
||||||
if (buffer == nil) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool current = false;
|
|
||||||
// tp_curwin is only valid for tabs that aren't the current one
|
|
||||||
if (currentTab) current = curwin ? win->handle == curwin->handle : false;
|
|
||||||
else if (t->tp_curwin) current = win->handle == t->tp_curwin->handle;
|
|
||||||
NeoVimWindow *window = [[NeoVimWindow alloc] initWithHandle:win->handle buffer:buffer currentInTab:current];
|
|
||||||
[windows addObject:window];
|
|
||||||
[window release];
|
|
||||||
}
|
|
||||||
|
|
||||||
NeoVimTab *tab = [[NeoVimTab alloc] initWithHandle:t->handle windows:windows current:currentTab];
|
|
||||||
[windows release];
|
|
||||||
|
|
||||||
[tabs addObject:tab];
|
|
||||||
[tab release];
|
|
||||||
}
|
|
||||||
|
|
||||||
DLOG("tabs: %s", tabs.description.cstr);
|
|
||||||
return [NSKeyedArchiver archivedDataWithRootObject:tabs];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void neovim_vim_command_output(void **argv) {
|
void neovim_vim_command_output(void **argv) {
|
||||||
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
|
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
|
||||||
NSString *input = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
NSString *input = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||||
|
@ -21,7 +21,11 @@ public class Nvim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Window {
|
public struct Window: Equatable {
|
||||||
|
|
||||||
|
public static func ==(lhs: Window, rhs: Window) -> Bool {
|
||||||
|
return lhs.handle == rhs.handle
|
||||||
|
}
|
||||||
|
|
||||||
public let handle: Int
|
public let handle: Int
|
||||||
|
|
||||||
@ -30,7 +34,11 @@ public class Nvim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Tabpage {
|
public struct Tabpage: Equatable {
|
||||||
|
|
||||||
|
public static func ==(lhs: Tabpage, rhs: Tabpage) -> Bool {
|
||||||
|
return lhs.handle == rhs.handle
|
||||||
|
}
|
||||||
|
|
||||||
public let handle: Int
|
public let handle: Int
|
||||||
|
|
||||||
@ -206,6 +214,7 @@ public class Nvim {
|
|||||||
self.session.stop()
|
self.session.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func checkBlocked<T>(_ fn: () -> Nvim.Response<T>) -> Nvim.Response<T> {
|
public func checkBlocked<T>(_ fn: () -> Nvim.Response<T>) -> Nvim.Response<T> {
|
||||||
if self.getMode().value?.dictionaryValue?[.string("blocked")] == .bool(true) {
|
if self.getMode().value?.dictionaryValue?[.string("blocked")] == .bool(true) {
|
||||||
return Nvim.Response.failure(Nvim.Error(type: .blocked, message: "Nvim is currently blocked."))
|
return Nvim.Response.failure(Nvim.Error(type: .blocked, message: "Nvim is currently blocked."))
|
||||||
|
@ -64,6 +64,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func bufSetLines(
|
public func bufSetLines(
|
||||||
buffer: Nvim.Buffer,
|
buffer: Nvim.Buffer,
|
||||||
start: Int,
|
start: Int,
|
||||||
@ -156,6 +157,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func bufSetVar(
|
public func bufSetVar(
|
||||||
buffer: Nvim.Buffer,
|
buffer: Nvim.Buffer,
|
||||||
name: String,
|
name: String,
|
||||||
@ -177,6 +179,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func bufDelVar(
|
public func bufDelVar(
|
||||||
buffer: Nvim.Buffer,
|
buffer: Nvim.Buffer,
|
||||||
name: String,
|
name: String,
|
||||||
@ -219,6 +222,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func bufSetOption(
|
public func bufSetOption(
|
||||||
buffer: Nvim.Buffer,
|
buffer: Nvim.Buffer,
|
||||||
name: String,
|
name: String,
|
||||||
@ -261,6 +265,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func bufSetName(
|
public func bufSetName(
|
||||||
buffer: Nvim.Buffer,
|
buffer: Nvim.Buffer,
|
||||||
name: String,
|
name: String,
|
||||||
@ -355,6 +360,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func bufClearHighlight(
|
public func bufClearHighlight(
|
||||||
buffer: Nvim.Buffer,
|
buffer: Nvim.Buffer,
|
||||||
src_id: Int,
|
src_id: Int,
|
||||||
@ -422,6 +428,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func tabpageSetVar(
|
public func tabpageSetVar(
|
||||||
tabpage: Nvim.Tabpage,
|
tabpage: Nvim.Tabpage,
|
||||||
name: String,
|
name: String,
|
||||||
@ -443,6 +450,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func tabpageDelVar(
|
public func tabpageDelVar(
|
||||||
tabpage: Nvim.Tabpage,
|
tabpage: Nvim.Tabpage,
|
||||||
name: String,
|
name: String,
|
||||||
@ -525,6 +533,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func uiAttach(
|
public func uiAttach(
|
||||||
width: Int,
|
width: Int,
|
||||||
height: Int,
|
height: Int,
|
||||||
@ -546,6 +555,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func uiDetach(
|
public func uiDetach(
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
) -> Nvim.Response<Void> {
|
) -> Nvim.Response<Void> {
|
||||||
@ -562,6 +572,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func uiTryResize(
|
public func uiTryResize(
|
||||||
width: Int,
|
width: Int,
|
||||||
height: Int,
|
height: Int,
|
||||||
@ -581,6 +592,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func uiSetOption(
|
public func uiSetOption(
|
||||||
name: String,
|
name: String,
|
||||||
value: Nvim.Value,
|
value: Nvim.Value,
|
||||||
@ -600,6 +612,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func command(
|
public func command(
|
||||||
command: String,
|
command: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -663,6 +676,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func feedkeys(
|
public func feedkeys(
|
||||||
keys: String,
|
keys: String,
|
||||||
mode: String,
|
mode: String,
|
||||||
@ -861,6 +875,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func setCurrentDir(
|
public func setCurrentDir(
|
||||||
dir: String,
|
dir: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -898,6 +913,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func setCurrentLine(
|
public func setCurrentLine(
|
||||||
line: String,
|
line: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -915,6 +931,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func delCurrentLine(
|
public func delCurrentLine(
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
) -> Nvim.Response<Void> {
|
) -> Nvim.Response<Void> {
|
||||||
@ -952,6 +969,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func setVar(
|
public func setVar(
|
||||||
name: String,
|
name: String,
|
||||||
value: Nvim.Value,
|
value: Nvim.Value,
|
||||||
@ -971,6 +989,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func delVar(
|
public func delVar(
|
||||||
name: String,
|
name: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1030,6 +1049,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func setOption(
|
public func setOption(
|
||||||
name: String,
|
name: String,
|
||||||
value: Nvim.Value,
|
value: Nvim.Value,
|
||||||
@ -1049,6 +1069,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func outWrite(
|
public func outWrite(
|
||||||
str: String,
|
str: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1066,6 +1087,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func errWrite(
|
public func errWrite(
|
||||||
str: String,
|
str: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1083,6 +1105,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func errWriteln(
|
public func errWriteln(
|
||||||
str: String,
|
str: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1140,6 +1163,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func setCurrentBuf(
|
public func setCurrentBuf(
|
||||||
buffer: Nvim.Buffer,
|
buffer: Nvim.Buffer,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1197,6 +1221,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func setCurrentWin(
|
public func setCurrentWin(
|
||||||
window: Nvim.Window,
|
window: Nvim.Window,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1254,6 +1279,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func setCurrentTabpage(
|
public func setCurrentTabpage(
|
||||||
tabpage: Nvim.Tabpage,
|
tabpage: Nvim.Tabpage,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1271,6 +1297,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func subscribe(
|
public func subscribe(
|
||||||
event: String,
|
event: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1288,6 +1315,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func unsubscribe(
|
public func unsubscribe(
|
||||||
event: String,
|
event: String,
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
@ -1470,6 +1498,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func winSetCursor(
|
public func winSetCursor(
|
||||||
window: Nvim.Window,
|
window: Nvim.Window,
|
||||||
pos: [Int],
|
pos: [Int],
|
||||||
@ -1510,6 +1539,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func winSetHeight(
|
public func winSetHeight(
|
||||||
window: Nvim.Window,
|
window: Nvim.Window,
|
||||||
height: Int,
|
height: Int,
|
||||||
@ -1550,6 +1580,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func winSetWidth(
|
public func winSetWidth(
|
||||||
window: Nvim.Window,
|
window: Nvim.Window,
|
||||||
width: Int,
|
width: Int,
|
||||||
@ -1592,6 +1623,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func winSetVar(
|
public func winSetVar(
|
||||||
window: Nvim.Window,
|
window: Nvim.Window,
|
||||||
name: String,
|
name: String,
|
||||||
@ -1613,6 +1645,7 @@ public extension Nvim {
|
|||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func winDelVar(
|
public func winDelVar(
|
||||||
window: Nvim.Window,
|
window: Nvim.Window,
|
||||||
name: String,
|
name: String,
|
||||||
@ -1655,6 +1688,7 @@ public extension Nvim {
|
|||||||
return .success(result)
|
return .success(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
public func winSetOption(
|
public func winSetOption(
|
||||||
window: Nvim.Window,
|
window: Nvim.Window,
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -48,8 +48,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
- (NSString * _Nullable)escapedFileName:(NSString *)fileName;
|
- (NSString * _Nullable)escapedFileName:(NSString *)fileName;
|
||||||
- (NSArray<NSString *> *)escapedFileNames:(NSArray<NSString *> *)fileNames;
|
- (NSArray<NSString *> *)escapedFileNames:(NSArray<NSString *> *)fileNames;
|
||||||
//- (NSArray<NeoVimBuffer *> *)buffers;
|
|
||||||
- (NSArray<NeoVimTab*> *)tabs;
|
|
||||||
|
|
||||||
- (void)scrollHorizontal:(NSInteger)horiz vertical:(NSInteger)vert at:(Position)position;
|
- (void)scrollHorizontal:(NSInteger)horiz vertical:(NSInteger)vert at:(Position)position;
|
||||||
- (void)selectWindow:(NeoVimWindow *)window;
|
- (void)selectWindow:(NeoVimWindow *)window;
|
||||||
|
@ -373,26 +373,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local __unused, SInt32 m
|
|||||||
return [NSKeyedUnarchiver unarchiveObjectWithData:response];
|
return [NSKeyedUnarchiver unarchiveObjectWithData:response];
|
||||||
}
|
}
|
||||||
|
|
||||||
//- (NSArray <NeoVimBuffer *> *)buffers {
|
|
||||||
// NSData *response = [self sendMessageWithId:NeoVimAgentMsgIdGetBuffers data:nil expectsReply:YES];
|
|
||||||
// if (response == nil) {
|
|
||||||
// log4Warn("The response for the msg %ld was nil.", (long) NeoVimAgentMsgIdGetBuffers);
|
|
||||||
// return @[];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return [NSKeyedUnarchiver unarchiveObjectWithData:response];
|
|
||||||
//}
|
|
||||||
|
|
||||||
- (NSArray<NeoVimWindow *> *)tabs {
|
|
||||||
NSData *response = [self sendMessageWithId:NeoVimAgentMsgIdGetTabs data:nil expectsReply:YES];
|
|
||||||
if (response == nil) {
|
|
||||||
log4Warn("The response for the msg %ld was nil.", (long) NeoVimAgentMsgIdGetTabs);
|
|
||||||
return @[];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [NSKeyedUnarchiver unarchiveObjectWithData:response];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)runLocalServer {
|
- (void)runLocalServer {
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
CFMessagePortContext localContext = {
|
CFMessagePortContext localContext = {
|
||||||
|
@ -41,13 +41,22 @@ extension NeoVimView {
|
|||||||
return self.currentBuffer()?.isDirty ?? false
|
return self.currentBuffer()?.isDirty ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func allTabs() -> [NeoVimTab] {
|
||||||
|
let curBuf = self.nvim.checkBlocked { self.nvim.getCurrentBuf() }.value
|
||||||
|
let curTab = self.nvim.checkBlocked { self.nvim.getCurrentTabpage() }.value
|
||||||
|
|
||||||
|
return self.nvim.checkBlocked({ nvim.listTabpages() })
|
||||||
|
.value?
|
||||||
|
.flatMap { self.neoVimTab(for: $0, currentTabpage: curTab, currentBuffer: curBuf) } ?? []
|
||||||
|
}
|
||||||
|
|
||||||
public func newTab() {
|
public func newTab() {
|
||||||
self.exec(command: "tabe")
|
self.exec(command: "tabe")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func `open`(urls: [URL]) {
|
public func `open`(urls: [URL]) {
|
||||||
let tabs = self.agent.tabs()
|
let tabs = self.allTabs()
|
||||||
let buffers = self.allBuffers()
|
let buffers = tabs.map { $0.windows }.flatMap { $0 }.map { $0.buffer }
|
||||||
let currentBufferIsTransient = buffers.first { $0.isCurrent }?.isTransient ?? false
|
let currentBufferIsTransient = buffers.first { $0.isCurrent }?.isTransient ?? false
|
||||||
|
|
||||||
urls.enumerated().forEach { (idx, url) in
|
urls.enumerated().forEach { (idx, url) in
|
||||||
@ -85,7 +94,7 @@ extension NeoVimView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func select(buffer: NeoVimBuffer) {
|
public func select(buffer: NeoVimBuffer) {
|
||||||
for window in self.agent.tabs().map({ $0.windows }).flatMap({ $0 }) {
|
for window in self.allTabs().map({ $0.windows }).flatMap({ $0 }) {
|
||||||
if window.buffer.handle == buffer.handle {
|
if window.buffer.handle == buffer.handle {
|
||||||
self.agent.select(window)
|
self.agent.select(window)
|
||||||
return
|
return
|
||||||
@ -191,6 +200,36 @@ extension NeoVimView {
|
|||||||
|
|
||||||
return NeoVimBuffer(handle: buf.handle, unescapedPath: path, dirty: dirty, readOnly: readonly, current: current)
|
return NeoVimBuffer(handle: buf.handle, unescapedPath: path, dirty: dirty, readOnly: readonly, current: current)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func neoVimWindow(for window: Nvim.Window,
|
||||||
|
currentWindow: Nvim.Window?,
|
||||||
|
currentBuffer: Nvim.Buffer?) -> NeoVimWindow? {
|
||||||
|
|
||||||
|
guard let buf = self.nvim.checkBlocked({ self.nvim.winGetBuf(window: window) }).value else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let buffer = self.neoVimBuffer(for: buf, currentBuffer: currentBuffer) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return NeoVimWindow(handle: window.handle, buffer: buffer, currentInTab: window == currentWindow)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func neoVimTab(for tabpage: Nvim.Tabpage,
|
||||||
|
currentTabpage: Nvim.Tabpage?,
|
||||||
|
currentBuffer: Nvim.Buffer?) -> NeoVimTab? {
|
||||||
|
|
||||||
|
let curWinInTab = self.nvim.checkBlocked { self.nvim.tabpageGetWin(tabpage: tabpage) }.value
|
||||||
|
|
||||||
|
let windows: [NeoVimWindow] = self.nvim.checkBlocked { self.nvim.tabpageListWins(tabpage: tabpage) }
|
||||||
|
.value?
|
||||||
|
.flatMap { self.neoVimWindow(for: $0,
|
||||||
|
currentWindow: curWinInTab,
|
||||||
|
currentBuffer: currentBuffer) } ?? []
|
||||||
|
|
||||||
|
return NeoVimTab(handle: tabpage.handle, windows: windows, current: tabpage == currentTabpage)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate let neoVimQuitTimeout = TimeInterval(5)
|
fileprivate let neoVimQuitTimeout = TimeInterval(5)
|
||||||
|
@ -53,7 +53,7 @@ extension NeoVimView : NSTouchBarDelegate, NSScrubberDataSource, NSScrubberDeleg
|
|||||||
|
|
||||||
func updateTouchBarCurrentBuffer() {
|
func updateTouchBarCurrentBuffer() {
|
||||||
guard let tabsControl = getTabsControl() else { return }
|
guard let tabsControl = getTabsControl() else { return }
|
||||||
tabsCache = self.agent.tabs()
|
tabsCache = self.allTabs()
|
||||||
tabsControl.reloadData()
|
tabsControl.reloadData()
|
||||||
(tabsControl.scrubberLayout as! NSScrubberProportionalLayout).numberOfVisibleItems = tabsControl.numberOfItems > 0 ? tabsControl.numberOfItems : 1
|
(tabsControl.scrubberLayout as! NSScrubberProportionalLayout).numberOfVisibleItems = tabsControl.numberOfItems > 0 ? tabsControl.numberOfItems : 1
|
||||||
tabsControl.selectedIndex = selectedTabIndex()
|
tabsControl.selectedIndex = selectedTabIndex()
|
||||||
@ -61,7 +61,7 @@ extension NeoVimView : NSTouchBarDelegate, NSScrubberDataSource, NSScrubberDeleg
|
|||||||
|
|
||||||
func updateTouchBarTab() {
|
func updateTouchBarTab() {
|
||||||
guard let tabsControl = getTabsControl() else { return }
|
guard let tabsControl = getTabsControl() else { return }
|
||||||
tabsCache = self.agent.tabs()
|
tabsCache = self.allTabs()
|
||||||
tabsControl.reloadData()
|
tabsControl.reloadData()
|
||||||
tabsControl.selectedIndex = selectedTabIndex()
|
tabsControl.selectedIndex = selectedTabIndex()
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
void_func_template = Template('''\
|
void_func_template = Template('''\
|
||||||
|
@discardableResult
|
||||||
public func ${func_name}(${args}
|
public func ${func_name}(${args}
|
||||||
expectsReturnValue: Bool = true
|
expectsReturnValue: Bool = true
|
||||||
) -> Nvim.Response<Void> {
|
) -> Nvim.Response<Void> {
|
||||||
|
Loading…
Reference in New Issue
Block a user