aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/_editor.lua (renamed from src/nvim/lua/vim.lua)9
-rw-r--r--runtime/lua/vim/_init_packages.lua (renamed from runtime/lua/vim/_load_package.lua)15
-rw-r--r--runtime/lua/vim/lsp/sync.lua13
-rwxr-xr-xscripts/vim-patch.sh20
-rw-r--r--src/nvim/CMakeLists.txt10
-rw-r--r--src/nvim/lua/executor.c56
-rw-r--r--test/functional/plugin/lsp/incremental_sync_spec.lua33
7 files changed, 88 insertions, 68 deletions
diff --git a/src/nvim/lua/vim.lua b/runtime/lua/vim/_editor.lua
index f5f293939b..5f3329ef42 100644
--- a/src/nvim/lua/vim.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -34,8 +34,7 @@
-- - https://github.com/bakpakin/Fennel (pretty print, repl)
-- - https://github.com/howl-editor/howl/tree/master/lib/howl/util
-local vim = vim
-assert(vim)
+local vim = assert(vim)
assert(vim.inspect)
-- These are for loading runtime modules lazily since they aren't available in
@@ -244,12 +243,6 @@ function vim.schedule_wrap(cb)
end)
end
---- <Docs described in |vim.empty_dict()| >
----@private
-function vim.empty_dict()
- return setmetatable({}, vim._empty_dict_mt)
-end
-
-- vim.fn.{func}(...)
vim.fn = setmetatable({}, {
__index = function(t, key)
diff --git a/runtime/lua/vim/_load_package.lua b/runtime/lua/vim/_init_packages.lua
index 59bca9b148..dcb402287c 100644
--- a/runtime/lua/vim/_load_package.lua
+++ b/runtime/lua/vim/_init_packages.lua
@@ -48,5 +48,18 @@ end
-- Insert vim._load_package after the preloader at position 2
table.insert(package.loaders, 2, vim._load_package)
--- should always be available
+-- builtin functions which always should be available
+require'vim.shared'
vim.inspect = require'vim.inspect'
+
+--- <Docs described in |vim.empty_dict()| >
+---@private
+--- TODO: should be in vim.shared when vim.shared always uses nvim-lua
+function vim.empty_dict()
+ return setmetatable({}, vim._empty_dict_mt)
+end
+
+-- only on main thread: functions for interacting with editor state
+if not vim.is_thread() then
+ require'vim._editor'
+end
diff --git a/runtime/lua/vim/lsp/sync.lua b/runtime/lua/vim/lsp/sync.lua
index 0f4e5b572b..e500be46c2 100644
--- a/runtime/lua/vim/lsp/sync.lua
+++ b/runtime/lua/vim/lsp/sync.lua
@@ -131,13 +131,22 @@ end
---@param offset_encoding string utf-8|utf-16|utf-32|nil (fallback to utf-8)
---@returns table<int, int> line_idx, byte_idx, and char_idx of first change position
local function compute_start_range(prev_lines, curr_lines, firstline, lastline, new_lastline, offset_encoding)
+ local char_idx
+ local byte_idx
-- If firstline == lastline, no existing text is changed. All edit operations
-- occur on a new line pointed to by lastline. This occurs during insertion of
-- new lines(O), the new newline is inserted at the line indicated by
-- new_lastline.
+ if firstline == lastline then
+ local line = prev_lines[firstline - 1]
+ byte_idx = #line + 1
+ char_idx = compute_line_length(line, offset_encoding) + 1
+ return { line_idx = firstline - 1, byte_idx = byte_idx, char_idx = char_idx }
+ end
+
-- If firstline == new_lastline, the first change occurred on a line that was deleted.
-- In this case, the first byte change is also at the first byte of firstline
- if firstline == new_lastline or firstline == lastline then
+ if firstline == new_lastline then
return { line_idx = firstline, byte_idx = 1, char_idx = 1 }
end
@@ -158,8 +167,6 @@ local function compute_start_range(prev_lines, curr_lines, firstline, lastline,
end
-- Convert byte to codepoint if applicable
- local char_idx
- local byte_idx
if start_byte_idx == 1 or (#prev_line == 0 and start_byte_idx == 1)then
byte_idx = start_byte_idx
char_idx = 1
diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh
index 67a2cc96fd..591c658e6b 100755
--- a/scripts/vim-patch.sh
+++ b/scripts/vim-patch.sh
@@ -36,7 +36,7 @@ usage() {
echo " can be a Vim version (8.0.xxx) or a Git hash."
echo " -P {vim-revision} Download, generate and apply a Vim patch."
echo " -g {vim-revision} Download a Vim patch."
- echo " -s Create a vim-patch pull request."
+ echo " -s [pr args] Create a vim-patch pull request."
echo " -r {pr-number} Review a vim-patch pull request."
echo " -V Clone the Vim source code to \$VIM_SOURCE_DIR."
echo
@@ -329,7 +329,8 @@ stage_patch() {
* Do this only for _related_ patches (otherwise it increases the
size of the pull request, making it harder to review)
- When you are done, try "%s -s" to create the pull request.
+ When you are done, try "%s -s" to create the pull request,
+ or "%s -s --draft" to create a draft pull request.
See the wiki for more information:
* https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim
@@ -338,13 +339,19 @@ stage_patch() {
}
gh_pr() {
- gh pr create --title "$1" --body "$2"
+ local pr_title
+ local pr_body
+ pr_title="$1"
+ pr_body="$2"
+ shift 2
+ gh pr create --title "${pr_title}" --body "${pr_body}" "$@"
}
git_hub_pr() {
local pr_message
pr_message="$(printf '%s\n\n%s\n' "$1" "$2")"
- git hub pull new -m "${pr_message}"
+ shift 2
+ git hub pull new -m "${pr_message}" "$@"
}
submit_pr() {
@@ -408,7 +415,7 @@ submit_pr() {
fi
echo "Creating pull request."
- if output="$($submit_fn "$pr_title" "$pr_body" 2>&1)"; then
+ if output="$($submit_fn "$pr_title" "$pr_body" "$@" 2>&1)"; then
msg_ok "$output"
else
msg_err "$output"
@@ -799,7 +806,8 @@ while getopts "hlLmMVp:P:g:r:s" opt; do
exit 0
;;
s)
- submit_pr
+ shift # remove opt
+ submit_pr "$@"
exit 0
;;
V)
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index 21150965f9..9abefbe02a 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -57,13 +57,13 @@ set(UNICODE_TABLES_GENERATOR ${GENERATOR_DIR}/gen_unicode_tables.lua)
set(UNICODE_DIR ${PROJECT_SOURCE_DIR}/unicode)
set(GENERATED_UNICODE_TABLES ${GENERATED_DIR}/unicode_tables.generated.h)
set(VIM_MODULE_FILE ${GENERATED_DIR}/lua/vim_module.generated.h)
-set(LUA_VIM_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/src/nvim/lua/vim.lua)
+set(LUA_EDITOR_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/_editor.lua)
set(LUA_SHARED_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/shared.lua)
set(LUA_INSPECT_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/inspect.lua)
set(LUA_F_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/F.lua)
set(LUA_META_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/_meta.lua)
set(LUA_FILETYPE_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/filetype.lua)
-set(LUA_LOAD_PACKAGE_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/_load_package.lua)
+set(LUA_INIT_PACKAGES_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/_init_packages.lua)
set(LUA_KEYMAP_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/keymap.lua)
set(CHAR_BLOB_GENERATOR ${GENERATOR_DIR}/gen_char_blob.lua)
set(LINT_SUPPRESS_FILE ${PROJECT_BINARY_DIR}/errors.json)
@@ -332,9 +332,9 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
"LUAC_PRG=${LUAC_PRG}"
${LUA_PRG} ${CHAR_BLOB_GENERATOR} -c ${VIM_MODULE_FILE}
- ${LUA_LOAD_PACKAGE_MODULE_SOURCE} "vim._load_package"
+ ${LUA_INIT_PACKAGES_MODULE_SOURCE} "vim._init_packages"
${LUA_INSPECT_MODULE_SOURCE} "vim.inspect"
- ${LUA_VIM_MODULE_SOURCE} "vim"
+ ${LUA_EDITOR_MODULE_SOURCE} "vim._editor"
${LUA_SHARED_MODULE_SOURCE} "vim.shared"
${LUA_F_MODULE_SOURCE} "vim.F"
${LUA_META_MODULE_SOURCE} "vim._meta"
@@ -342,7 +342,7 @@ add_custom_command(
${LUA_KEYMAP_MODULE_SOURCE} "vim.keymap"
DEPENDS
${CHAR_BLOB_GENERATOR}
- ${LUA_VIM_MODULE_SOURCE}
+ ${LUA_EDITOR_MODULE_SOURCE}
${LUA_SHARED_MODULE_SOURCE}
${LUA_INSPECT_MODULE_SOURCE}
${LUA_F_MODULE_SOURCE}
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index e233e0e6d0..29a3c515c2 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -525,24 +525,6 @@ static void nlua_common_vim_init(lua_State *lstate, bool is_thread)
lua_pop(lstate, 3);
}
-static void nlua_preload_modules(lua_State *lstate)
-{
- lua_getglobal(lstate, "package"); // [package]
- lua_getfield(lstate, -1, "preload"); // [package, preload]
- for (size_t i = 0; i < ARRAY_SIZE(builtin_modules); i++) {
- ModuleDef def = builtin_modules[i];
- lua_pushinteger(lstate, (long)i); // [package, preload, i]
- lua_pushcclosure(lstate, nlua_module_preloader, 1); // [package, preload, cclosure]
- lua_setfield(lstate, -2, def.name); // [package, preload]
-
- if (nlua_disable_preload && strequal(def.name, "vim")) {
- break;
- }
- }
-
- lua_pop(lstate, 2); // []
-}
-
static int nlua_module_preloader(lua_State *lstate)
{
size_t i = (size_t)lua_tointeger(lstate, lua_upvalueindex(1));
@@ -561,24 +543,29 @@ static int nlua_module_preloader(lua_State *lstate)
return 1;
}
-static bool nlua_common_package_init(lua_State *lstate)
+static bool nlua_init_packages(lua_State *lstate)
FUNC_ATTR_NONNULL_ALL
{
- nlua_preload_modules(lstate);
+ // put builtin packages in preload
+ lua_getglobal(lstate, "package"); // [package]
+ lua_getfield(lstate, -1, "preload"); // [package, preload]
+ for (size_t i = 0; i < ARRAY_SIZE(builtin_modules); i++) {
+ ModuleDef def = builtin_modules[i];
+ lua_pushinteger(lstate, (long)i); // [package, preload, i]
+ lua_pushcclosure(lstate, nlua_module_preloader, 1); // [package, preload, cclosure]
+ lua_setfield(lstate, -2, def.name); // [package, preload]
- lua_getglobal(lstate, "require");
- lua_pushstring(lstate, "vim._load_package");
- if (nlua_pcall(lstate, 1, 0)) {
- nlua_error(lstate, _("E5106: Error while creating _load_package module: %.*s\n"));
- return false;
+ if (nlua_disable_preload && strequal(def.name, "vim.inspect")) {
+ break;
+ }
}
- // TODO(bfredl): ideally all initialization should be done as a single require
- // call.
+ lua_pop(lstate, 2); // []
+
lua_getglobal(lstate, "require");
- lua_pushstring(lstate, "vim.shared");
+ lua_pushstring(lstate, "vim._init_packages");
if (nlua_pcall(lstate, 1, 0)) {
- nlua_error(lstate, _("E5106: Error while creating shared module: %.*s\n"));
+ nlua_error(lstate, _("E5106: Error while loading packages: %.*s\n"));
return false;
}
@@ -654,14 +641,7 @@ static bool nlua_state_init(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_setglobal(lstate, "vim");
- if (!nlua_common_package_init(lstate)) {
- return false;
- }
-
- lua_getglobal(lstate, "require");
- lua_pushstring(lstate, "vim");
- if (nlua_pcall(lstate, 1, 0)) {
- nlua_error(lstate, _("E5106: Error while creating vim module: %.*s\n"));
+ if (!nlua_init_packages(lstate)) {
return false;
}
@@ -732,7 +712,7 @@ static lua_State *nlua_thread_acquire_vm(void)
lua_setglobal(lstate, "vim");
- nlua_common_package_init(lstate);
+ nlua_init_packages(lstate);
lua_getglobal(lstate, "package");
lua_getfield(lstate, -1, "loaded");
diff --git a/test/functional/plugin/lsp/incremental_sync_spec.lua b/test/functional/plugin/lsp/incremental_sync_spec.lua
index 4e3eddb960..da54f3c649 100644
--- a/test/functional/plugin/lsp/incremental_sync_spec.lua
+++ b/test/functional/plugin/lsp/incremental_sync_spec.lua
@@ -207,16 +207,16 @@ describe('incremental synchronization', function()
{
range = {
['start'] = {
- character = 0,
- line = 1
+ character = 11,
+ line = 0,
},
['end'] = {
character = 0,
line = 1
}
},
- rangeLength = 0,
- text = 'hello world\n'
+ rangeLength = 1,
+ text = '\nhello world\n'
}
}
test_edit({"hello world"}, {"yyp"}, expected_text_changes, 'utf-16', '\n')
@@ -226,19 +226,38 @@ describe('incremental synchronization', function()
{
range = {
['start'] = {
+ character = 11,
+ line = 0
+ },
+ ['end'] = {
character = 0,
line = 1
+ }
+ },
+ rangeLength = 1,
+ text = '\n\n'
+ }
+ }
+ test_edit({"hello world"}, {"o"}, expected_text_changes, 'utf-16', '\n')
+ end)
+ it('adding a line to an empty buffer', function()
+ local expected_text_changes = {
+ {
+ range = {
+ ['start'] = {
+ character = 0,
+ line = 0
},
['end'] = {
character = 0,
line = 1
}
},
- rangeLength = 0,
- text = '\n'
+ rangeLength = 1,
+ text = '\n\n'
}
}
- test_edit({"hello world"}, {"o"}, expected_text_changes, 'utf-16', '\n')
+ test_edit({""}, {"o"}, expected_text_changes, 'utf-16', '\n')
end)
end)
describe('multi line edit', function()