From 5098c1378179113a74ba49adf1ba5eab7317e84c Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 7 Jan 2017 13:55:53 +0100 Subject: [PATCH] GH-339 Try set cursor method --- NeoVimServer/NeoVimServer.m | 2 ++ NeoVimServer/server_globals.h | 2 ++ NeoVimServer/server_ui.m | 34 +++++++++++++++++++++++++++++++++- SwiftNeoVim/NeoVimAgent.h | 3 +++ SwiftNeoVim/NeoVimAgent.m | 8 ++++++-- SwiftNeoVim/NeoVimView.swift | 10 ++++++++-- VimR/MainWindowComponent.swift | 6 ++++-- 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/NeoVimServer/NeoVimServer.m b/NeoVimServer/NeoVimServer.m index b233c923..c8fa4cdd 100644 --- a/NeoVimServer/NeoVimServer.m +++ b/NeoVimServer/NeoVimServer.m @@ -99,6 +99,8 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD case NeoVimAgentMsgIdDelete: return null_data_async(data, neovim_delete); + case NeoVimAgentDebug1: return null_data_async(data, neovim_cursor_goto); + default: return NULL; } diff --git a/NeoVimServer/server_globals.h b/NeoVimServer/server_globals.h index bd76c031..23090dfe 100644 --- a/NeoVimServer/server_globals.h +++ b/NeoVimServer/server_globals.h @@ -27,3 +27,5 @@ extern void neovim_vim_command(void **argv); extern void neovim_vim_input(void **argv); extern void neovim_vim_input_marked_text(void **argv); extern void neovim_delete(void **argv); + +extern void neovim_cursor_goto(void **argv); diff --git a/NeoVimServer/server_ui.m b/NeoVimServer/server_ui.m index 75232a89..855d79e1 100644 --- a/NeoVimServer/server_ui.m +++ b/NeoVimServer/server_ui.m @@ -30,6 +30,8 @@ #import #import #import +#import +#import #define pun_type(t, x) (*((t *) (&(x)))) @@ -757,7 +759,9 @@ void neovim_vim_command(void **argv) { Error err = ERROR_INIT; nvim_command(vim_string_from(input), &err); - // FIXME: handle err.set == true + if (err.set) { + WLOG("ERROR while executing command %s: %s", input.cstr, err.msg); + } [input release]; @@ -851,3 +855,31 @@ void neovim_delete(void **argv) { return nil; }); } + +void neovim_cursor_goto(void **argv) { + work_async(argv, ^NSData *(NSData *data) { + Array position = ARRAY_DICT_INIT; + position.size = 2; + position.items = xmalloc(sizeof(Object) * 2); + + Object row = OBJECT_INIT; + row.type = kObjectTypeInteger; + row.data.integer = 10; + + Object col = OBJECT_INIT; + col.type = kObjectTypeInteger; + col.data.integer = 5; + + position.items[0] = row; + position.items[1] = col; + + Error err = ERROR_INIT; + + nvim_win_set_cursor(nvim_get_current_win(), position, &err); +// nvim_input((String){.data="", .size=5}); + + xfree(position.items); + + return nil; + }); +} diff --git a/SwiftNeoVim/NeoVimAgent.h b/SwiftNeoVim/NeoVimAgent.h index 79cef20a..dd0fa7f0 100644 --- a/SwiftNeoVim/NeoVimAgent.h +++ b/SwiftNeoVim/NeoVimAgent.h @@ -21,6 +21,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, weak) id bridge; - (instancetype)initWithUuid:(NSString *)uuid; + +- (void)debug; + - (void)quit; - (bool)runLocalServerAndNeoVim; diff --git a/SwiftNeoVim/NeoVimAgent.m b/SwiftNeoVim/NeoVimAgent.m index 8fda42f0..63fb7699 100644 --- a/SwiftNeoVim/NeoVimAgent.m +++ b/SwiftNeoVim/NeoVimAgent.m @@ -84,7 +84,7 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD NSCondition *_neoVimReadyCondition; bool _isInitErrorPresent; - uint32_t _neoVimIsQuitting; + volatile uint32_t _neoVimIsQuitting; } - (instancetype)initWithUuid:(NSString *)uuid { @@ -108,6 +108,10 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD return _neoVimIsQuitting == 1; } +- (void)debug { + [self sendMessageWithId:NeoVimAgentDebug1 data:nil expectsReply:NO]; +} + // We cannot use -dealloc for this since -dealloc is not called until the run loop in the thread stops. - (void)quit { OSAtomicOr32Barrier(1, &_neoVimIsQuitting); @@ -236,7 +240,7 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD NSData *response = [self sendMessageWithId:NeoVimAgentMsgIdGetDirtyDocs data:nil expectsReply:YES]; if (response == nil) { log4Warn("The response for the msg %lu was nil.", NeoVimAgentMsgIdGetDirtyDocs); - return YES; + return NO; } NSNumber *value = [NSKeyedUnarchiver unarchiveObjectWithData:response]; diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index faf688b4..5bef88b3 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -208,8 +208,14 @@ public class NeoVimView: NSView, NeoVimUiBridgeProtocol, NSUserInterfaceValidati @IBAction public func debug1(_ sender: AnyObject?) { NSLog("DEBUG 1 - Start") - self.vimExCommand("norm 10G5|") - self.vimInput("") +// self.vimExCommand("norm 10G5|") +// self.vimExCommand("redraw") +// self.vimExCommand("cal cursor(10,5)") +// self.exec(command: "cal cursor(10,5)") +// self.vimOutput(of: "cal nvim_win_set_cursor(1000, [10, 5])") +// self.vimExCommand("redraw") +// self.vimInput("") + self.agent.debug() NSLog("DEBUG 1 - End") } diff --git a/VimR/MainWindowComponent.swift b/VimR/MainWindowComponent.swift index 5e855678..8e144688 100644 --- a/VimR/MainWindowComponent.swift +++ b/VimR/MainWindowComponent.swift @@ -309,9 +309,11 @@ class MainWindowComponent: WindowComponent, self.neoVimView.select(buffer: buffer) case let PreviewComponent.Action.reverseSearch(to: position): - self.neoVimView.vimExCommand("norm \(position.row)G\(position.column)|") + let command = "norm \(position.row)G\(position.column)|" + self.neoVimView.exec(command: "call nvim_win_set_cursor(1000, 10, 5)") +// self.neoVimView.vimExCommand(command) // The above command does not refresh the cursor... - self.neoVimView.vimInput("") +// self.neoVimView.vimInput("") return