API: Refactor: Return handles instead of indexes

- Define specialized arrays for each remote object type
- Implement msgpack_rpc functions for dealing with the new types
- Refactor all functions dealing with buffers, windows and tabpages to
  return/accept handles instead of list indexes.
This commit is contained in:
Thiago de Arruda
2014-05-23 15:49:44 -03:00
parent f70f9bfac1
commit a842fe4dc1
9 changed files with 109 additions and 92 deletions

View File

@@ -6,10 +6,11 @@
#include "nvim/api/vim.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/memory.h"
Integer tabpage_get_window_count(Tabpage tabpage, Error *err)
WindowArray tabpage_get_windows(Tabpage tabpage, Error *err)
{
Integer rv = 0;
WindowArray rv = {.size = 0};
tabpage_T *tab = find_tab(tabpage, err);
if (!tab) {
@@ -23,7 +24,17 @@ Integer tabpage_get_window_count(Tabpage tabpage, Error *err)
if (tp != tab) {
break;
}
rv++;
rv.size++;
}
rv.items = xmalloc(sizeof(Window) * rv.size);
size_t i = 0;
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (tp != tab) {
break;
}
rv.items[i++] = wp->handle;
}
return rv;
@@ -67,13 +78,11 @@ Window tabpage_get_window(Tabpage tabpage, Error *err)
} else {
tabpage_T *tp;
win_T *wp;
rv = 1;
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (tp == tab && wp == tab->tp_curwin) {
return rv;
return wp->handle;
}
rv++;
}
// There should always be a current window for a tabpage
abort();