aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/typval.c
diff options
context:
space:
mode:
authorMatthieu Coudron <mattator@gmail.com>2020-04-30 15:25:15 +0200
committerGitHub <noreply@github.com>2020-04-30 15:25:15 +0200
commit42b441738d833543c98c97cad0c200bde28ae233 (patch)
tree6487aa3db8e2b85a4b61a9eecd465c83184c3b62 /src/nvim/eval/typval.c
parentf9055c585f597fe4ea8ecb990927a2826234393c (diff)
parente4a1be779b9a6bb9a47700ebf92f8dd934bb1712 (diff)
downloadrneovim-42b441738d833543c98c97cad0c200bde28ae233.tar.gz
rneovim-42b441738d833543c98c97cad0c200bde28ae233.tar.bz2
rneovim-42b441738d833543c98c97cad0c200bde28ae233.zip
Merge pull request #12204 from archseer/lsp-user-data
lsp/completion: Expose completion_item under completed_items.user_data + vim-patch:8.2.0084
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r--src/nvim/eval/typval.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 773e493d0b..35130f6f40 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1429,6 +1429,23 @@ dictitem_T *tv_dict_find(const dict_T *const d, const char *const key,
return TV_DICT_HI2DI(hi);
}
+/// Get a typval item from a dictionary and copy it into "rettv".
+///
+/// @param[in] d Dictionary to check.
+/// @param[in] key Dictionary key.
+/// @param[in] rettv Return value.
+/// @return OK in case of success or FAIL if nothing was found.
+int tv_dict_get_tv(dict_T *d, const char *const key, typval_T *rettv)
+{
+ dictitem_T *const di = tv_dict_find(d, key, -1);
+ if (di == NULL) {
+ return FAIL;
+ }
+
+ tv_copy(&di->di_tv, rettv);
+ return OK;
+}
+
/// Get a number item from a dictionary
///
/// Returns 0 if the entry does not exist.
@@ -1588,6 +1605,26 @@ int tv_dict_add_list(dict_T *const d, const char *const key,
return OK;
}
+/// Add a typval entry to dictionary.
+///
+/// @param[out] d Dictionary to add entry to.
+/// @param[in] key Key to add.
+/// @param[in] key_len Key length.
+///
+/// @return FAIL if out of memory or key already exists.
+int tv_dict_add_tv(dict_T *d, const char *key, const size_t key_len,
+ typval_T *tv)
+{
+ dictitem_T *const item = tv_dict_item_alloc_len(key, key_len);
+
+ tv_copy(tv, &item->di_tv);
+ if (tv_dict_add(d, item) == FAIL) {
+ tv_dict_item_free(item);
+ return FAIL;
+ }
+ return OK;
+}
+
/// Add a dictionary entry to dictionary
///
/// @param[out] d Dictionary to add entry to.