1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 02:54:31 +03:00

Use API to vim command

This commit is contained in:
Tae Won Ha 2017-12-01 15:07:13 +01:00
parent 7aeb809f86
commit 91dbba75b5
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
9 changed files with 5 additions and 80 deletions

View File

@ -47,8 +47,6 @@ typedef NS_ENUM(NSInteger, NeoVimServerMsgId) {
typedef NS_ENUM(NSInteger, NeoVimAgentMsgId) {
NeoVimAgentMsgIdAgentReady = 0,
NeoVimAgentMsgIdCommand,
NeoVimAgentMsgIdCommandOutput,
NeoVimAgentMsgIdInput,
NeoVimAgentMsgIdInputMarked,
NeoVimAgentMsgIdDelete,

View File

@ -66,8 +66,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
return NULL;
}
case NeoVimAgentMsgIdCommandOutput: return data_sync(data, outputCondition, neovim_vim_command_output);
case NeoVimAgentMsgIdSelectWindow: return data_sync(data, outputCondition, neovim_select_window);
case NeoVimAgentMsgIdScroll: return data_sync(data, outputCondition, neovim_scroll);
@ -76,8 +74,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
case NeoVimAgentMsgIdResize: return data_sync(data, outputCondition, neovim_resize);
case NeoVimAgentMsgIdCommand: return data_sync(data, outputCondition, neovim_vim_command);
case NeoVimAgentMsgIdInput: return data_sync(data, outputCondition, neovim_vim_input);
case NeoVimAgentMsgIdInputMarked: return data_sync(data, outputCondition, neovim_vim_input_marked_text);

View File

@ -15,10 +15,8 @@ extern void start_neovim(NSInteger width, NSInteger height, NSArray<NSString *>
extern void neovim_select_window(void **argv);
extern void neovim_scroll(void **argv);
extern void neovim_vim_command_output(void **argv);
extern void neovim_escaped_filenames(void **argv);
extern void neovim_resize(void **argv);
extern void neovim_vim_command(void **argv);
extern void neovim_vim_input(void **argv);
extern void neovim_vim_input_marked_text(void **argv);

View File

@ -744,34 +744,6 @@ void neovim_select_window(void **argv) {
});
}
void neovim_vim_command_output(void **argv) {
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
NSString *input = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Error err = ERROR_INIT;
String commandOutput = nvim_command_output(vim_string_from(input), &err);
char_u *output = (char_u *) commandOutput.data;
// FIXME: handle err.set == true
NSString *result = nil;
if (output == NULL) {
WLOG("vim command output is null");
} else if (ERROR_SET(&err)) {
WLOG("vim command output for '%s' was not successful: %s", input.cstr, err.msg);
} else {
result = [[NSString alloc] initWithCString:(const char *) output
encoding:NSUTF8StringEncoding];
}
NSData *resultData = result == nil ? nil : [NSKeyedArchiver archivedDataWithRootObject:result];
[result release];
[input release];
return resultData;
});
}
void neovim_escaped_filenames(void **argv) {
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
NSArray *fileNames = [NSKeyedUnarchiver unarchiveObjectWithData:data];
@ -798,23 +770,6 @@ void neovim_resize(void **argv) {
});
}
void neovim_vim_command(void **argv) {
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
NSString *input = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Error err = ERROR_INIT;
nvim_command(vim_string_from(input), &err);
if (ERROR_SET(&err)) {
WLOG("ERROR while executing command %s: %s", input.cstr, err.msg);
}
[input release];
return nil;
});
}
void neovim_vim_input(void **argv) {
work_and_write_data_sync(argv, ^NSData *(NSData *data) {
NSString *input = [[[NSString alloc] initWithData:data

View File

@ -37,7 +37,6 @@ NS_ASSUME_NONNULL_BEGIN
- (bool)runLocalServerAndNeoVimWithWidth:(NSInteger)width height:(NSInteger)height;
- (NSURL *)pwd;
- (void)vimCommand:(NSString *)string;
- (void)vimInput:(NSString *)string;
- (void)vimInputMarkedText:(NSString *)markedText;
@ -52,9 +51,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)scrollHorizontal:(NSInteger)horiz vertical:(NSInteger)vert at:(Position)position;
- (void)selectWindow:(NeoVimWindow *)window;
// WAITS
- (NSString * _Nullable)vimCommandOutput:(NSString *)string;
- (void)focusGained:(bool)gained;
@end

View File

@ -268,24 +268,6 @@ static CFDataRef local_server_callback(CFMessagePortRef local __unused, SInt32 m
return pwd;
}
- (void)vimCommand:(NSString *)string {
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
[self sendMessageWithId:NeoVimAgentMsgIdCommand data:data expectsReply:NO];
}
- (NSString *)vimCommandOutput:(NSString *)string {
NSData *data = [self sendMessageWithId:NeoVimAgentMsgIdCommandOutput
data:[string dataUsingEncoding:NSUTF8StringEncoding]
expectsReply:YES];
if (data == nil) {
return nil;
}
NSString *result = [NSKeyedUnarchiver unarchiveObjectWithData:data];
return [result stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)vimInput:(NSString *)string {
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
[self sendMessageWithId:NeoVimAgentMsgIdInput data:data expectsReply:NO];

View File

@ -133,7 +133,7 @@ extension NeoVimView {
}
public func vimOutput(of command: String) -> String {
return self.agent.vimCommandOutput(command) ?? ""
return self.nvim.commandOutput(str: command) ?? ""
}
public func cursorGo(to position: Position) {

View File

@ -59,9 +59,9 @@ extension NeoVimView {
self.nvim.connect()
self.agent.vimCommand("set mouse=a")
self.agent.vimCommand("set title")
self.agent.vimCommand("set termguicolors")
self.nvim.setOption(name: "mouse", value: .string("a"))
self.nvim.setOption(name: "title", value: .bool(true))
self.nvim.setOption(name: "termguicolors", value: .bool(true))
if noErrorDuringInitialization == false {
self.logger.fault("There was an error launching neovim.")

View File

@ -139,7 +139,7 @@ public class NeoVimView: NSView,
return
}
self.agent.vimCommandOutput("cd \(escapedCwd)")
self.nvim.command(command: "cd \(escapedCwd)")
}
}