mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	runtime/lua/vim/compat.lua
ref #9280 Introduce the `vim.compat` module, to help environments with system Lua 5.2+ run the build/tests. Include the module implicitly in all tests. ref #8677 legacy `vim` module: beep buffer command dict eval firstline lastline line list open type window
This commit is contained in:
		@@ -688,7 +688,7 @@ if(LUACHECK_PRG)
 | 
				
			|||||||
      -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake)
 | 
					      -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  add_custom_target(
 | 
					  add_custom_target(
 | 
				
			||||||
    blobcodelint
 | 
					    lintbuiltinlua
 | 
				
			||||||
    COMMAND
 | 
					    COMMAND
 | 
				
			||||||
      ${CMAKE_COMMAND}
 | 
					      ${CMAKE_COMMAND}
 | 
				
			||||||
        -DLUACHECK_PRG=${LUACHECK_PRG}
 | 
					        -DLUACHECK_PRG=${LUACHECK_PRG}
 | 
				
			||||||
@@ -697,10 +697,21 @@ if(LUACHECK_PRG)
 | 
				
			|||||||
        -DREAD_GLOBALS=vim
 | 
					        -DREAD_GLOBALS=vim
 | 
				
			||||||
        -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake
 | 
					        -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					  add_custom_target(
 | 
				
			||||||
 | 
					    lintruntimelua
 | 
				
			||||||
 | 
					    COMMAND
 | 
				
			||||||
 | 
					      ${CMAKE_COMMAND}
 | 
				
			||||||
 | 
					        -DLUACHECK_PRG=${LUACHECK_PRG}
 | 
				
			||||||
 | 
					        -DLUAFILES_DIR=${CMAKE_CURRENT_SOURCE_DIR}/runtime/lua
 | 
				
			||||||
 | 
					        -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
 | 
				
			||||||
 | 
					        -DREAD_GLOBALS=vim
 | 
				
			||||||
 | 
					        -P ${PROJECT_SOURCE_DIR}/cmake/RunLuacheck.cmake
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
  # TODO(ZyX-I): Run linter for all lua code in src
 | 
					  # TODO(ZyX-I): Run linter for all lua code in src
 | 
				
			||||||
  add_custom_target(
 | 
					  add_custom_target(
 | 
				
			||||||
    lualint
 | 
					    lualint
 | 
				
			||||||
    DEPENDS blobcodelint
 | 
					    DEPENDS lintruntimelua
 | 
				
			||||||
 | 
					    DEPENDS lintbuiltinlua
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,10 @@ set(ENV{SYSTEM_NAME} ${SYSTEM_NAME})
 | 
				
			|||||||
execute_process(
 | 
					execute_process(
 | 
				
			||||||
  COMMAND ${BUSTED_PRG} ${TEST_TAG} ${TEST_FILTER} -v -o ${BUSTED_OUTPUT_TYPE}
 | 
					  COMMAND ${BUSTED_PRG} ${TEST_TAG} ${TEST_FILTER} -v -o ${BUSTED_OUTPUT_TYPE}
 | 
				
			||||||
    --lua=${LUA_PRG} --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
 | 
					    --lua=${LUA_PRG} --lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
 | 
				
			||||||
    --lpath=${BUILD_DIR}/?.lua --lpath=?.lua ${TEST_PATH}
 | 
					    --lpath=${BUILD_DIR}/?.lua
 | 
				
			||||||
 | 
					    --lpath=${WORKING_DIR}/runtime/lua/?.lua
 | 
				
			||||||
 | 
					    --lpath=?.lua
 | 
				
			||||||
 | 
					    ${TEST_PATH}
 | 
				
			||||||
  WORKING_DIRECTORY ${WORKING_DIR}
 | 
					  WORKING_DIRECTORY ${WORKING_DIR}
 | 
				
			||||||
  ERROR_VARIABLE err
 | 
					  ERROR_VARIABLE err
 | 
				
			||||||
  RESULT_VARIABLE res
 | 
					  RESULT_VARIABLE res
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
 | 
					require('vim.compat')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local buf_hls = {}
 | 
					local buf_hls = {}
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function highlight_line(line, linenr)
 | 
					local function highlight_line(line, linenr)
 | 
				
			||||||
  local chars = {}
 | 
					  local chars = {}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										12
									
								
								runtime/lua/vim/compat.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								runtime/lua/vim/compat.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					-- Lua 5.1 forward-compatibility layer.
 | 
				
			||||||
 | 
					-- For background see https://github.com/neovim/neovim/pull/9280
 | 
				
			||||||
 | 
					--
 | 
				
			||||||
 | 
					-- Reference the lua-compat-5.2 project for hints:
 | 
				
			||||||
 | 
					--    https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/compat52/mstrict.lua
 | 
				
			||||||
 | 
					--    https://github.com/keplerproject/lua-compat-5.2/blob/c164c8f339b95451b572d6b4b4d11e944dc7169d/tests/test.lua
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local lua_version = _VERSION:sub(-3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if lua_version >= "5.2" then
 | 
				
			||||||
 | 
					  unpack = table.unpack  -- luacheck: ignore 121 143
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
@@ -2,7 +2,6 @@
 | 
				
			|||||||
-- `rpcrequest` calls we need the client event loop to be running.
 | 
					-- `rpcrequest` calls we need the client event loop to be running.
 | 
				
			||||||
local helpers = require('test.functional.helpers')(after_each)
 | 
					local helpers = require('test.functional.helpers')(after_each)
 | 
				
			||||||
local Paths = require('test.config.paths')
 | 
					local Paths = require('test.config.paths')
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
 | 
					local clear, nvim, eval = helpers.clear, helpers.nvim, helpers.eval
 | 
				
			||||||
local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
 | 
					local eq, neq, run, stop = helpers.eq, helpers.neq, helpers.run, helpers.stop
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,6 @@ local request = helpers.request
 | 
				
			|||||||
local NIL = helpers.NIL
 | 
					local NIL = helpers.NIL
 | 
				
			||||||
local meth_pcall = helpers.meth_pcall
 | 
					local meth_pcall = helpers.meth_pcall
 | 
				
			||||||
local command = helpers.command
 | 
					local command = helpers.command
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('api/tabpage', function()
 | 
					describe('api/tabpage', function()
 | 
				
			||||||
  before_each(clear)
 | 
					  before_each(clear)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,7 +12,6 @@ local meth_pcall = helpers.meth_pcall
 | 
				
			|||||||
local meths = helpers.meths
 | 
					local meths = helpers.meths
 | 
				
			||||||
local command = helpers.command
 | 
					local command = helpers.command
 | 
				
			||||||
local expect_err = helpers.expect_err
 | 
					local expect_err = helpers.expect_err
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- check if str is visible at the beginning of some line
 | 
					-- check if str is visible at the beginning of some line
 | 
				
			||||||
local function is_visible(str)
 | 
					local function is_visible(str)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,4 @@
 | 
				
			|||||||
local helpers = require('test.functional.helpers')(after_each)
 | 
					local helpers = require('test.functional.helpers')(after_each)
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local clear = helpers.clear
 | 
					local clear = helpers.clear
 | 
				
			||||||
local eq = helpers.eq
 | 
					local eq = helpers.eq
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@ local iswin = helpers.iswin
 | 
				
			|||||||
local ok = helpers.ok
 | 
					local ok = helpers.ok
 | 
				
			||||||
local matches = helpers.matches
 | 
					local matches = helpers.matches
 | 
				
			||||||
local expect_err = helpers.expect_err
 | 
					local expect_err = helpers.expect_err
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function clear_serverlist()
 | 
					local function clear_serverlist()
 | 
				
			||||||
  for _, server in pairs(funcs.serverlist()) do
 | 
					  for _, server in pairs(funcs.serverlist()) do
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,6 @@ local eq, next_msg = helpers.eq, helpers.next_msg
 | 
				
			|||||||
local exc_exec = helpers.exc_exec
 | 
					local exc_exec = helpers.exc_exec
 | 
				
			||||||
local command = helpers.command
 | 
					local command = helpers.command
 | 
				
			||||||
local eval = helpers.eval
 | 
					local eval = helpers.eval
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('dictionary change notifications', function()
 | 
					describe('dictionary change notifications', function()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
 | 
					require('vim.compat')
 | 
				
			||||||
require('coxpcall')
 | 
					require('coxpcall')
 | 
				
			||||||
local luv = require('luv')
 | 
					local luv = require('luv')
 | 
				
			||||||
local lfs = require('lfs')
 | 
					local lfs = require('lfs')
 | 
				
			||||||
local global_helpers = require('test.helpers')
 | 
					local global_helpers = require('test.helpers')
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- nvim client: Found in .deps/usr/share/lua/<version>/nvim/ if "bundled".
 | 
					-- nvim client: Found in .deps/usr/share/lua/<version>/nvim/ if "bundled".
 | 
				
			||||||
local Session = require('nvim.session')
 | 
					local Session = require('nvim.session')
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,6 @@ local curbuf, buf = helpers.curbuf, helpers.bufmeths
 | 
				
			|||||||
local curwin = helpers.curwin
 | 
					local curwin = helpers.curwin
 | 
				
			||||||
local redir_exec = helpers.redir_exec
 | 
					local redir_exec = helpers.redir_exec
 | 
				
			||||||
local source, command = helpers.source, helpers.command
 | 
					local source, command = helpers.source, helpers.command
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function declare_hook_function()
 | 
					local function declare_hook_function()
 | 
				
			||||||
  source([[
 | 
					  source([[
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,7 +78,6 @@ local helpers = require('test.functional.helpers')(nil)
 | 
				
			|||||||
local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths
 | 
					local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths
 | 
				
			||||||
local eq = helpers.eq
 | 
					local eq = helpers.eq
 | 
				
			||||||
local dedent = helpers.dedent
 | 
					local dedent = helpers.dedent
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local inspect = require('inspect')
 | 
					local inspect = require('inspect')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,6 @@
 | 
				
			|||||||
local helpers = require('test.functional.helpers')(after_each)
 | 
					local helpers = require('test.functional.helpers')(after_each)
 | 
				
			||||||
local Screen = require('test.functional.ui.screen')
 | 
					local Screen = require('test.functional.ui.screen')
 | 
				
			||||||
local clear, command, eq = helpers.clear, helpers.command, helpers.eq
 | 
					local clear, command, eq = helpers.clear, helpers.command, helpers.eq
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('ui/ext_tabline', function()
 | 
					describe('ui/ext_tabline', function()
 | 
				
			||||||
  local screen
 | 
					  local screen
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,6 @@ local assert = require('luassert')
 | 
				
			|||||||
local luv = require('luv')
 | 
					local luv = require('luv')
 | 
				
			||||||
local lfs = require('lfs')
 | 
					local lfs = require('lfs')
 | 
				
			||||||
local relpath = require('pl.path').relpath
 | 
					local relpath = require('pl.path').relpath
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
 | 
					local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
 | 
				
			||||||
local function shell_quote(str)
 | 
					local function shell_quote(str)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,6 @@ local bit = require('bit')
 | 
				
			|||||||
local helpers = require('test.unit.helpers')(after_each)
 | 
					local helpers = require('test.unit.helpers')(after_each)
 | 
				
			||||||
local eval_helpers = require('test.unit.eval.helpers')
 | 
					local eval_helpers = require('test.unit.eval.helpers')
 | 
				
			||||||
local global_helpers = require('test.helpers')
 | 
					local global_helpers = require('test.helpers')
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local itp = helpers.gen_itp(it)
 | 
					local itp = helpers.gen_itp(it)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,7 +13,6 @@ local garray = cimport('./src/nvim/garray.h')
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
local itemsize = 14
 | 
					local itemsize = 14
 | 
				
			||||||
local growsize = 95
 | 
					local growsize = 95
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- define a basic interface to garray. We could make it a lot nicer by
 | 
					-- define a basic interface to garray. We could make it a lot nicer by
 | 
				
			||||||
-- constructing a class wrapper around garray. It could for example associate
 | 
					-- constructing a class wrapper around garray. It could for example associate
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,6 @@ local say = require('say')
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
local posix = nil
 | 
					local posix = nil
 | 
				
			||||||
local syscall = nil
 | 
					local syscall = nil
 | 
				
			||||||
local unpack = table.unpack or unpack -- luacheck: ignore
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
local check_cores = global_helpers.check_cores
 | 
					local check_cores = global_helpers.check_cores
 | 
				
			||||||
local dedent = global_helpers.dedent
 | 
					local dedent = global_helpers.dedent
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user